Created
December 27, 2016 13:24
-
-
Save mkoubik/3dd62f82046666e94be6989b4458cec1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class TestCase extends \Tester\TestCase | |
{ | |
private $tearDownCallbacks = []; | |
protected function addTearDownCallback($callback) | |
{ | |
if (!is_callable($callback)) { | |
throw new \InvalidArgumentException('$callback is not callable'); | |
} | |
$this->tearDownCallbacks[] = $callback; | |
} | |
protected function tearDown() | |
{ | |
parent::tearDown(); | |
foreach ($this->tearDownCallbacks as $callback) { | |
$callback(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
trait TestWithMockista | |
{ | |
/** | |
* @var Registry | |
*/ | |
private $mockista; | |
/** | |
* @return Registry | |
*/ | |
protected function getMockista() | |
{ | |
if ($this->mockista === null) { | |
$this->mockista = new Registry(); | |
$this->addTearDownCallback(function () { | |
$this->mockista->assertExpectations(); | |
}); | |
} | |
return $this->mockista; | |
} | |
protected abstract function addTearDownCallback($callback); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment