<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Symfony | Nerdpress.org</title>
	<atom:link href="https://nerdpress.org/category/php/symfony-framework/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerdpress.org</link>
	<description>...dev, tech problems and solutions.</description>
	<lastBuildDate>Wed, 06 Aug 2025 07:02:57 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Symfony HTTP Client default timeout</title>
		<link>https://nerdpress.org/2025/08/06/symfony-http-client-default-timeout/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Wed, 06 Aug 2025 07:02:56 +0000</pubDate>
				<category><![CDATA[Symfony]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=3428</guid>

					<description><![CDATA[<p>Small Service Post: The default timeout of the Symfony HTTP Client is 60s (seconds)! Sure, it is mentioned in the Symfony HTTP Client docs, that PHP&#8217;s default_socket_timeout is taken as default value.So what is the default_socket_timeout then, you might wonder? One click away in PHP Runtime Configuration docs you will find that in the php.ini &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2025/08/06/symfony-http-client-default-timeout/" class="more-link">Continue reading<span class="screen-reader-text"> "Symfony HTTP Client default timeout"</span></a></p>
The post <a href="https://nerdpress.org/2025/08/06/symfony-http-client-default-timeout/">Symfony HTTP Client default timeout</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p><br />Small Service Post:<br /><br />The default timeout of the Symfony HTTP Client is <strong>60s</strong> (seconds)!<br /><br />Sure, it is mentioned in the <a href="https://symfony.com/doc/current/reference/configuration/framework.html#timeout" title="">Symfony HTTP Client docs</a>, that PHP&#8217;s <em>default_socket_timeout</em> is taken as default value.<br />So what is the default_socket_timeout then, you might wonder?</p>



<p>One click away in <a href="https://www.php.net/manual/en/filesystem.configuration.php" target="_blank" rel="noopener" title="">PHP Runtime Configuration docs</a> you will find that in the php.ini the default value is &#8220;60&#8221;. <br />In case you wonder what unit these &#8220;60&#8221; is, you will find <em>(in seconds)</em> a bit down below the config table. <br />&#8211; Yeah, seconds was my first guess, but I need to assure it is not microseconds by any chance. &#8211;</p>



<p>And thats it! Thats the post.</p>



<p>P.S: It is funny how scattered information sometimes is, although is all there. <br />AI did know, but did not name a source. <br />And since AI is not to trust, I still had to look it up via Search.</p>The post <a href="https://nerdpress.org/2025/08/06/symfony-http-client-default-timeout/">Symfony HTTP Client default timeout</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Symfony integration tests custom header is missing</title>
		<link>https://nerdpress.org/2024/06/14/symfony-integration-tests-custom-header-is-missing/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Fri, 14 Jun 2024 14:27:00 +0000</pubDate>
				<category><![CDATA[Symfony]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=3316</guid>

					<description><![CDATA[<p>I am writing an integration test in Symfony with a request that includes custom headers. However, the request fails because the custom header is apparently missing. What happened was I forgot to add an HTTP prefix to the custom header. This is a common pitfall when writing integration tests in Symfony and using custom HTTP &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2024/06/14/symfony-integration-tests-custom-header-is-missing/" class="more-link">Continue reading<span class="screen-reader-text"> "Symfony integration tests custom header is missing"</span></a></p>
The post <a href="https://nerdpress.org/2024/06/14/symfony-integration-tests-custom-header-is-missing/">Symfony integration tests custom header is missing</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>I am writing an integration test in Symfony with a request that includes custom headers. However, the request fails because the custom header is apparently missing. <br />What happened was I forgot to add an HTTP prefix to the custom header.</p>



<p>This is a common pitfall when writing integration tests in Symfony and using custom HTTP headers: the necessity to add an <strong>HTTP_</strong> prefix to the header in the test. <br />If you do not add the prefix to the custom header, it will silently not be added to the request, and you have to debug why the request fails.</p>



<p>So this will fail:</p>


<pre class="wp-block-code"><span><code class="hljs language-php"><span class="hljs-keyword">static</span>::$client-&gt;request(<span class="hljs-string">'GET'</span>, <span class="hljs-string">'/ping'</span>, &#91;], &#91;], &#91;<span class="hljs-string">'X-Custom-Header'</span> =&gt; <span class="hljs-string">'custom'</span>]);</code></span></pre>


<p>And this will work:</p>


<pre class="wp-block-code"><span><code class="hljs language-php"><span class="hljs-keyword">static</span>::$client-&gt;request(<span class="hljs-string">'GET'</span>, <span class="hljs-string">'/ping'</span>, &#91;], &#91;], &#91;<span class="hljs-string">'HTTP_X-Custom-Header'</span> =&gt; <span class="hljs-string">'custom'</span>]);</code></span></pre>


<span id="more-3316"></span>



<p>According to the <a href="https://symfony.com/doc/current/testing.html#sending-custom-headers" target="_blank" rel="noopener" title="">documentation</a>, you would actually also need to transform it to uppercase and replace the dash with an underscore but it will work with just the HTTP prefix.</p>



<p>HTTP_X_CUSTOM_HEADER</p>



<p>The prefix is however not necessary for not custom but standard headers like &#8216;Content-Type&#8217;.</p>



<p>This is not an intuitive requirement, and I wish it were not necessary. <br />At the very least, a warning would be nice when the test client encounters a non-prefixed, non-standard header.</p>



<p>A related StackOverflow Post: <a href="https://stackoverflow.com/questions/11549672/symfony-functional-test-custom-headers-not-passing-through" target="_blank" rel="noopener" title="">https://stackoverflow.com/questions/11549672/symfony-functional-test-custom-headers-not-passing-through</a></p>The post <a href="https://nerdpress.org/2024/06/14/symfony-integration-tests-custom-header-is-missing/">Symfony integration tests custom header is missing</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Stream an image from Symfony controller</title>
		<link>https://nerdpress.org/2022/12/12/stream-an-image-from-symfony-controller/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Mon, 12 Dec 2022 09:26:26 +0000</pubDate>
				<category><![CDATA[Symfony]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=3190</guid>

					<description><![CDATA[<p>When sending an image/file from a Symfony controller you would usually read the file from filesystem.This you can do by passing the file path to the BinaryFileResponse class and return it in the controller, as described in the docs:https://symfony.com/doc/current/components/http_foundation.html#serving-files But in some cases you might want to create an image dynamically and return it directly &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2022/12/12/stream-an-image-from-symfony-controller/" class="more-link">Continue reading<span class="screen-reader-text"> "Stream an image from Symfony controller"</span></a></p>
The post <a href="https://nerdpress.org/2022/12/12/stream-an-image-from-symfony-controller/">Stream an image from Symfony controller</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>When sending an image/file from a Symfony controller you would usually read the file from filesystem.<br />This you can do by passing the file path to the BinaryFileResponse class and return it in the controller, as described in the docs:<br /><a href="https://symfony.com/doc/current/components/http_foundation.html#serving-files" target="_blank" rel="noreferrer noopener">https://symfony.com/doc/current/components/http_foundation.html#serving-files</a></p>


<pre class="wp-block-code"><span><code class="hljs language-php"><span class="hljs-keyword">use</span> <span class="hljs-title">Symfony</span>\<span class="hljs-title">Component</span>\<span class="hljs-title">HttpFoundation</span>\<span class="hljs-title">BinaryFileResponse</span>;

$file = <span class="hljs-string">'path/to/file.txt'</span>;
$response = <span class="hljs-keyword">new</span> BinaryFileResponse($file);</code></span></pre>


<p>But in some cases you might want to create an image dynamically and return it directly from the controller without storing it on the filesystem.<br />So you can create your image with the GD library and directly stream the GDImage object from the symfony controller with the <em>StreamedResponse</em> class.</p>



<span id="more-3190"></span>


<pre class="wp-block-code"><span><code class="hljs language-php">$image = imagecreatetruecolor($imgWidth, $imgHeight);
<span class="hljs-comment">// do something with the image</span>
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> StreamedResponse(fn () =&gt; imagepng($image), <span class="hljs-number">200</span>, &#91;<span class="hljs-string">'Content-Type'</span> =&gt; <span class="hljs-string">'image/png'</span>]);</code></span></pre>


<p>Great that was easy, but not so obvious ;)</p>



<p>Another thing you might wonder is how to add the OpenAPI annotation when streaming images to generate a proper documentation for your endpoints.<br />Just use <em>MediaType </em>class in the Response annotation and set the format to binary.</p>


<pre class="wp-block-code"><span><code class="hljs language-php">responses: &#91;
	<span class="hljs-keyword">new</span> OA\Response(
		response: <span class="hljs-number">200</span>,
		description: <span class="hljs-string">"dynamic image"</span>,
		content: <span class="hljs-keyword">new</span> OA\MediaType(
			mediaType: <span class="hljs-string">'image/png'</span>, 
			schema: <span class="hljs-keyword">new</span> OA\Schema(
				type: <span class="hljs-string">'string'</span>,
				format: <span class="hljs-string">'binary'</span>
			)
		)
	),
]</code></span></pre>


<p>Then finally you should test the <em>StreamedResponse</em> from the controller.<br />For this you can not use the normal <code>$client-&gt;getResponse()</code> but instead use the <em>getInternalResponse</em> which holds the binary data as string however.<br />So to test the binary response in your test add this:</p>


<pre class="wp-block-code"><span><code class="hljs language-php">$response = <span class="hljs-keyword">static</span>::$client-&gt;getInternalResponse();
$image = $response-&gt;getContent();
		
<span class="hljs-keyword">self</span>::assertInstanceOf(GdImage::class, imagecreatefromstring($image));</code></span></pre>


<p>This seems to be valid from Symfony 4 upwards.<br />Before Symfony 4 you could get the binary data from <code>$client-&gt;getResponse()</code>.</p>The post <a href="https://nerdpress.org/2022/12/12/stream-an-image-from-symfony-controller/">Stream an image from Symfony controller</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Symfony deprecation log channel</title>
		<link>https://nerdpress.org/2022/09/13/symfony-deprecation-log-channel/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Tue, 13 Sep 2022 13:53:02 +0000</pubDate>
				<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Logging]]></category>
		<category><![CDATA[Monolog]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=3170</guid>

					<description><![CDATA[<p>Are you annoyed of too many deprecation warnings in you logs of your symfony app?Probably yes because it is really a lot of noise.However deprecation logs are still useful to ensure future compatibility of your app. So since version 5.1 symfony will log deprecations to a dedicated log channel when it exists and ships with &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2022/09/13/symfony-deprecation-log-channel/" class="more-link">Continue reading<span class="screen-reader-text"> "Symfony deprecation log channel"</span></a></p>
The post <a href="https://nerdpress.org/2022/09/13/symfony-deprecation-log-channel/">Symfony deprecation log channel</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Are you annoyed of too many deprecation warnings in you logs of your symfony app?<br />Probably yes because it is really a lot of noise.<br />However deprecation logs are still useful to ensure future compatibility of your app.</p>



<p>So since version 5.1 symfony will log deprecations to a dedicated log channel when it exists and ships with this monolog config:</p>


<pre class="wp-block-code"><span><code class="hljs language-php">monolog:
    channels:
        - deprecation <span class="hljs-comment"># Deprecations are logged in the dedicated "deprecation" channel when it exists</span></code></span></pre>


<p>This is added already in the <a href="https://github.com/symfony/recipes/blob/main/symfony/monolog-bundle/3.1/config/packages/prod/deprecations.yaml" target="_blank" rel="noreferrer noopener">recipe</a> and ships when installing symfony.</p>



<p>Ok, but the handler for this deprecation channel is not configured, so you have to do this yourself.<br />How? Add this to your monolog config:</p>



<span id="more-3170"></span>


<pre class="wp-block-code"><span><code class="hljs language-javascript">...
when@dev:
   monolog:
       handlers:
           main:
	       type: stream
	       <span class="hljs-attr">path</span>: <span class="hljs-string">"%kernel.logs_dir%/%kernel.environment%.log"</span>
	       <span class="hljs-attr">level</span>: debug
	       <span class="hljs-attr">channels</span>: &#91;<span class="hljs-string">"!event"</span>, <span class="hljs-string">"!deprecation"</span>]
	   <span class="hljs-attr">deprecation</span>:
	       type: rotating_file
	       <span class="hljs-attr">path</span>: <span class="hljs-string">"%kernel.logs_dir%/%kernel.environment%.deprecations.log"</span>
	       <span class="hljs-attr">max_files</span>: <span class="hljs-number">2</span>
	       <span class="hljs-attr">channels</span>: &#91;deprecation]
	   <span class="hljs-attr">console</span>:
	       type: <span class="hljs-built_in">console</span>
	       <span class="hljs-attr">process_psr_3_messages</span>: <span class="hljs-literal">false</span>
               <span class="hljs-attr">channels</span>: &#91;<span class="hljs-string">"!event"</span>, <span class="hljs-string">"!doctrine"</span>, <span class="hljs-string">"!console"</span>, <span class="hljs-string">"!deprecation"</span>]
...
</code></span></pre>


<p>What is happening here?<br />We declare a new handler for deprecations named <code>deprecation</code> when in dev environment.<br />This handler listens to the deprecation channel.<br />We declare it as a rotating file since the assumption is we dont need to keep this log entries for longer.<br />The other handlers will ignore the deprecation channel by adding a !deprecation to the channel directive.</p>



<p>The deprecation channel was already created and so all deprecations are now not in the main log file but in a dedicated deprecation log file.</p>



<p>For production we dont need to edit configuration since the log level here is info and therefore deprecations will not be considered anyway.</p>The post <a href="https://nerdpress.org/2022/09/13/symfony-deprecation-log-channel/">Symfony deprecation log channel</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Converting umlaute with symfony String component</title>
		<link>https://nerdpress.org/2022/07/18/converting-umlaute-with-symfony-string-component/</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 18 Jul 2022 10:03:11 +0000</pubDate>
				<category><![CDATA[Symfony]]></category>
		<category><![CDATA[umlaut]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=3159</guid>

					<description><![CDATA[<p>There are multiple PHP native ways to convert umlaute and other special characters to ascii save formats, but most of them i experience insufficient in the one or other way. Since i am using symfony anyway i can use the String component which has a handy slugger which converts any characters into safe ascii characters.It &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2022/07/18/converting-umlaute-with-symfony-string-component/" class="more-link">Continue reading<span class="screen-reader-text"> "Converting umlaute with symfony String component"</span></a></p>
The post <a href="https://nerdpress.org/2022/07/18/converting-umlaute-with-symfony-string-component/">Converting umlaute with symfony String component</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>There are multiple PHP native ways to convert umlaute and other special characters to ascii save formats, but most of them i experience insufficient in the one or other way.</p>



<p>Since i am using symfony anyway i can use the <a href="https://symfony.com/doc/current/components/string.html" target="_blank" rel="noreferrer noopener" title="https://symfony.com/doc/current/components/string.html">String component</a> which has a handy slugger which converts any characters into safe ascii characters.<br />It is very flexible and can be customized with locales, custom replacements and closures.</p>


<pre class="wp-block-code"><span><code class="hljs language-php">$umlautString = <span class="hljs-string">"Müller Meier"</span>;
$slugger = <span class="hljs-keyword">new</span> Symfony\Component\String\Slugger\AsciiSlugger(<span class="hljs-string">'de'</span>);
$slugger-&gt;slug($umlautString, $seperator = <span class="hljs-string">' '</span>)-&gt;toString();
<span class="hljs-keyword">echo</span> $umlautString; <span class="hljs-comment">// mueller meier</span></code></span></pre>


<p>I guess this will become my go-to method resp. slugger to convert umlaute in any PHP application.</p>



<span id="more-3159"></span>



<p>One example why the PHP native ways have their downsides is iconv.<br />Iconv can transliterate umlauts:</p>


<pre class="wp-block-code"><span><code class="hljs language-php">$string = iconv(<span class="hljs-string">'UTF-8'</span>, <span class="hljs-string">'ASCII//TRANSLIT'</span>, $string);</code></span></pre>


<p>But it can not handle the locale in a convenient way but relies on the system wide locale instead.<br />You need to use the global method <code>setlocale</code> before using it and reset the locale after usage again, which can cause sideeffects and is not very convenient.</p>



<p>From: <a href="https://www.php.net/manual/de/function.iconv.php#105507">https://www.php.net/manual/de/function.iconv.php#105507</a></p>


<pre class="wp-block-code"><span><code class="hljs language-php">$utf8_sentence = <span class="hljs-string">'Weiß, Göbel'</span>;
<span class="hljs-comment">//transliterate</span>
$trans_sentence = iconv(<span class="hljs-string">'UTF-8'</span>, <span class="hljs-string">'ASCII//TRANSLIT'</span>, $utf8_sentence);
<span class="hljs-comment">//gives &#91;Weiss, Gobel]</span>
<span class="hljs-comment">//Germany</span>
setlocale(LC_ALL, <span class="hljs-string">'de_DE'</span>);
$trans_sentence = iconv(<span class="hljs-string">'UTF-8'</span>, <span class="hljs-string">'ASCII//TRANSLIT'</span>, $utf8_sentence);
<span class="hljs-comment">//gives &#91;Weiss, Goebel]</span></code></span></pre>


<p>Thanks to this StackOverflow answer for the tip with the symfony String component. <a href="https://stackoverflow.com/a/68742023/541949" target="_blank" rel="noreferrer noopener">https://stackoverflow.com/a/68742023/541949</a></p>The post <a href="https://nerdpress.org/2022/07/18/converting-umlaute-with-symfony-string-component/">Converting umlaute with symfony String component</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Migrating user table from Mysql to Postgres with Symfony and Doctrine</title>
		<link>https://nerdpress.org/2021/11/10/migrating-user-table-from-mysql-to-postgres-with-symfony-and-doctrine/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Wed, 10 Nov 2021 08:46:07 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[Postgres]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=3087</guid>

					<description><![CDATA[<p>When using bin/console make:entity on Mysql and then later you switch your application to Postgres and you have a table called user, which you most likely have when using security component of Symfony.Then you will receive an error because user is a reserved word in Postgres! An exception occurred while executing 'INSERT INTO user (id, &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2021/11/10/migrating-user-table-from-mysql-to-postgres-with-symfony-and-doctrine/" class="more-link">Continue reading<span class="screen-reader-text"> "Migrating user table from Mysql to Postgres with Symfony and Doctrine"</span></a></p>
The post <a href="https://nerdpress.org/2021/11/10/migrating-user-table-from-mysql-to-postgres-with-symfony-and-doctrine/">Migrating user table from Mysql to Postgres with Symfony and Doctrine</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>When using <code>bin/console make:entity</code> on Mysql and then later you switch your application to Postgres and you have a table called <code>user</code>, which you most likely have when using security component of Symfony.<br />Then you will receive an error because <code>user</code> is a reserved word in Postgres!</p>



<p><code>An exception occurred while executing 'INSERT INTO user (id, email, roles, password, is_verified) VALUES (?, ?, ?, ?, ?)' with params [3, "dev@dev.de", "[]", "your-encrypted-password", 0]:<br />SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "user"<br />LINE 1: INSERT INTO user (id, email, roles, password, is_verified) V...</code></p>



<span id="more-3087"></span>



<p>To fix this you have to escape the table name on your entity, fe. User.php:<br /><br />@<code>ORM\Table(name="`user`")</code></p>



<p>(<strong>note the backticks inside the quotes!)</strong></p>



<p>If you generate the entity with <a href="https://symfony.com/bundles/SymfonyMakerBundle/current/index.html" target="_blank" rel="noreferrer noopener">maker bundle</a>: <code>bin/console make:entity</code> directly on Postgres the backticks are added automatically.<br />But not when you switch the DB type. Then you have to add them manually. :)</p>



<p><br /></p>The post <a href="https://nerdpress.org/2021/11/10/migrating-user-table-from-mysql-to-postgres-with-symfony-and-doctrine/">Migrating user table from Mysql to Postgres with Symfony and Doctrine</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Passing a boolean to the constructor of &#8220;Symfony\Component\Dotenv\Dotenv&#8221; is deprecated</title>
		<link>https://nerdpress.org/2021/04/12/passing-a-boolean-to-the-constructor-of-symfonycomponentdotenvdotenv-is-deprecated/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Mon, 12 Apr 2021 10:06:21 +0000</pubDate>
				<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=3034</guid>

					<description><![CDATA[<p>You might encounter this deprecation message after your upgrade to symfony 5.1 in your symfony project: Since symfony/dotenv 5.1: Passing a boolean to the constructor of &#8220;Symfony\Component\Dotenv\Dotenv&#8221; is deprecated, use &#8220;Dotenv::usePutenv() To fix this, go to config/bootstrap.php and remove the false from the Dotenv constructor:(new Dotenv(false))-&#62;loadEnv(dirname(DIR).'/.env');to(new Dotenv())-&#62;loadEnv(dirname(DIR).'/.env');See: https://github.com/symfony/symfony/issues/37195 Actually the file config/bootstrap.php has been removed &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2021/04/12/passing-a-boolean-to-the-constructor-of-symfonycomponentdotenvdotenv-is-deprecated/" class="more-link">Continue reading<span class="screen-reader-text"> "Passing a boolean to the constructor of &#8220;Symfony\Component\Dotenv\Dotenv&#8221; is deprecated"</span></a></p>
The post <a href="https://nerdpress.org/2021/04/12/passing-a-boolean-to-the-constructor-of-symfonycomponentdotenvdotenv-is-deprecated/">Passing a boolean to the constructor of “Symfony\Component\Dotenv\Dotenv” is deprecated</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>You might encounter this deprecation message after your upgrade to symfony 5.1 in your symfony project:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Since symfony/dotenv 5.1: Passing a boolean to the constructor of &#8220;Symfony\Component\Dotenv\Dotenv&#8221; is deprecated, use &#8220;Dotenv::usePutenv()</p></blockquote>



<p>To fix this, go to <em>config/bootstrap.php</em> and remove the <code>false</code> from the Dotenv constructor:<br /><code>(new Dotenv(false))-&gt;loadEnv(dirname(<strong>DIR</strong>).'/.env');</code><br />to<br /><code>(new Dotenv())-&gt;loadEnv(dirname(<strong>DIR</strong>).'/.env');</code><br />See: https://github.com/symfony/symfony/issues/37195</p>



<p>Actually the file <em>config/bootstrap.php</em> has been removed from symfony 5.1 and was replaced in <a href="https://github.com/symfony/recipes/blob/master/symfony/framework-bundle/5.1/public/index.php" target="_blank" rel="noreferrer noopener" title="https://github.com/symfony/recipes/blob/master/symfony/framework-bundle/5.1/public/index.php">public/index.php</a>.</p>



<p>But since the project was updated from an symfony 4 version the bootrap file is still present.</p>



<p>So another option would be to remove the boostrap file and update the project entirely to <a href="https://github.com/symfony/recipes/tree/master/symfony/framework-bundle/5.1" target="_blank" rel="noreferrer noopener">symfony 5.1 recipe</a>.<br />This is not trivial though as you can see in this corresponfing <a href="https://github.com/symfony/recipes/pull/724" target="_blank" rel="noreferrer noopener">PullRequest</a>.</p>The post <a href="https://nerdpress.org/2021/04/12/passing-a-boolean-to-the-constructor-of-symfonycomponentdotenvdotenv-is-deprecated/">Passing a boolean to the constructor of “Symfony\Component\Dotenv\Dotenv” is deprecated</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Psalm Static Analyzer fails with Symfony&#8217;s builtin preloading file</title>
		<link>https://nerdpress.org/2020/10/20/psalm-static-analyzer-fails-with-symfonys-builtin-preloading-file/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Tue, 20 Oct 2020 08:55:43 +0000</pubDate>
				<category><![CDATA[Symfony]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2951</guid>

					<description><![CDATA[<p>So i updated a symfony app the other day to version 5.1.6 and suddenly the static code analyzer psalm ran appearently in an hangup loop and never terminated. After some investigation it showed that symfony added a .preload.php file to the src directory to enable the new PHP7.4 preloading feature. Unfortunatly psalm parsed this file &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2020/10/20/psalm-static-analyzer-fails-with-symfonys-builtin-preloading-file/" class="more-link">Continue reading<span class="screen-reader-text"> "Psalm Static Analyzer fails with Symfony&#8217;s builtin preloading file"</span></a></p>
The post <a href="https://nerdpress.org/2020/10/20/psalm-static-analyzer-fails-with-symfonys-builtin-preloading-file/">Psalm Static Analyzer fails with Symfony’s builtin preloading file</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>So i updated a symfony app the other day to version 5.1.6 and suddenly the static code analyzer <a href="https://psalm.dev/" target="_blank" rel="noreferrer noopener">psalm</a> ran appearently in an hangup loop and never terminated.</p>



<p>After some investigation it showed that symfony added a <strong>.preload.php</strong> file to the src directory to enable the new PHP7.4 preloading feature.</p>



<p>Unfortunatly psalm parsed this file and followed all includes.<br>This took it so long that i took it for an endless loop.</p>



<p>There is some<a href="https://github.com/symfony/symfony/issues/38334#issuecomment-700237706" target="_blank" rel="noreferrer noopener"> discussion</a> in symfony github issues about this and the conclusion was to replace src/.preload.php with config/preload.php which happens now in a recipe.</p>



<span id="more-2951"></span>



<p>So best remove the old preload file</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
rm src/.preload.php
</pre></div>


<p>and rerun the framework bundle recipe:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
composer recipes:install symfony/framework-bundle --force -v
</pre></div>


<p><strong>Caution: this will override your current config and Kernel.php, make a careful diff on the change and revert changes that are unwanted.</strong><br></p>



<p>The new preload file is now in config/preload.php and only available for prod env. <br>So psalm wont pick it up anymore and it will work again as usual.</p>



<p><br>Without updating the recipe, the fix would be to tell psalm to ignore this file in psalm.xml.</p>


<pre class="wp-block-code"><span><code class="hljs language-xml">    <span class="hljs-tag">&lt;<span class="hljs-name">projectFiles</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">directory</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"./src"</span>/&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">ignoreFiles</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">file</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"./src/.preload.php"</span>/&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">ignoreFiles</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">projectFiles</span>&gt;</span></code></span></pre>


<p>:)</p>The post <a href="https://nerdpress.org/2020/10/20/psalm-static-analyzer-fails-with-symfonys-builtin-preloading-file/">Psalm Static Analyzer fails with Symfony’s builtin preloading file</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Disable symfony deprecation warnings in PHPUnit tests</title>
		<link>https://nerdpress.org/2019/08/29/disable-symfony-deprecation-warnings-in-phpunit-tests/</link>
					<comments>https://nerdpress.org/2019/08/29/disable-symfony-deprecation-warnings-in-phpunit-tests/#comments</comments>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Thu, 29 Aug 2019 07:39:23 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[PHPUnit]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2878</guid>

					<description><![CDATA[<p>Symfony&#8217;s deprecation warnings while running tests is a great service to keep track with upcoming changes in newer symfony versions. However these warnings can break your CI/CD pipeline and sometimes you cant fix all deprecation warnings immediatly. To disable them you can set the ENV var SYMFONY_DEPRECATIONS_HELPER=disabled and the warnings will not be displayed anymore &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2019/08/29/disable-symfony-deprecation-warnings-in-phpunit-tests/" class="more-link">Continue reading<span class="screen-reader-text"> "Disable symfony deprecation warnings in PHPUnit tests"</span></a></p>
The post <a href="https://nerdpress.org/2019/08/29/disable-symfony-deprecation-warnings-in-phpunit-tests/">Disable symfony deprecation warnings in PHPUnit tests</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Symfony&#8217;s deprecation warnings while running tests is a great service to keep track with upcoming changes in newer symfony versions.<br> However these warnings can break your CI/CD pipeline and sometimes you cant fix all deprecation warnings immediatly.</p>



<p>To disable them you can set the ENV var <br><code>SYMFONY_DEPRECATIONS_HELPER=disabled</code> <br>and the warnings will not be displayed anymore and CI/CD will pass again.<strong><br>Update from comments:</strong><code><br>SYMFONY_DEPRECATIONS_HELPER=weak</code> does also work and will still show the deprecation warnings count. (Thx Max)</p>



<span id="more-2878"></span>



<p> This was introduced a while ago with this <a rel="noreferrer noopener" aria-label="PullRequest (opens in a new tab)" href="https://github.com/symfony/symfony/pull/18232" target="_blank">PullRequest</a> and works for symfony >= 3.1.</p>



<p>So for running the tests manually, do like this:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
SYMFONY_DEPRECATIONS_HELPER=disabled vendor/bin/phpunit
</pre></div>


<p>Or add it to the phpunit.xml</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
&amp;lt;php&gt;
    &amp;lt;ini name=&quot;error_reporting&quot; value=&quot;-1&quot; /&gt;
    &amp;lt;env name=&quot;KERNEL_CLASS&quot; value=&quot;App\Kernel&quot; /&gt;
    ...
    &amp;lt;env name=&quot;SYMFONY_DEPRECATIONS_HELPER&quot; value=&quot;disabled&quot; /&gt;
&amp;lt;/php&gt;
</pre></div>


<p>With bitbucket pipelines it looks like this:</p>



<pre class="wp-block-preformatted"><code>pipelines:<br>   branches:<br>     master:<br>       - step:<br>           script:<br>             - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer<br>             - composer install<br>             - SYMFONY_DEPRECATIONS_HELPER=disabled composer test<br>             - composer check-style</code></pre>The post <a href="https://nerdpress.org/2019/08/29/disable-symfony-deprecation-warnings-in-phpunit-tests/">Disable symfony deprecation warnings in PHPUnit tests</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2019/08/29/disable-symfony-deprecation-warnings-in-phpunit-tests/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>mocking APIs with Guzzle</title>
		<link>https://nerdpress.org/2017/12/11/mocking-apis-with-guzzle/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Mon, 11 Dec 2017 16:10:17 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[guzzle]]></category>
		<category><![CDATA[mocks]]></category>
		<category><![CDATA[PHPUnit]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2803</guid>

					<description><![CDATA[<p>When working with APIs you sometimes cant use the live API in the tests. Because you dont own the API, dont want to spam, cant create entities for testing or various other reasons. Then you need to mock the API and deliever responses from fixtures. Though there is this term of &#8220;Don&#8217;t mock what you &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2017/12/11/mocking-apis-with-guzzle/" class="more-link">Continue reading<span class="screen-reader-text"> "mocking APIs with Guzzle"</span></a></p>
The post <a href="https://nerdpress.org/2017/12/11/mocking-apis-with-guzzle/">mocking APIs with Guzzle</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>When working with APIs you sometimes cant use the live API in the tests.<br />
Because you dont own the API, dont want to spam, cant create entities for testing or various other reasons.</p>
<p>Then you need to mock the API and deliever responses from fixtures.<br />
Though there is this term of &#8220;<em>Don&#8217;t mock what you don&#8217;t own</em>&#8221; we will mock the API because we dont own it. :)</p>
<p><a href="https://github.com/julienfalque/http-mock" rel="noopener" target="_blank">https://github.com/julienfalque/http-mock</a> is a nice library which helps a lot when mocking an API.<br />
And when your client is using Guzzle there is also a <a href="https://github.com/julienfalque/http-mock-guzzle" rel="noopener" target="_blank">Guzzle handler</a> for HttpMock that makes integration easy.</p>
<p>How does this work?<br />
<span id="more-2803"></span></p>
<p>See below but with caution: its pseudo code but you get the idea dont you? :)</p>
<p>1. lets create a HttpMock Server object through a Factory<br />
and define the endpoints and assign the fixture.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

namespace Nerdpress\Tests;

use GuzzleHttp\Psr7\Response;
use Jfalque\HttpMock\Server;

class HttpMockFactory
{
    public static function create(): Server
    {
        $server = (new Server())-&gt;whenUri('http://mock.api/action/ding')
                                -&gt;andWhenMethod('POST')
                                -&gt;return($foo = new Response(200, &#x5B;],
                                    file_get_contents(__DIR__.'/fixtures/DingResponse.xml')))
                                -&gt;end();

        return $server;
    }
}
</pre>
<p>2. lets create a mock Guzzle client that takes the HttpMock server and delegates the requests.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

namespace Nerdpress\Tests;

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Middleware;
use Jfalque\HttpMock\Guzzle\HttpMockHandler;
use Jfalque\HttpMock\Server;
use Psr\Http\Message\RequestInterface;

class HttpClientMock implements ClientInterface
{
    /**
     * @var Server
     */
    protected $server;
    /**
     * @var \GuzzleHttp\Client
     */
    protected $delegate;
    /**
     * The set of requests that have been sent through the client.
     *
     * @var \Psr\Http\Message\RequestInterface&#x5B;]
     */
    protected $requestHistory = &#x5B;];

    /**
     * HttpClientMock constructor.
     * @param Server $server
     * @param array $options
     */
    public function __construct(Server $server, array $options = &#x5B;])
    {
        $this-&gt;initialize($server, $options);
    }

    /**
     * {@inheritDoc}
     */
    public function send(RequestInterface $request, array $options = &#x5B;])
    {
        return $this-&gt;delegate-&gt;send($request, $options);
    }

    /**
     * {@inheritDoc}
     */
    public function sendAsync(RequestInterface $request, array $options = &#x5B;])
    {
        return $this-&gt;delegate-&gt;sendAsync($request, $options);
    }

    /**
     * {@inheritDoc}
     */
    public function request($method, $uri, array $options = &#x5B;])
    {
        return $this-&gt;delegate-&gt;request($method, $uri, $options);
    }

    /**
     * {@inheritDoc}
     */
    public function requestAsync($method, $uri, array $options = &#x5B;])
    {
        return $this-&gt;delegate-&gt;requestAsync($method, $uri, $options);
    }

    /**
     * {@inheritDoc}
     */
    public function getConfig($option = null)
    {
        return $this-&gt;delegate-&gt;getConfig($option);
    }

    /**
     * @return RequestInterface&#x5B;]
     */
    public function getRequestHistory(): array
    {
        return $this-&gt;requestHistory;
    }

    /**
     * @param Server $server
     * @param array $options
     */
    private function initialize(Server $server, array $options)
    {
        $this-&gt;requestHistory = &#x5B;];
        $history              = Middleware::history($this-&gt;requestHistory);
        $stack                = HttpMockHandler::createStack($server);
        $stack-&gt;push($history);
        $client         = new Client(array_merge($options, &#x5B;
            'handler' =&gt; $stack,
        ]));
        $this-&gt;delegate = $client;
    }
}
</pre>
<p>3. lets say we use symfony and create services for the mocks</p>
<pre class="brush: yaml; title: ; notranslate">
services:
  Nerdpress\Tests\HttpMockFactory:
  Nerdpress\Tests\HttpClientMock:
    arguments: &#x5B;&quot;@=service('Nerdpress\\\\Tests\\\\HttpMockFactory').create()&quot;, base_uri: 'http://mock.api']

my_bundle:
  client: 'Nerdpress\Tests\HttpClientMock'
</pre>
<p>4. lets write a test and use the client and work on the returned fixtures</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

namespace Nerdpress\Tests;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class RequestTest extends WebTestCase
{

    protected function setUp()
    {
        parent::setUp();
        static::createClient();
    }

    public function testRequest()
    {
        $container     = static::$kernel-&gt;getContainer();

        $request = $container-&gt;get('my_bundle.request.with.client');

        $payload = &#x5B;'testo' =&gt; 'bert'];
        $response = $request-&gt;send($payload);

        //hey lets have a look at the request
        $reqs = $container-&gt;get('Nerdpress\Tests\HttpClientMockt')-&gt;getRequestHistory();
        $sendedRequest = $reqs&#x5B;0]&#x5B;'request']-&gt;getBody()-&gt;__toString();

        $this-&gt;assertEquals($sendedRequest, '&lt;req&gt;&lt;action type=&quot;testo&quot;&gt;bert&lt;/action&gt;&lt;/req&gt;');
        $this-&gt;assertEquals('you got pinged', $response-&gt;getData());
    }
}
</pre>
<p>Happy Testing :)</p>The post <a href="https://nerdpress.org/2017/12/11/mocking-apis-with-guzzle/">mocking APIs with Guzzle</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
