-
-
Save everzet/981729 to your computer and use it in GitHub Desktop.
| <?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 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.
Please refer to the update of the syntax in phpspec version 2: https://gist.github.com/07831388218f192068ce
👍 people make libraries for the sake of making libraries nowadays :)