Skip to content

Instantly share code, notes, and snippets.

@mkoubik
Created December 27, 2016 13:24
Show Gist options
  • Save mkoubik/3dd62f82046666e94be6989b4458cec1 to your computer and use it in GitHub Desktop.
Save mkoubik/3dd62f82046666e94be6989b4458cec1 to your computer and use it in GitHub Desktop.
<?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();
}
}
}
<?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