& TechAdemy Founder of the Dutch Web Alliance. Development in PHP, Python, C, Java. Lead developer of Saffire. Blog: http://adayinthelifeof.nl Email: [email protected] Twitter: @jaytaph
• Hours and hours of trying to setup our systems for PHPUnit. • Spending ages on trying our first unit tests. • Never ever reaching the advanced stuff..
public function testBlahBlah() { $foo = new Foo(); $this->assertEquals($foo->baz(), 1); } public function testIsOdd() { $foo = new Foo(); $this->assertTrue($foo->isOdd(1)); } public function testDoesIsOddReturnFalseWhenAnEvenDigitIsGiven { $foo = new Foo(); $this->assertFalse($foo->isOdd(2)); } }
separately and without dependencies. • Test “units”, not “applications” • MVC: controller tests, but these are not unit tests. • Be careful with external resources (DB, Mail, HTTP etc)
public function getPaymentProvider() { return $this->_psp; } public function pay(Article $article) { $psp = $this->getPaymentProvider(); $psp->setAmount($article->getAmount()); return $psp->pay(); }