Skip to content

Commit d7168d2

Browse files
author
Jonas Pardon
authored
Merge pull request #14 from JonasPardon/#11-add-support-for-dispatch-helper
2 parents dfd57e3 + 99564be commit d7168d2

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/EventVisualizer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ private function getDispatchedJobs(CodeParser $codeParser): Collection
194194

195195
$jobs = [];
196196

197+
$foundFunctionCalls = $codeParser->getFunctionCalls('dispatch');
198+
if (count($foundFunctionCalls) > 0) {
199+
$jobs = array_merge($jobs, $foundFunctionCalls);
200+
}
201+
197202
foreach ($classes as $class) {
198203
foreach ($methods as $method) {
199204
$foundStaticCalls = $codeParser->getStaticCalls($class, $method);

tests/Unit/CodeParser/FunctionCallsParsingTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,39 @@ public function handle(): void
4242
$this->assertEquals($expectedHelperCall->method, $helperCalls[0]->method);
4343
$this->assertEquals($expectedHelperCall->dispatchedClass, $helperCalls[0]->dispatchedClass);
4444
}
45+
46+
/** @test */
47+
public function it_finds_a_dispatch_helper_call(): void
48+
{
49+
$code = <<<'CODE'
50+
<?php
51+
52+
namespace App\Domain\SomeDomain;
53+
54+
use App\Events\SomeJob;
55+
56+
class SomeClass
57+
{
58+
public function handle(): void
59+
{
60+
dispatch(new SomeJob());
61+
}
62+
}
63+
CODE;
64+
65+
$codeParser = new CodeParser($code);
66+
67+
$helperCalls = $codeParser->getFunctionCalls('dispatch');
68+
69+
$expectedHelperCall = new ResolvedCall(
70+
dispatcherClass: 'none',
71+
dispatchedClass: 'App\Events\SomeJob',
72+
method: 'dispatch',
73+
);
74+
75+
$this->assertCount(1, $helperCalls);
76+
$this->assertEquals($expectedHelperCall->dispatcherClass, $helperCalls[0]->dispatcherClass);
77+
$this->assertEquals($expectedHelperCall->method, $helperCalls[0]->method);
78+
$this->assertEquals($expectedHelperCall->dispatchedClass, $helperCalls[0]->dispatchedClass);
79+
}
4580
}

0 commit comments

Comments
 (0)