mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-22 06:47:19 +00:00
feat: Implement a fixture callback class using the PHPUnit TestListener interface.
This commit is contained in:
parent
72079a54e6
commit
bd633c023a
2 changed files with 70 additions and 0 deletions
67
lib/Cake/TestSuite/Fixture/CakeFixtureInjector.php
Normal file
67
lib/Cake/TestSuite/Fixture/CakeFixtureInjector.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
use PHPUnit\Framework\AssertionFailedError;
|
||||
use PHPUnit\Framework\Test;
|
||||
use PHPUnit\Framework\TestListener;
|
||||
use PHPUnit\Framework\TestSuite;
|
||||
use PHPUnit\Framework\Warning;
|
||||
|
||||
/**
|
||||
* @property CakeFixtureManager $_fixtureManager
|
||||
* @property TestSuite $_first
|
||||
*/
|
||||
class CakeFixtureInjector implements TestListener {
|
||||
|
||||
protected $_fixtureManager;
|
||||
|
||||
protected $_first;
|
||||
|
||||
public function __construct(?CakeFixtureManager $manager = null) {
|
||||
$this->_fixtureManager = $manager ?? new CakeFixtureManager();
|
||||
$this->_fixtureManager->shutDown();
|
||||
}
|
||||
|
||||
public function startTestSuite(TestSuite $suite) : void {
|
||||
if (empty($this->_first)) {
|
||||
$this->_first = $suite;
|
||||
}
|
||||
}
|
||||
|
||||
public function endTestSuite(TestSuite $suite) : void {
|
||||
if ($this->_first === $suite) {
|
||||
$this->_fixtureManager->shutDown();
|
||||
}
|
||||
}
|
||||
|
||||
public function startTest(Test $test) : void {
|
||||
$test->fixtureManager = $this->_fixtureManager;
|
||||
if ($test instanceof CakeTestCase) {
|
||||
$this->_fixtureManager->fixturize($test);
|
||||
$this->_fixtureManager->load($test);
|
||||
}
|
||||
}
|
||||
|
||||
public function endTest(Test $test, $time) : void {
|
||||
if ($test instanceof CakeTestCase) {
|
||||
$this->_fixtureManager->unload($test);
|
||||
}
|
||||
}
|
||||
|
||||
public function addError(Test $test, Throwable $e, $time) : void {
|
||||
}
|
||||
|
||||
public function addFailure(Test $test, AssertionFailedError $e, $time) : void {
|
||||
}
|
||||
|
||||
public function addIncompleteTest(Test $test, Throwable $e, $time) : void {
|
||||
}
|
||||
|
||||
public function addSkippedTest(Test $test, Throwable $e, $time) : void {
|
||||
}
|
||||
|
||||
public function addRiskyTest(Test $test, Throwable $e, $time) : void {
|
||||
}
|
||||
|
||||
public function addWarning(Test $test, Warning $e, float $time) : void {
|
||||
}
|
||||
}
|
|
@ -7,4 +7,7 @@
|
|||
<php>
|
||||
<ini name="memory_limit" value="-1"/>
|
||||
</php>
|
||||
<listeners>
|
||||
<listener class="CakeFixtureInjector" file="./lib/Cake/TestSuite/Fixture/CakeFixtureInjector.php"/>
|
||||
</listeners>
|
||||
</phpunit>
|
||||
|
|
Loading…
Reference in a new issue