<?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>PHPUnit | Nerdpress.org</title>
	<atom:link href="https://nerdpress.org/category/php/phpunit/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerdpress.org</link>
	<description>...dev, tech problems and solutions.</description>
	<lastBuildDate>Mon, 04 Apr 2022 08:10:00 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.3</generator>
	<item>
		<title>Testing Deprecations with PHPUnit</title>
		<link>https://nerdpress.org/2022/04/04/testing-deprecations-with-phpunit/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Mon, 04 Apr 2022 08:08:26 +0000</pubDate>
				<category><![CDATA[PHPUnit]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=3121</guid>

					<description><![CDATA[<p>When testing deprecations with PHPUnit greater than 9.5.10 you might encounter this error: Failed asserting that exception of type "PHPUnit\Framework\Error\Deprecated" is thrown. The code in the test is as follows: $this-&#62;expectDeprecation(); and the code that should be tested is like this: \trigger_error('foo', \E_USER_DEPRECATED); However PHPUnit does not convert the deprecation to a testable error.By default &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2022/04/04/testing-deprecations-with-phpunit/" class="more-link">Continue reading<span class="screen-reader-text"> "Testing Deprecations with PHPUnit"</span></a></p>
The post <a href="https://nerdpress.org/2022/04/04/testing-deprecations-with-phpunit/">Testing Deprecations with PHPUnit</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p class="wp-block-paragraph">When testing deprecations with PHPUnit greater than 9.5.10 you might encounter this error:</p>



<p class="wp-block-paragraph"><em><code>Failed asserting that exception of type "PHPUnit\Framework\Error\Deprecated" is thrown.</code></em></p>



<p class="wp-block-paragraph">The code in the test is as follows:</p>



<p class="wp-block-paragraph"><code>$this-&gt;expectDeprecation();</code></p>



<p class="wp-block-paragraph">and the code that should be tested is like this:</p>



<p class="wp-block-paragraph"><code>\trigger_error('foo', \E_USER_DEPRECATED);</code></p>



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



<p class="wp-block-paragraph">However PHPUnit does not convert the deprecation to a testable error.<br />By default PHPUnit converts only errors, warnings and notices but not deprecations as we can read here:<br /><a href="https://phpunit.readthedocs.io/en/9.5/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices" target="_blank" rel="noreferrer noopener">https://phpunit.readthedocs.io/en/9.5/writing-tests-for-phpunit.html#testing-php-errors-warnings-and-notices</a></p>



<p class="wp-block-paragraph">So we have to tell PHPUnit to convert also deprecations to exceptions and we do this in the <em>phpunit.xml.dist</em> by setting the attribute</p>



<p class="wp-block-paragraph"><code>convertDeprecationsToExceptions="true"</code></p>



<p class="wp-block-paragraph">in the root element.</p>



<p class="wp-block-paragraph">Now the test should work and deprecations are handled as exceptions.</p>The post <a href="https://nerdpress.org/2022/04/04/testing-deprecations-with-phpunit/">Testing Deprecations with PHPUnit</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
