of the few PHP projects (...) promoting PHP projects (...) promoting radical changes to the way radical changes to the way developers work developers work Fabien Potencier Fabien Potencier
$sql = “SELECT * FROM orders WHERE client_id = $GET['client_id']“; $result = mysql_query($sql); if ($result) { while ($row = mysql_fetch_row($result)) { echo “<tr><td>$row['label']</td><td>$row['value']</td><tr>”; } } ?> </table> <?php include 'includes/closedb.php'; include 'includes/footer.inc'; ?> <?php include 'includes/opendb.php'; include 'includes/header.inc'; ?> <h1>Orders</h1> <table> <?php $sql = “SELECT * FROM orders WHERE client_id = $GET['client_id']“; $result = mysql_query($sql); if ($result) { while ($row = mysql_fetch_row($result)) { echo “<tr><td>$row['label']</td><td>$row['value']</td><tr>”; } } ?> </table> <?php include 'includes/closedb.php'; include 'includes/footer.inc'; ?> PHP began with code like that (me too) PHP began with code like that (me too)
$sql = “SELECT * FROM orders WHERE client_id = $GET['client_id']“; $result = mysql_query($sql); if ($result) { while ($row = mysql_fetch_row($result)) { echo “<tr><td>$row['label']</td><td>$row['value']</td><tr>”; } } ?> </table> <?php include 'includes/closedb.php'; include 'includes/footer.inc'; ?> <?php include 'includes/opendb.php'; include 'includes/header.inc'; ?> <h1>Orders</h1> <table> <?php $sql = “SELECT * FROM orders WHERE client_id = $GET['client_id']“; $result = mysql_query($sql); if ($result) { while ($row = mysql_fetch_row($result)) { echo “<tr><td>$row['label']</td><td>$row['value']</td><tr>”; } } ?> </table> <?php include 'includes/closedb.php'; include 'includes/footer.inc'; ?> We want to improve our work We want to improve our work DIFFICULT TO REUSE SECURITY RISK NO SEPARATION OF CONCERNS NOT TESTED!
study by David S. Janzen[1]: According to university study by David S. Janzen[1]: • reduces the number of lines of code reduces the number of lines of code • improves productivity improves productivity • less effort per line-of-code less effort per line-of-code • improves code structure improves code structure • makes developer more confident about their work makes developer more confident about their work [1] http://src.acm.org/subpages/gf_entries_06/DavidJanzen_src_gf06.pdf
improves the code stability and quality: Further improves the code stability and quality: • http://research.microsoft.com/en-us/groups/ese/nagappan_tdd.pdf http://research.microsoft.com/en-us/groups/ese/nagappan_tdd.pdf • http://research.microsoft.com/en-us/groups/ese/fp17288-bhat.pdf http://research.microsoft.com/en-us/groups/ese/fp17288-bhat.pdf • and others... and others... Most successful Theodo Most successful Theodo projects were written using projects were written using the TDD technique. the TDD technique.
use Phake; class CmsEnablerExtensionTest extends \PHPUnit_Framework_TestCase { public function setUp() { $this->securityContext = Phake::mock('Symfony\Component\Security\Core\SecurityContextInterface'); $this->enabler = new CmsEnablerExtension($this->securityContext); } } <?php namespace Theodo\CmsBundle\Tests\Twig; use Theodo\CmsBundle\Twig\CmsEnablerExtension; use Phake; class CmsEnablerExtensionTest extends \PHPUnit_Framework_TestCase { public function setUp() { $this->securityContext = Phake::mock('Symfony\Component\Security\Core\SecurityContextInterface'); $this->enabler = new CmsEnablerExtension($this->securityContext); } }
use Phake; class CmsEnablerExtensionTest extends \PHPUnit_Framework_TestCase { public function setUp() { $this->securityContext = Phake::mock('Symfony\Component\Security\Core\SecurityContextInterface'); $this->enabler = new CmsEnablerExtension($this->securityContext); } public function testChecksIfCmsShouldBeEnabled() { Phake::when($this->securityContext)->isGranted('ROLE_ADMIN', null) ->thenReturn(true); } } <?php namespace Theodo\CmsBundle\Tests\Twig; use Theodo\CmsBundle\Twig\CmsEnablerExtension; use Phake; class CmsEnablerExtensionTest extends \PHPUnit_Framework_TestCase { public function setUp() { $this->securityContext = Phake::mock('Symfony\Component\Security\Core\SecurityContextInterface'); $this->enabler = new CmsEnablerExtension($this->securityContext); } public function testChecksIfCmsShouldBeEnabled() { Phake::when($this->securityContext)->isGranted('ROLE_ADMIN', null) ->thenReturn(true); } }
use Phake; class CmsEnablerExtensionTest extends \PHPUnit_Framework_TestCase { public function setUp() { $this->securityContext = Phake::mock('Symfony\Component\Security\Core\SecurityContextInterface'); $this->enabler = new CmsEnablerExtension($this->securityContext); } public function testChecksIfCmsShouldBeEnabled() { Phake::when($this->securityContext)->isGranted('ROLE_ADMIN', null) ->thenReturn(true); $this->assertTrue($this->enabler->isEnabled()); Phake::verify($this->securityContext, Phake::times(1))->isGranted('ROLE_ADMIN', null); } } <?php namespace Theodo\CmsBundle\Tests\Twig; use Theodo\CmsBundle\Twig\CmsEnablerExtension; use Phake; class CmsEnablerExtensionTest extends \PHPUnit_Framework_TestCase { public function setUp() { $this->securityContext = Phake::mock('Symfony\Component\Security\Core\SecurityContextInterface'); $this->enabler = new CmsEnablerExtension($this->securityContext); } public function testChecksIfCmsShouldBeEnabled() { Phake::when($this->securityContext)->isGranted('ROLE_ADMIN', null) ->thenReturn(true); $this->assertTrue($this->enabler->isEnabled()); Phake::verify($this->securityContext, Phake::times(1))->isGranted('ROLE_ADMIN', null); } }
use Phake; class CmsEnablerExtensionTest extends \PHPUnit_Framework_TestCase { public function setUp() { $this->securityContext = Phake::mock('Symfony\Component\Security\Core\SecurityContextInterface'); $this->enabler = new CmsEnablerExtension($this->securityContext); } public function testChecksIfCmsShouldBeEnabled() { Phake::when($this->securityContext)->isGranted('ROLE_ADMIN', null) ->thenReturn(true); $this->enabler->setEnv('cms'); $this->assertTrue($this->enabler->isEnabled()); $this->enabler->setEnv('prod'); $this->assertFalse($this->enabler->isEnabled()); Phake::verify($this->securityContext, Phake::times(1))->isGranted('ROLE_ADMIN', null); } } <?php namespace Theodo\CmsBundle\Tests\Twig; use Theodo\CmsBundle\Twig\CmsEnablerExtension; use Phake; class CmsEnablerExtensionTest extends \PHPUnit_Framework_TestCase { public function setUp() { $this->securityContext = Phake::mock('Symfony\Component\Security\Core\SecurityContextInterface'); $this->enabler = new CmsEnablerExtension($this->securityContext); } public function testChecksIfCmsShouldBeEnabled() { Phake::when($this->securityContext)->isGranted('ROLE_ADMIN', null) ->thenReturn(true); $this->enabler->setEnv('cms'); $this->assertTrue($this->enabler->isEnabled()); $this->enabler->setEnv('prod'); $this->assertFalse($this->enabler->isEnabled()); Phake::verify($this->securityContext, Phake::times(1))->isGranted('ROLE_ADMIN', null); } }
/** * @group unit */ class CmsEnablerExtensionTest extends \PHPUnit_Framework_TestCase { public function setUp() { $this->securityContext = Phake::mock('Symfony\Component\Security\Core\SecurityContextInterface'); $this->enabler = new CmsEnablerExtension($this->securityContext); } <?php namespace Theodo\CmsBundle\Tests\Twig; use Theodo\CmsBundle\Twig\CmsEnablerExtension; use Phake; /** * @group unit */ class CmsEnablerExtensionTest extends \PHPUnit_Framework_TestCase { public function setUp() { $this->securityContext = Phake::mock('Symfony\Component\Security\Core\SecurityContextInterface'); $this->enabler = new CmsEnablerExtension($this->securityContext); } $ bin/phpunit -c app/ --group unit $ bin/phpunit -c app/ --group unit