1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace Codeception\Subscriber;
use Codeception\Event\TestEvent;
use Codeception\Test\Descriptor;
use Codeception\Test\Interfaces\Dependent;
use Codeception\TestInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Codeception\Events;
class Dependencies implements EventSubscriberInterface
{
use Shared\StaticEvents;
static $events = [
Events::TEST_START => 'testStart',
Events::TEST_SUCCESS => 'testSuccess'
];
protected $successfulTests = [];
public function testStart(TestEvent $event)
{
$test = $event->getTest();
if (!$test instanceof Dependent) {
return;
}
$testSignatures = $test->getDependencies();
foreach ($testSignatures as $signature) {
if (!in_array($signature, $this->successfulTests)) {
$test->getMetadata()->setSkip("This test depends on $signature to pass");
return;
}
}
}
public function testSuccess(TestEvent $event)
{
$test = $event->getTest();
if (!$test instanceof TestInterface) {
return;
}
$this->successfulTests[] = Descriptor::getTestSignature($test);
}
}