9 use RecursiveDirectoryIterator;
10 use RecursiveIteratorIterator;
35 private $fixtureBaseDir;
42 private $origComponents =
null;
51 $this->fixtureBaseDir = $fixtureBaseDir;
60 public function startTest(\PHPUnit\Framework\TestCase $test)
62 $this->registerComponents($test);
73 public function endTest(\PHPUnit\Framework\TestCase $test)
75 $this->restoreComponents();
83 private function registerComponents(\PHPUnit\Framework\TestCase $test)
85 $annotations = $test->getAnnotations();
86 $componentAnnotations = [];
87 if (isset($annotations[
'class'][self::ANNOTATION_NAME])) {
88 $componentAnnotations = array_merge($componentAnnotations, $annotations[
'class'][self::ANNOTATION_NAME]);
90 if (isset($annotations[
'method'][self::ANNOTATION_NAME])) {
91 $componentAnnotations = array_merge($componentAnnotations, $annotations[
'method'][self::ANNOTATION_NAME]);
93 if (empty($componentAnnotations)) {
96 $componentAnnotations = array_unique($componentAnnotations);
97 $reflection = new \ReflectionClass(self::REGISTRAR_CLASS);
98 $paths = $reflection->getProperty(self::PATHS_FIELD);
99 $paths->setAccessible(
true);
100 $this->origComponents =
$paths->getValue();
101 $paths->setAccessible(
false);
102 foreach ($componentAnnotations as $fixturePath) {
103 $fixturesDir = $this->fixtureBaseDir .
'/' . $fixturePath;
104 if (!file_exists($fixturesDir)) {
105 throw new \InvalidArgumentException(
106 self::ANNOTATION_NAME .
" fixture '$fixturePath' does not exist" 110 new RecursiveIteratorIterator(
111 new RecursiveDirectoryIterator($fixturesDir, \FilesystemIterator::SKIP_DOTS)
113 '/^.+\/registration\.php$/' 118 foreach (
$iterator as $registrationFile) {
119 require $registrationFile->getRealPath();
127 private function restoreComponents()
129 if (
null !== $this->origComponents) {
130 $reflection = new \ReflectionClass(self::REGISTRAR_CLASS);
131 $paths = $reflection->getProperty(self::PATHS_FIELD);
132 $paths->setAccessible(
true);
133 $paths->setValue($this->origComponents);
134 $paths->setAccessible(
false);
135 $this->origComponents =
null;
__construct($fixtureBaseDir)
startTest(\PHPUnit\Framework\TestCase $test)
endTest(\PHPUnit\Framework\TestCase $test)