<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Enno Rehling (恩諾)</title>
    <description>The latest articles on DEV Community by Enno Rehling (恩諾) (@ennor).</description>
    <link>https://dev.to/ennor</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F819%2F3c22a5de-e31e-4a72-8639-a3073b9bee85.png</url>
      <title>DEV Community: Enno Rehling (恩諾)</title>
      <link>https://dev.to/ennor</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ennor"/>
    <language>en</language>
    <item>
      <title>Testing Laravel JSON requests</title>
      <dc:creator>Enno Rehling (恩諾)</dc:creator>
      <pubDate>Tue, 27 Jan 2026 09:23:38 +0000</pubDate>
      <link>https://dev.to/ennor/testing-laravel-json-requests-ajm</link>
      <guid>https://dev.to/ennor/testing-laravel-json-requests-ajm</guid>
      <description>&lt;p&gt;Chased a stupid problem all day today. Long story short: I had a simple Laravel controller that was trying to just echo back the inputs from a JSON request body. It's not enough to write a test like the following.&lt;/p&gt;

&lt;h3&gt;
  
  
  Wrong Code:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyTest&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;TestCase&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;test_example&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;withHeaders&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
      &lt;span class="s1"&gt;'Accept'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'application/json'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s1"&gt;'Content-Type'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'application/json'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'echo'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'foo'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'bar'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;assertJson&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;'foo'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'bar'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The controller tries to read &lt;code&gt;$request-&amp;gt;all()&lt;/code&gt;, which is empty! That's because of how the Laravel test framework constructs request objects. It doesn't care that I provided those headers to indicate that there was a JSON body to draw from. You have to use &lt;code&gt;postJson&lt;/code&gt; instead of &lt;code&gt;post&lt;/code&gt; for that, and then you don't need those headers, either.&lt;/p&gt;

&lt;h3&gt;
  
  
  Correct:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;  &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;test_example&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;postJson&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'echo'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'foo'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'bar'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;assertJson&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;'foo'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'bar'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same is true for &lt;code&gt;patch&lt;/code&gt; vs. &lt;code&gt;patchJson&lt;/code&gt;. So somehow, I've been using the wrong method all this time, and it's never been a problem? I'm shocked and confused.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>json</category>
    </item>
    <item>
      <title>Puzzle of the day: VS Code and CMAKE_TOOLCHAIN_FILE</title>
      <dc:creator>Enno Rehling (恩諾)</dc:creator>
      <pubDate>Sat, 19 Mar 2022 11:50:24 +0000</pubDate>
      <link>https://dev.to/ennor/puzzle-of-the-day-vs-code-and-cmaketoolchainfile-3e61</link>
      <guid>https://dev.to/ennor/puzzle-of-the-day-vs-code-and-cmaketoolchainfile-3e61</guid>
      <description>&lt;p&gt;This is one of those problems that I've now solved from scratch at least twice, and never gives good Google result, do it's time I write a post, if only for myself.&lt;/p&gt;

&lt;p&gt;My situation is as follows: I'm running VS Code on a Windows host to build a Linux program with WSL2, or other remote connection (i.e. SSH to a remote machine). My build tool of choice is CMake, and I have the CMake extension installed.&lt;/p&gt;

&lt;p&gt;Trying to build my project gives me this error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[proc] Executing command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/x86_64-linux-gnu-gcc-10 -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/x86_64-linux-gnu-g++-10 -S/home/enno/echeck -B/home/enno/echeck/build -G "Unix Makefiles"
[cmake] CMake Error at /usr/share/cmake-3.18/Modules/CMakeDetermineSystem.cmake:99 (message):
[cmake]   Could not find toolchain file: C:/vcpkg/scripts/buildsystems/vcpkg.cmake
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Somehow, there is a CMAKE_TOOLCHAIN_FILE argument being passed to cmake, and it contains a path on my Windows filesystem (this project also compiles on Windows, using vcpkg for its find_package dependencies). Of course this can't work, I'm using a gcc toolchain on Linux. Where does this come from?&lt;/p&gt;

