@ryan.murray
In phpspec, you can reuse common tests using shared examples. Shared examples allow you to define a set of tests that can be reused across different classes or specifications.
Here's how you can reuse common tests in phpspec using shared examples:
1 2 3 4 5 6 7 8 9 |
use PhpSpecObjectBehavior; class SomeTest extends ObjectBehavior { function it_does_something() { // Test logic here } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
use PhpSpecObjectBehavior; class MySpec extends ObjectBehavior { // ... function it_should_do_something() { $this->should('do_something'); $this->doSomething(); } function it_should_reuse_some_test() { $this->beAnInstanceOf('SharedExampleSomeTest'); } } |
By using shared examples, you can easily reuse common tests across multiple specifications and keep your test code DRY.