Skip to content

Instantly share code, notes, and snippets.

@everzet
Created May 19, 2011 20:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save everzet/981729 to your computer and use it in GitHub Desktop.
Save everzet/981729 to your computer and use it in GitHub Desktop.
comparison of BDD-style PHPUnit VS PHPSpec1 (has almost nothing to do with phpspec2)
<?php
// how that:
class DescribeContextZend extends PHPSpec_Context
{
public function itShouldSetControllerNameUsingContextClass()
{
$context = new DescribeFooController;
$this->spec($context->getController())->should->be('Foo');
}
public function itShouldCreateFrontControllerWhenInstantiated()
{
$context = new DescribeFooController;
$this->spec($context->getFrontController())->should
->beAnInstanceOf('Zend_Controller_Front');
}
}
// is better than that:
class ContextZendTest extends PHPUnit_Framework_TestCase
{
/**
* @Test
*/
public function itShouldSetControllerNameUsingContextClass()
{
$context = new DescribeFooController;
$this->assertEquals('Foo', $context->getController());
}
/**
* @Test
*/
public function itShouldCreateFrontControllerWhenInstantiated()
{
$context = new DescribeFooController;
$this->assertInstanceOf('Zend_Controller_Front', $context->getFrontController());
}
}
// ? :-)
// And what's even worse - second one is really-really more readable!
@avalanche123
Copy link

👍 people make libraries for the sake of making libraries nowadays :)

@MarcelloDuarte
Copy link

@avalanche123 PHPSpec was written back in 2007, not with the intention to replace PHPUnit. Pádraic saw that BDD was a good idea and wanted to make it possible for PHP developers to use a BDD framework. everzet spec could have been written slightly better, as I have shown him, but I agree that the DSL in PHPSpec is far from perfect, specially the OO version (that seems to be there because of PHPUnit influence, interesting enough). I agree with you that people jump very quickly into criticising and writing new libraries instead of contributing to existing open source projects. That's why I joined as a contributor to PHPSpec instead of creating my own. I also see BDD's value and found in PHPSpec a potential to create a proper spec framework. Plus I also think $result->should->be(42) better than $this->assertEquals(42, $result), because it keeps the focus on feature rather then code.

@MarcelloDuarte
Copy link

Please refer to the update of the syntax in phpspec version 2: https://gist.github.com/07831388218f192068ce

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment