-
-
Notifications
You must be signed in to change notification settings - Fork 394
/
CheckDispatchArgumentTypesCompatibleWithClassConstructorRuleTest.php
92 lines (82 loc) · 8.16 KB
/
CheckDispatchArgumentTypesCompatibleWithClassConstructorRuleTest.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
declare(strict_types=1);
namespace Tests\Rules;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Foundation\Events\Dispatchable as EventDispatchable;
use NunoMaduro\Larastan\Rules\CheckDispatchArgumentTypesCompatibleWithClassConstructorRule;
use PHPStan\Rules\FunctionCallParametersCheck;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
/** @extends RuleTestCase<CheckDispatchArgumentTypesCompatibleWithClassConstructorRule> */
class CheckDispatchArgumentTypesCompatibleWithClassConstructorRuleTest extends RuleTestCase
{
/** @var string */
private $dispatchableClass;
/**
* @inheritDoc
*/
protected function getRule(): Rule
{
$broker = $this->createReflectionProvider();
return new CheckDispatchArgumentTypesCompatibleWithClassConstructorRule(
$broker,
self::getContainer()->getByType(FunctionCallParametersCheck::class),
$this->dispatchableClass
);
}
public function testJobDispatch(): void
{
$this->dispatchableClass = Dispatchable::class;
$this->analyse([__DIR__.'/Data/job-dispatch.php'], [
['Job class Tests\Rules\Data\LaravelJob constructor invoked with 0 parameters in Tests\Rules\Data\LaravelJob::dispatch(), 2 required.', 5],
['Job class Tests\Rules\Data\LaravelJob constructor invoked with 0 parameters in Tests\Rules\Data\LaravelJob::dispatchSync(), 2 required.', 6],
['Job class Tests\Rules\Data\LaravelJob constructor invoked with 0 parameters in Tests\Rules\Data\LaravelJob::dispatchNow(), 2 required.', 7],
['Job class Tests\Rules\Data\LaravelJob constructor invoked with 0 parameters in Tests\Rules\Data\LaravelJob::dispatchAfterResponse(), 2 required.', 8],
['Job class Tests\Rules\Data\LaravelJob constructor invoked with 1 parameter in Tests\Rules\Data\LaravelJob::dispatch(), 2 required.', 10],
['Parameter #1 $foo of job class Tests\Rules\Data\LaravelJob constructor expects string in Tests\Rules\Data\LaravelJob::dispatch(), int given.', 11],
['Parameter #2 $bar of job class Tests\Rules\Data\LaravelJob constructor expects int in Tests\Rules\Data\LaravelJob::dispatch(), string given.', 11],
['Parameter #1 $foo of job class Tests\Rules\Data\LaravelJob constructor expects string in Tests\Rules\Data\LaravelJob::dispatch(), true given.', 12],
['Parameter #2 $bar of job class Tests\Rules\Data\LaravelJob constructor expects int in Tests\Rules\Data\LaravelJob::dispatch(), false given.', 12],
['Job class Tests\Rules\Data\LaravelJob constructor invoked with 1 parameter in Tests\Rules\Data\LaravelJob::dispatchSync(), 2 required.', 14],
['Parameter #1 $foo of job class Tests\Rules\Data\LaravelJob constructor expects string in Tests\Rules\Data\LaravelJob::dispatchSync(), int given.', 15],
['Parameter #2 $bar of job class Tests\Rules\Data\LaravelJob constructor expects int in Tests\Rules\Data\LaravelJob::dispatchSync(), string given.', 15],
['Parameter #1 $foo of job class Tests\Rules\Data\LaravelJob constructor expects string in Tests\Rules\Data\LaravelJob::dispatchSync(), true given.', 16],
['Parameter #2 $bar of job class Tests\Rules\Data\LaravelJob constructor expects int in Tests\Rules\Data\LaravelJob::dispatchSync(), false given.', 16],
['Job class Tests\Rules\Data\LaravelJob constructor invoked with 1 parameter in Tests\Rules\Data\LaravelJob::dispatchNow(), 2 required.', 18],
['Parameter #1 $foo of job class Tests\Rules\Data\LaravelJob constructor expects string in Tests\Rules\Data\LaravelJob::dispatchNow(), int given.', 19],
['Parameter #2 $bar of job class Tests\Rules\Data\LaravelJob constructor expects int in Tests\Rules\Data\LaravelJob::dispatchNow(), string given.', 19],
['Parameter #1 $foo of job class Tests\Rules\Data\LaravelJob constructor expects string in Tests\Rules\Data\LaravelJob::dispatchNow(), true given.', 20],
['Parameter #2 $bar of job class Tests\Rules\Data\LaravelJob constructor expects int in Tests\Rules\Data\LaravelJob::dispatchNow(), false given.', 20],
['Job class Tests\Rules\Data\LaravelJob constructor invoked with 1 parameter in Tests\Rules\Data\LaravelJob::dispatchAfterResponse(), 2 required.', 22],
['Parameter #1 $foo of job class Tests\Rules\Data\LaravelJob constructor expects string in Tests\Rules\Data\LaravelJob::dispatchAfterResponse(), int given.', 23],
['Parameter #2 $bar of job class Tests\Rules\Data\LaravelJob constructor expects int in Tests\Rules\Data\LaravelJob::dispatchAfterResponse(), string given.', 23],
['Parameter #1 $foo of job class Tests\Rules\Data\LaravelJob constructor expects string in Tests\Rules\Data\LaravelJob::dispatchAfterResponse(), true given.', 24],
['Parameter #2 $bar of job class Tests\Rules\Data\LaravelJob constructor expects int in Tests\Rules\Data\LaravelJob::dispatchAfterResponse(), false given.', 24],
['Parameter #1 $foo of job class Tests\Rules\Data\LaravelJob constructor expects string in Tests\Rules\Data\LaravelJob::dispatchIf(), int given.', 26],
['Parameter #2 $bar of job class Tests\Rules\Data\LaravelJob constructor expects int in Tests\Rules\Data\LaravelJob::dispatchIf(), string given.', 26],
['Parameter #1 $foo of job class Tests\Rules\Data\LaravelJob constructor expects string in Tests\Rules\Data\LaravelJob::dispatchUnless(), int given.', 27],
['Job class Tests\Rules\Data\LaravelJobWithoutConstructor does not have a constructor and must be dispatched without any parameters.', 30],
['Job class Tests\Rules\Data\LaravelJobWithoutConstructor does not have a constructor and must be dispatched without any parameters.', 32],
['Job class Tests\Rules\Data\LaravelJobWithoutConstructor does not have a constructor and must be dispatched without any parameters.', 34],
['Job class Tests\Rules\Data\LaravelJobWithoutConstructor does not have a constructor and must be dispatched without any parameters.', 36],
['Job class Tests\Rules\Data\LaravelJobWithoutConstructor does not have a constructor and must be dispatched without any parameters.', 39],
]);
}
public function testEventDispatch(): void
{
$this->dispatchableClass = EventDispatchable::class;
$this->analyse([__DIR__.'/Data/event-dispatch.php'], [
['Event class Tests\Rules\Data\LaravelEvent constructor invoked with 0 parameters in Tests\Rules\Data\LaravelEvent::dispatch(), 2 required.', 5],
['Event class Tests\Rules\Data\LaravelEvent constructor invoked with 1 parameter in Tests\Rules\Data\LaravelEvent::dispatch(), 2 required.', 7],
['Parameter #1 $foo of event class Tests\Rules\Data\LaravelEvent constructor expects string in Tests\Rules\Data\LaravelEvent::dispatch(), int given.', 8],
['Parameter #2 $bar of event class Tests\Rules\Data\LaravelEvent constructor expects int in Tests\Rules\Data\LaravelEvent::dispatch(), string given.', 8],
['Parameter #1 $foo of event class Tests\Rules\Data\LaravelEvent constructor expects string in Tests\Rules\Data\LaravelEvent::dispatch(), true given.', 9],
['Parameter #2 $bar of event class Tests\Rules\Data\LaravelEvent constructor expects int in Tests\Rules\Data\LaravelEvent::dispatch(), false given.', 9],
['Parameter #1 $foo of event class Tests\Rules\Data\LaravelEvent constructor expects string in Tests\Rules\Data\LaravelEvent::dispatchIf(), int given.', 11],
['Parameter #2 $bar of event class Tests\Rules\Data\LaravelEvent constructor expects int in Tests\Rules\Data\LaravelEvent::dispatchIf(), string given.', 11],
['Parameter #1 $foo of event class Tests\Rules\Data\LaravelEvent constructor expects string in Tests\Rules\Data\LaravelEvent::dispatchUnless(), int given.', 12],
['Event class Tests\Rules\Data\LaravelEventWithoutConstructor does not have a constructor and must be dispatched without any parameters.', 15],
['Event class Tests\Rules\Data\LaravelEventWithoutConstructor does not have a constructor and must be dispatched without any parameters.', 18],
]);
}
}