<?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>Matthew Turland &#187; PHPUnit</title>
	<atom:link href="http://matthewturland.com/tag/phpunit/feed/" rel="self" type="application/rss+xml" />
	<link>http://matthewturland.com</link>
	<description></description>
	<lastBuildDate>Sun, 18 Jul 2010 14:29:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Database Testing with PHPUnit and MySQL</title>
		<link>http://matthewturland.com/2010/01/04/database-testing-with-phpunit-and-mysql/</link>
		<comments>http://matthewturland.com/2010/01/04/database-testing-with-phpunit-and-mysql/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 16:00:47 +0000</pubDate>
		<dc:creator>Matthew Turland</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHPUnit]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://matthewturland.com/?p=49</guid>
		<description><![CDATA[I recently made a contribution to the PHPUnit project that I thought I&#8217;d take a blog post to discuss. One of the extensions bundled with PHPUnit adds support for database testing. This extension was contributed by Mike Lively and is a port of the DbUnit extension for the JUnit Java unit testing framework. If you&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<p>I recently made a contribution to the <a title="PHPUnit" href="http://www.phpunit.de/">PHPUnit</a> project that I thought I&#8217;d take a blog post to discuss. One of the extensions bundled with PHPUnit adds support for <a title="Chapter 9. Database Testing" href="http://www.phpunit.de/manual/3.4/en/database.html">database testing</a>. This extension was contributed by <a title="Digital Sandwich" href="http://www.ds-o.com/">Mike Lively</a> and is a port of the <a title="DbUnit - Core Components" href="http://www.dbunit.org/components.html">DbUnit</a> extension for the <a title="Welcome to JUnit.org! | JUnit.org" href="http://www.junit.org/">JUnit</a> Java unit testing framework. If you&#8217;re interested in learning more about database unit testing, check out <a title="Testing PHP/MySQL Applications with PHPUnit/DbUnit  - Sebastian Bergmann" href="http://sebastian-bergmann.de/archives/773-Testing-PHPMySQL-Applications-with-PHPUnitDbUnit.html">this presentation</a> by <a title="Sebastian Bergmann  - Sebastian Bergmann" href="http://sebastian-bergmann.de/">Sebastian Bergmann</a> on the subject.</p>
<p>One of the major components of both extensions is the data set. Database unit tests involve loading a seed data set into a database, executing code that performs an operation on that data set such as deleting a record, and then checking the state of the data set to confirm that the operation had the desired effect. DbUnit supports <a title="DbUnit - Core Components" href="http://www.dbunit.org/components.html">multiple formats</a> for seed data sets. The PHPUnit Database extension includes <a title="Chapter 9. Database Testing" href="http://www.phpunit.de/manual/3.4/en/database.html#database.datasets">support</a> for DbUnit&#8217;s XML and flat XML formats plus <acronym title="Comma Separated Values">CSV</acronym> format as well.</p>
<p>If you&#8217;re using <a title="MySQL ::  The world's most popular open source database" href="http://www.mysql.com/">MySQL</a> as your database, CSV has been the only format supported by both the <a title="MySQL ::   MySQL 5.0 Reference Manual :: 4.5.4 mysqldump — A Database Backup Program" href="http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html#option_mysqldump_fields">mysqldump</a> utility and the PHPUnit Database extension up to this point. My contribution adds support for its <a title="MySQL ::   MySQL 5.0 Reference Manual :: 4.5.4 mysqldump — A Database Backup Program" href="http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html#option_mysqldump_xml">XML format</a> to the extension. While this support was developed to work in the PHPUnit 3.4.x branch, it won&#8217;t be available in a stable release until 3.5.0. In the meantime, this is how you can use it now.</p>
<ol>
<li>Go to the <a title="Commit fad913fd84720f889e1d3415e775f68304e76f52 to elazar's phpunit - GitHub" href="http://github.com/sebastianbergmann/phpunit/commit/fad913fd84720f889e1d3415e775f68304e76f52">commit</a> on Github and apply the additions and modifications included in it to your PHPUnit installation.</li>
<li>From a shell, get your XML seed data set and store it in a location accessible to your unit test cases.
<pre class="brush: bash;">mysqldump --xml -t -u username -p database &gt; seed.xml</pre>
</li>
<li>Creat a test case class that extends PHPUnit_Extensions_Database_TestCase. Implement getConnection() and getDataSet() as per the documentation where the latter will include a method call to create the data set from the XML file as shown below.
<pre class="brush: php;">$dataSet = $this-&gt;createMySQLXMLDataSet('/path/to/seed.xml');</pre>
</li>
<li>At this point, you can execute operations on the database to get it to its expected state following a test, produce an XML dump of the database in that state, and then compare that dump to the actual database contents in a test method to confirm that the two are equal.
<pre class="brush: php;">$expected = $this-&gt;createMySQLXMLDataSet('/path/to/expected.xml');
$actual = new PHPUnit_Extension_Database_DataSet_QueryDataSet($this-&gt;getConnection());
// Specify a SELECT query as the 2nd parameter here to limit the data set, else the entire table is used
$actual-&gt;addTable('tablename');
$this-&gt;assertDataSetsEqual($expected, $actual);</pre>
</li>
</ol>
<p>That&#8217;s it! Hopefully this proves useful to <a title="Twitter / Trevor Morse: @elazar OMG, yes! I've bee ..." href="http://twitter.com/trevor_morse/status/7239323093">someone else</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewturland.com/2010/01/04/database-testing-with-phpunit-and-mysql/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>PHPUnit and Xdebug on Ubuntu Karmic</title>
		<link>http://matthewturland.com/2010/01/03/phpunit-and-xdebug-on-ubuntu-karmic/</link>
		<comments>http://matthewturland.com/2010/01/03/phpunit-and-xdebug-on-ubuntu-karmic/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 16:00:20 +0000</pubDate>
		<dc:creator>Matthew Turland</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHPUnit]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Xdebug]]></category>

		<guid isPermaLink="false">http://matthewturland.com/?p=62</guid>
		<description><![CDATA[This is just a quick post to advise anyone who may be using PHPUnit and Xdebug together on Ubuntu Karmic. If you try to upgrade to PHPUnit 3.4.6 and you&#8217;re using the php5-xdebug Ubuntu package (which is Xdebug 2.0.4), you may get output that looks like this: $ sudo pear upgrade phpunit/PHPUnit Did not download [...]]]></description>
			<content:encoded><![CDATA[<p>This is just a quick post to advise anyone who may be using <a title="PHPUnit" href="http://www.phpunit.de/">PHPUnit</a> and <a title="Xdebug - Debugger and Profiler Tool for PHP" href="http://xdebug.org/">Xdebug</a> together on <a title="Ubuntu Home Page | Ubuntu" href="http://www.ubuntu.com/">Ubuntu Karmic</a>. If you try to upgrade to PHPUnit 3.4.6 and you&#8217;re using the <a title="Ubuntu -- Details of package php5-xdebug in karmic" href="http://packages.ubuntu.com/karmic/php5-xdebug">php5-xdebug</a> Ubuntu package (which is Xdebug 2.0.4), you may get output that looks like this:</p>
<pre class="brush: plain;">$ sudo pear upgrade phpunit/PHPUnit
Did not download optional dependencies: pear/Image_GraphViz, pear/Log, use --alldeps to download automatically
phpunit/PHPUnit can optionally use package &quot;pear/Image_GraphViz&quot; (version &gt;= 1.2.1)
phpunit/PHPUnit can optionally use package &quot;pear/Log&quot;
phpunit/PHPUnit can optionally use PHP extension &quot;pdo_sqlite&quot;
phpunit/PHPUnit requires PHP extension &quot;xdebug&quot; (version &gt;= 2.0.5), installed version is 2.0.4
No valid packages found
upgrade failed</pre>
<p>There are two ways to deal with this situation. First off, note that the newer Xdebug 2.0.5 version includes <a title="Xdebug: Updates" href="http://xdebug.org/updates.php">several bugfixes</a> including one related to code coverage reporting. That said, if you still want to continue using the php5-xdebug package anyway, you can force the upgrade by having the PEAR installer ignore dependencies like so:</p>
<pre class="brush: bash;">sudo pear upgrade -n phpunit/PHPUnit</pre>
<p>The other method involves installing Xdebug 2.0.5. First, if you have the php5-xdebug package, remove it.</p>
<pre class="brush: bash;">sudo apt-get remove php5-xdebug</pre>
<p>Next, use the PECL installer to install Xdebug. This requires that you have the php5-dev package installed so that the extension can be compiled locally.</p>
<pre class="brush: bash;">sudo apt-get install php5-dev
sudo pecl install xdebug</pre>
<p>At this point, create the file /etc/php5/conf.d/xdebug.ini if it doesn&#8217;t already exist and populate it with these contents:</p>
<pre class="brush: plain;">zend_extension=/usr/lib/php5/20060613/xdebug.so</pre>
<p>Then bounce Apache so that the new extension will be loaded.</p>
<pre class="brush: bash;">sudo apache2ctl restart</pre>
<p>That&#8217;s it. Hope someone finds this helpful.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewturland.com/2010/01/03/phpunit-and-xdebug-on-ubuntu-karmic/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
