{"id":2559,"date":"2013-11-11T16:30:31","date_gmt":"2013-11-11T21:30:31","guid":{"rendered":"http:\/\/www.testingtv.com\/?p=2559"},"modified":"2013-11-11T16:30:31","modified_gmt":"2013-11-11T21:30:31","slug":"writing-unit-tests-using-phpunit","status":"publish","type":"post","link":"https:\/\/www.testingtv.com\/2013\/11\/11\/writing-unit-tests-using-phpunit\/","title":{"rendered":"Writing Unit Tests Using PHPUnit"},"content":{"rendered":"<p>A lot of people will tell you that unit testing in PHP is easy, but in practice it&#8217;s one of the hardest disciplines to get right. When you&#8217;ve never written unit tests before you&#8217;ll probably have a million questions really fast; your code has got a lot of dependencies, runs queries on your database and sends out e-mails, and there seems to be no way to write reliable tests for this code that you can actually use time after time.<!--more--><\/p>\n<p>This talk is a hands-on introduction to writing unit tests using <a href=\"http:\/\/phpunit.de\/\">PHPUnit<\/a>. We&#8217;ll be writing some actual unit tests for (sometimes problematic) pieces of code that you could come across while testing real-life applications. I&#8217;ll explain how you could apply TDD and how to use it into your advantage, and I&#8217;ll come with some suggestions on how you could convince your boss that unit testing is important and actually worth the effort on the long run.<\/p>\n<p>[youtube Jr8jAK86Uf0]<\/p>\n<p>Video producer: <a href=\"http:\/\/phpconference.co.uk\/\">http:\/\/phpconference.co.uk\/<\/a><\/p>\n<p>Further reading:<br \/>\n* <a href=\"http:\/\/www.softwaretestingmagazine.com\/knowledge\/php-unit-testing-with-phpunit\/\">PHP Unit Testing with PHPUnit<\/a><br \/>\n* <a href=\"http:\/\/www.softwaretestingmagazine.com\/knowledge\/using-mocks-and-stubs-in-phpunit\/\">Using Mocks and Stubs in PHPUnit<\/a><br \/>\n* <a href=\"http:\/\/www.softwaretestingmagazine.com\/knowledge\/phpunit-tips-tricks\/\">PHPUnit Tips &amp; Tricks<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A lot of people will tell you that unit testing in PHP is easy, but in practice it&#8217;s one of the hardest disciplines to get right. When you&#8217;ve never written unit tests before you&#8217;ll probably have a million questions really fast; your code has got a lot of dependencies, runs &hellip;<\/p>\n","protected":false},"author":3,"featured_media":3049,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38],"tags":[29],"class_list":["post-2559","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-unit-testing","tag-php"],"_links":{"self":[{"href":"https:\/\/www.testingtv.com\/wp-json\/wp\/v2\/posts\/2559","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testingtv.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.testingtv.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.testingtv.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testingtv.com\/wp-json\/wp\/v2\/comments?post=2559"}],"version-history":[{"count":0,"href":"https:\/\/www.testingtv.com\/wp-json\/wp\/v2\/posts\/2559\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.testingtv.com\/wp-json\/wp\/v2\/media\/3049"}],"wp:attachment":[{"href":"https:\/\/www.testingtv.com\/wp-json\/wp\/v2\/media?parent=2559"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingtv.com\/wp-json\/wp\/v2\/categories?post=2559"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingtv.com\/wp-json\/wp\/v2\/tags?post=2559"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}