/** * @param string $depends * @param array $expected * * @dataProvider dpDepends */ public function testDepends($depends, array $expected) { $method = new \ReflectionMethod($this->meta, 'setDependencies'); $method->setAccessible(true); $method->invoke($this->meta, ['depends' => $depends]); $this->assertEquals($expected, $this->meta->getDependencies()); }
/** * Check specified depends and run test if necessary. * * @param TestMeta $test * * @throws \LogicException If found infinitive depends loop */ public function resolveDependencies(TestMeta $test) { $depends = $test->getDependencies(); if (empty($depends)) { return; } $test->setStatus(TestMeta::TEST_MARKED); foreach ($depends as $depend) { $test = $this->getTestMethod($depend); if ($test->getStatus() === TestMeta::TEST_NEW) { if ($this->testMethod($test)) { /** @var SkipOnce $controller */ $controller = $this->controller->switchTo(ControllerParentInterface::CONTROLLER_SKIP_ONCE); $controller->setDepends(null); } } elseif ($test->getStatus() === TestMeta::TEST_MARKED) { throw new \LogicException(sprintf('Found infinitive loop in depends for test method "%s::%s()"', $this->reflectionClass->getName(), $depend)); } elseif ($test->getStatus() !== TestMeta::TEST_DONE) { /** @var SkipOnce $controller */ $controller = $this->controller->switchTo(ControllerParentInterface::CONTROLLER_SKIP_ONCE); $controller->setDepends(null); } } }
/** * @param TestMeta $test */ public function configByTestMeta(TestMeta $test) { $this->class = $test->getClass(); $this->method = $test->getMethod(); $this->depends = $test->getDependencies(); $this->annotations = $test->getAnnotations(); }