&lt;p&gt;The answer turned out to be that the settings.json file in %APPDATA%\Code\User on my Windows host contained this nugget:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    "cmake.configureArgs": [
        "-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake"
    ],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I must have set this at some point, trying to use VS Code to build on Windows, and for reasons, VS Code applies it to all my CMake builds, even remote builds. So, after I deleted that entry from the settings.json file and deleted the generated CMakeCache.txt, I can now build my project! And next time this happens, I hope Google will point me to this post.&lt;/p&gt;

</description>
      <category>vscode</category>
      <category>wsl</category>
      <category>cmake</category>
      <category>solution</category>
    </item>
    <item>
      <title>List Formatting in C</title>
      <dc:creator>Enno Rehling (恩諾)</dc:creator>
      <pubDate>Sat, 21 Sep 2019 19:18:20 +0000</pubDate>
      <link>https://dev.to/ennor/list-formatting-in-c-4lgp</link>
      <guid>https://dev.to/ennor/list-formatting-in-c-4lgp</guid>
      <description>&lt;p&gt;Today I needed to format a list of words in C, and ended up writing my own list formatter, which was rather satisfying (I like fidgety string manipulation). The goal was this: given a list of words like {"apple", "banana", "mango"}, create a string like "apple, banana, and mango". At first glance, this is simple: We step through the list, append each word to the result with a trailing comma, and when we're appending the final word, prefix it with " and ".&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;char *format_list(int argc, const char **argv, char *output, const char *and) {
  output[0] = '\0';
  for (int i = 0; i != argc; ++i) {
    strcat(output, argv[i]);
    strcat(output, ", ");
    if (argc == i + 2) {
      strcat(output, and);
      strcat(output, " ");
    }
  }
  return output;
}

void print_fruit(void) {
    const char * fruit[] = {"apple", "banana", "mango"};
    char buffer[1024];
    puts(format_list, 3, fruit, buffer, "and");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;WARNING: This function does no bounds checking, so the output buffer needs to have enough space for the resulting string. This is bad function design, and adding the necessary checking is not hard, but would make it harder to get the point across that this code is really trivial.&lt;/p&gt;

&lt;p&gt;However, I needed my solution to work in other languages. We could use gettext to translate the inputs and the word "and", translate the word into a locale-dependent substitute, like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void print_fruit(void) {
    const char * fruit[3];
    char buffer[1024];
    fruit[0] = gettext("apple");
    fruit[1] = gettext("banana");
    fruit[2] = gettext("mango");
    puts(format_list, 3, fruit, buffer, gettext("and"));
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This way (with the correct .po file and libgettext) we get "Apfel, Banane, und Mango" if we're using a German locale. There's a problem with that: German does not use an oxford comma. And other languages that I don't speak don't write lists with the same rules at all. Some put the and at the start (think "apple and banana, mango"). What we need is more than just the "and" to encapsulate all those rules, without writing a separate function for each language. &lt;/p&gt;

&lt;p&gt;Cribbing inspiration from the &lt;a href="http://icu-project.org/apiref/icu4j/com/ibm/icu/text/ListFormatter.html"&gt;icu4j library&lt;/a&gt;, this is the function I came up with:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ennorehling/clibs/blob/master/format.c#L29"&gt;https://github.com/ennorehling/clibs/blob/master/format.c#L29&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I'm not including the entire file, since with the bounds checking, it gets rather long, but it does the trick, and is customizable by a set of patterns:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;list of two words (English: "{0} and {1}")&lt;/li&gt;
&lt;li&gt;start of a list with 3 or more elements (English: "{0}, {1}")&lt;/li&gt;
&lt;li&gt;middle of a list with 3 or more elements (English: "{0}, {1}")&lt;/li&gt;
&lt;li&gt;end of a list with 3 or more elements (English: "{0}, and {1}")&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you don't use an oxford comma (I won't judge you), then that last string should be "{0} and {1}".&lt;/p&gt;

&lt;p&gt;Incidentally, this is the first time I've ever used goto in C, and I apologize to Ed Dijkstra and all the computer science teachers who told me, repeatedly, to never do that, ever. Well, I broke the law, and I regret nothing!&lt;/p&gt;

</description>
      <category>c</category>
      <category>l10n</category>
      <category>i18n</category>
    </item>
  </channel>
</rss>
