-
-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathDiscoversEventHandlersTest.php
67 lines (54 loc) · 2.33 KB
/
DiscoversEventHandlersTest.php
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace Spatie\EventSourcing\Tests;
use function PHPUnit\Framework\assertEqualsCanonicalizing;
use Spatie\EventSourcing\EventHandlers\EventHandler;
use Spatie\EventSourcing\Projectionist;
use Spatie\EventSourcing\Support\Composer;
use Spatie\EventSourcing\Support\DiscoverEventHandlers;
use Spatie\EventSourcing\Tests\TestClasses\AutoDiscoverEventHandlers\Subdirectory\TestProjectorInSubdirectory;
use Spatie\EventSourcing\Tests\TestClasses\AutoDiscoverEventHandlers\Subdirectory\TestQueuedProjectorInSubdirectory;
use Spatie\EventSourcing\Tests\TestClasses\AutoDiscoverEventHandlers\Subdirectory\TestReactorInSubdirectory;
use Spatie\EventSourcing\Tests\TestClasses\AutoDiscoverEventHandlers\TestProjector;
use Spatie\EventSourcing\Tests\TestClasses\AutoDiscoverEventHandlers\TestQueuedProjector;
use Spatie\EventSourcing\Tests\TestClasses\AutoDiscoverEventHandlers\TestReactor;
function getDiscoveryBasePath(): string
{
return realpath(test()->pathToTests().'/../');
}
it('can get all classes that have event handlers', function () {
/** @var \Spatie\EventSourcing\Projectionist $projectionist */
$projectionist = app(Projectionist::class);
$pathToComposerJson = __DIR__.'/../composer.json';
(new DiscoverEventHandlers())
->within([__DIR__.'/TestClasses/AutoDiscoverEventHandlers'])
->useBasePath(getDiscoveryBasePath())
->useRootNamespace('Spatie\EventSourcing\\')
->ignoringFiles(Composer::getAutoloadedFiles($pathToComposerJson))
->addToProjectionist($projectionist);
$registeredProjectors = $projectionist
->getProjectors()
->toBase()
->map(function (EventHandler $eventHandler) {
return get_class($eventHandler);
})
->values()
->toArray();
assertEqualsCanonicalizing([
TestQueuedProjector::class,
TestProjectorInSubdirectory::class,
TestQueuedProjectorInSubdirectory::class,
TestProjector::class,
], $registeredProjectors);
$registeredReactors = $projectionist
->getReactors()
->toBase()
->map(function (EventHandler $eventHandler) {
return get_class($eventHandler);
})
->values()
->toArray();
assertEqualsCanonicalizing([
TestReactorInSubdirectory::class,
TestReactor::class,
], $registeredReactors);
});