<?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>Internet Strategy Guide &#187; Exception handling</title>
	<atom:link href="http://phpprotip.com/tag/exception-handling/feed/" rel="self" type="application/rss+xml" />
	<link>http://phpprotip.com</link>
	<description>Together we can defeat the internet</description>
	<lastBuildDate>Tue, 08 Nov 2011 06:19:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>expected exceptions annotations, mocked object calls, oh my.</title>
		<link>http://phpprotip.com/2010/12/expected-exceptions-annotations-mocked-object-calls-oh-my/</link>
		<comments>http://phpprotip.com/2010/12/expected-exceptions-annotations-mocked-object-calls-oh-my/#comments</comments>
		<pubDate>Fri, 24 Dec 2010 15:06:11 +0000</pubDate>
		<dc:creator>chance</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phpunit]]></category>
		<category><![CDATA[unittesting]]></category>
		<category><![CDATA[Exception handling]]></category>
		<category><![CDATA[Mock object]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://phpprotip.com/?p=490</guid>
		<description><![CDATA[Note: I have tested this in PHPUnit 3.4.1 and haven't tried it out in 3.5. Anyone who has worked with PHPUnit has most likely worked with expected exceptions and mock objects. The nice thing about working with expected exceptions is that we have access to a handy @expectedException annotation. I've gotten into the habit of [...]]]></description>
			<content:encoded><![CDATA[<p>Note: I have tested this in <a class=\"zem_slink freebase/en/phpunit\" title=\"PHPUnit\" rel=\"homepage nofollow\" href="http://phpprotip.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5waHB1bml0LmRlLw==">PHPUnit</a> 3.4.1 and haven't tried it out in 3.5.<br />
Anyone who has worked with PHPUnit has most likely worked with expected <a class=\"zem_slink freebase/en/exception_handling\" title=\"Exception handling\" rel=\"wikipedia nofollow\" href="http://phpprotip.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2VuLndpa2lwZWRpYS5vcmcvd2lraS9FeGNlcHRpb25faGFuZGxpbmc=">exceptions</a> and mock objects. The nice thing about working  with expected exceptions is that we have access to a handy @expectedException annotation. I've gotten into the habit of using this for exceptions my fixtures should throw but also for when I'm using a <a class=\"zem_slink freebase/en/mock_object\" title=\"Mock object\" rel=\"wikipedia nofollow\" href="http://phpprotip.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2VuLndpa2lwZWRpYS5vcmcvd2lraS9Nb2NrX29iamVjdA==">mock object</a> to verify a method call. So my tests usually expect foo_exception for fixture throws and when i'm testing method calls via a mock, they expect Exception. Therein lies my problem. Because all my custom class exceptions obviously extend the Exception class, I can get some false positives in testing.</p>
<pre class="php">equire_once <span style="color: #ff0000;">'Zend/Loader/Autoloader.php'</span>;
<span style="color: #0000ff;">$loader</span> = Zend_Loader_Autoloader::<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">require_once</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'foo.php'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #006699; font-weight: bold;">class</span> tmpTest <span style="color: #006699; font-weight: bold;">extends</span> PHPUnit_Framework_Testcase
<span style="color: #66cc66;">&#123;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/**
     * @expectedException Exception
     */</span>
    <span style="color: #006699; font-weight: bold;">public</span> <span style="color: #006699; font-weight: bold;">function</span> testFooBar<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0000ff;">$foo</span>=<span style="color: #006699; font-weight: bold;">new</span> foo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0000ff;">$foo</span>-&amp;gt;bar<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/**
     * @expectedException Exception
     */</span>
    <span style="color: #006699; font-weight: bold;">public</span> <span style="color: #006699; font-weight: bold;">function</span> testBarBaz<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0000ff;">$mock</span>=<span style="color: #0000ff;">$this</span>-&amp;gt;getMock<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'foo'</span>,<a href="http://phpprotip.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5waHAubmV0L2FycmF5"><span style="color: #006666;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'baz'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0000ff;">$mock</span>-&amp;gt;expects<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&amp;gt;any<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
         -&amp;gt;method<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'baz'</span><span style="color: #66cc66;">&#41;</span>
         -&amp;gt;will<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&amp;gt;throwException<span style="color: #66cc66;">&#40;</span><span style="color: #006699; font-weight: bold;">new</span> Exception<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'baz'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0000ff;">$mock</span>-&amp;gt;barbaz<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>
<pre class="php"><span style="color: #006699; font-weight: bold;">class</span> foo_exception <span style="color: #006699; font-weight: bold;">extends</span> Exception<span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #006699; font-weight: bold;">class</span> foo
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #006699; font-weight: bold;">public</span> <span style="color: #006699; font-weight: bold;">function</span> bar<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        throw <span style="color: #006699; font-weight: bold;">new</span> foo_exception<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'bar'</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #006699; font-weight: bold;">public</span> <span style="color: #006699; font-weight: bold;">function</span> baz<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        <a href="http://phpprotip.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5waHAubmV0L2VjaG8="><span style="color: #006666;">echo</span></a> <span style="color: #ff0000;">&quot;bwah<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #006699; font-weight: bold;">public</span> <span style="color: #006699; font-weight: bold;">function</span> barbaz<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0000ff;">$this</span>-&amp;gt;bar<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0000ff;">$this</span>-&amp;gt;baz<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>
<p>So here we have an expectation for Exception but if we look at the code, we see that the bar method throws a foo_exception and the testBarBaz test is trying to test for the baz call via a mock that throws an Exception. if we change the annotation to expect foo_exception, the test still passes. This leads me to believe the best way to isolate the behavior we wish to test is to not use annotation for these sorts of tests. Or if you want to use annotation, be sure to use a unique exception for the mock. This means, unfortunately for me, that I'll have to go back through all my tests and ensure there's no false positives.</p>
<p>Lesson learned: be careful using shortcuts (and don't stand in the fire).</p>
<p>On a side note, <a href="http://phpprotip.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cHM6Ly9naXRodWIuY29tL3NlYmFzdGlhbmJlcmdtYW5uL3BocHVuaXQvYmxvYi8zLjUvUEhQVW5pdC9GcmFtZXdvcmsvVGVzdENhc2UucGhwI0w3NDM=">this part of PHPUnit</a> is why those tests will behave that way. The behavior is completely my fault but I wanted to confirm it was behaving because of how it was verifying the expected exception.</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class=\"zemanta-pixie-a\" title=\"Enhanced by Zemanta\" href="http://phpprotip.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy56ZW1hbnRhLmNvbS8="><img class="zemanta-pixie-img" style="border: none; float: right;" src="http://img.zemanta.com/zemified_c.png?x-id=d53ab02f-d978-4960-8750-b7ee8c46327b" alt="Enhanced by Zemanta" /></a><span class="zem-script more-related more-info pretty-attribution"><script src="http://static.zemanta.com/readside/loader.js" type="text/javascript"></script></span></div>
 <img src="http://phpprotip.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=490" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://phpprotip.com/2010/12/expected-exceptions-annotations-mocked-object-calls-oh-my/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>tekx &#8211; lig&#8217;s talk on scalability and mysql</title>
		<link>http://phpprotip.com/2010/05/tekx-ligs-talk-on-scalability-and-mysql/</link>
		<comments>http://phpprotip.com/2010/05/tekx-ligs-talk-on-scalability-and-mysql/#comments</comments>
		<pubDate>Thu, 20 May 2010 21:56:30 +0000</pubDate>
		<dc:creator>chance</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phptek]]></category>
		<category><![CDATA[tekx]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Exception handling]]></category>
		<category><![CDATA[innodb]]></category>
		<category><![CDATA[Replication]]></category>
		<category><![CDATA[scalability]]></category>

		<guid isPermaLink="false">http://phpprotip.com/?p=285</guid>
		<description><![CDATA[@lig will be talking about mysql 5.5 and scalability this session She is Senior Technical Support Engineer for MySQL. We will be covering semi-synchronous replication performance schema SIGNAL/RESIGNAL more partitioning options InnoDB - LOTS of InnoDB (performance and scalability improvements) In 5.5 InnoDB will be the default!!! WOOT. Default replication is asynchronous. Meaning master writes [...]]]></description>
			<content:encoded><![CDATA[<p>@lig will be talking about mysql 5.5 and <a class=\"zem_slink freebase/en/scalability\" title=\"Scalability\" rel=\"wikipedia\" href="http://phpprotip.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2VuLndpa2lwZWRpYS5vcmcvd2lraS9TY2FsYWJpbGl0eQ==">scalability</a> this session She is Senior Technical Support Engineer for <a class=\"zem_slink freebase/en/mysql\" title=\"MySQL\" rel=\"homepage\" href="http://phpprotip.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5teXNxbC5jb20=">MySQL</a>.</p>
<p>We will be covering</p>
<ul>
<li>semi-synchronous replication</li>
<li>performance schema</li>
<li>SIGNAL/RESIGNAL</li>
<li>more partitioning options</li>
<li><a class=\"zem_slink freebase/en/innodb\" title=\"InnoDB\" rel=\"homepage\" href="http://phpprotip.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5pbm5vZGIuY29tLw==">InnoDB</a> - LOTS of InnoDB (performance and scalability improvements)</li>
</ul>
<p>In 5.5 InnoDB will be the default!!! WOOT.</p>
<p>Default replication is asynchronous. Meaning master writes to binary log and the slave connects and "pulls" contents of the binary log. Bad thing is if the master crashes, there's no guarantee that a slave has all committed transanction.</p>
<p>Simi-Synchronous Replication is an alternative to <a class=\"zem_slink freebase/en/replication\" title=\"Replication (computer science)\" rel=\"wikipedia\" href="http://phpprotip.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2VuLndpa2lwZWRpYS5vcmcvd2lraS9SZXBsaWNhdGlvbl8lMjhjb21wdXRlcl9zY2llbmNlJTI5">asynchronous replication</a>. Midway point between asynchronous and fully syncronous. Master only waits for a slave to receive an event. Don't have to wait for slaves to actually commit.</p>
<p>Performance schema tracks at an extremely low level. Just like <a class=\"zem_slink freebase/en/information_schema\" title=\"Information schema\" rel=\"wikipedia\" href="http://phpprotip.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2VuLndpa2lwZWRpYS5vcmcvd2lraS9JbmZvcm1hdGlvbl9zY2hlbWE=">Information schema</a>, tables are views or temporary tables. Activation doesn't cause any change in server behavior. This is designed for advanced users.</p>
<p>Think of SIGNAL as an exception, a way to "return" an error. You get exception-handling logic for <a class=\"zem_slink freebase/en/stored_procedure\" title=\"Stored procedure\" rel=\"wikipedia\" href="http://phpprotip.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2VuLndpa2lwZWRpYS5vcmcvd2lraS9TdG9yZWRfcHJvY2VkdXJl">stored procedures</a>, stored functions, triggers,events and db apps.</p>
<p>RESIGNAL lets you pass error information up. Think of it as a catch. Requres an active handler to execute. Lets you program on your PHP side to catch that very specific handling.</p>
<p><span id="more-285"></span></p>
<p>Column partitioning is variants on RANGE and LIST partitioning. Allows the use of multiple columns in partitioning keys. All columns are taken into account for placing rows in partitions and for partitioning pruning. Supports the use of non-integer columns (DATE/DATETIME/strings...).</p>
<p>Major differences from just RANGE is you don't accept expressions, only names in columns. Looking at an example. You're looking at full tuples, not the individual parts. Both parts of the <a class=\"zem_slink freebase/en/tuple\" title=\"Tuple\" rel=\"wikipedia\" href="http://phpprotip.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2VuLndpa2lwZWRpYS5vcmcvd2lraS9UdXBsZQ==">tuple</a> have to pass.</p>
<p>List column allows for multiple column values. Do not need to convert values to integers to work with. Much easier to read. Example slide is very hot.</p>
<p><a class=\"zem_slink freebase/en/mutual_exclusion\" title=\"Mutual exclusion\" rel=\"wikipedia\" href="http://phpprotip.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2VuLndpa2lwZWRpYS5vcmcvd2lraS9NdXR1YWxfZXhjbHVzaW9u">Mutex</a>: Mutually Exclusive lock. Apparently horrible for concurrency.</p>
<p>Read Ahead is when InnoDB tries to be smart for you. Prefetch multiple pages in the buffer cache asynchronously. You can now control when InnoDB performs a read-aahead operation by setting innodb_read_ahead_threshold. Default is 56.</p>
<p>Edit/Note: There was a lot more discussed by @lig but it was over my head a bit. I'll try to look at her slides and see if I can understand them. Trying the slideshare embed below so that others can see. Feel free to explain the rest of the slides to me because, like i said, they're beyond my current skill level.</p>
<div id="__ss_4184212" style="width: 425px;"><strong style="display: block; margin: 12px 0 4px;"><a title=\"MySQL 5.5\" href="http://phpprotip.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5zbGlkZXNoYXJlLm5ldC9saWdheWEvbXlzcWwtNTU=">MySQL 5.5</a></strong><object id="__sse4184212" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=5-5talk-100520185426-phpapp02&amp;stripped_title=mysql-55" /><param name="name" value="__sse4184212" /><param name="allowfullscreen" value="true" /><embed id="__sse4184212" type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=5-5talk-100520185426-phpapp02&amp;stripped_title=mysql-55" name="__sse4184212" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="padding: 5px 0 12px;">View more <a href="http://phpprotip.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5zbGlkZXNoYXJlLm5ldC8=">presentations</a> from <a href="http://phpprotip.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5zbGlkZXNoYXJlLm5ldC9saWdheWE=">Ligaya Turmelle</a>.</div>
</div>
<h6 class="zemanta-related-title" style="font-size: 1em;">Related articles by Zemanta</h6>
<ul class="zemanta-article-ul">
<li class="zemanta-article-ul-li"><a href="http://phpprotip.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5teXNxbHBlcmZvcm1hbmNlYmxvZy5jb20vMjAxMC8wMi8yOC9teXNxbC01LTUtbTItc2NhbGFiaWxpdHkv">MySQL 5.5-m2 scalability</a> (mysqlperformanceblog.com)</li>
<li class="zemanta-article-ul-li"><a href="http://phpprotip.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5teXNxbHBlcmZvcm1hbmNlYmxvZy5jb20vMjAxMC8wNS8yNS9mbGFzaGNhY2hlLXRwY2Mtd29ya2xvYWQv">FlashCache: tpcc workload</a> (mysqlperformanceblog.com)</li>
</ul>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class=\"zemanta-pixie-a\" title=\"Reblog this post [with Zemanta]\" href="http://phpprotip.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3JlYmxvZy56ZW1hbnRhLmNvbS96ZW1pZmllZC82MGFlZmUwNC0xNGNmLTQxZjgtOTFiZC1kMmQ2NGM2M2IxMWIv"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/reblog_a.png?x-id=60aefe04-14cf-41f8-91bd-d2d64c63b11b" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related more-info pretty-attribution"><script src="http://static.zemanta.com/readside/loader.js" type="text/javascript"></script></span></div>
 <img src="http://phpprotip.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=285" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://phpprotip.com/2010/05/tekx-ligs-talk-on-scalability-and-mysql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

