These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Tests\Unit\Task; |
||
4 | |||
5 | use AspectMock\Test as test; |
||
6 | |||
7 | class WatchTest extends \Codeception\TestCase\Test |
||
8 | { |
||
9 | /** |
||
10 | * @var \AspectMock\Proxy\AnythingClassProxy |
||
11 | */ |
||
12 | protected $resourceWatcher; |
||
13 | |||
14 | public function _before() |
||
15 | { |
||
16 | if (!class_exists('Lurker\\ResourceWatcher')) { |
||
17 | $this->resourceWatcher = test::spec( |
||
18 | 'Lurker\ResourceWatcher', |
||
19 | [ |
||
20 | 'start' => true, |
||
21 | 'track' => true, |
||
22 | 'addListener' => true |
||
23 | ] |
||
24 | )->make(); |
||
25 | } else { |
||
26 | $this->resourceWatcher = test::double( |
||
0 ignored issues
–
show
|
|||
27 | 'Lurker\ResourceWatcher', |
||
28 | [ |
||
29 | 'start' => true, |
||
30 | 'track' => true, |
||
31 | 'addListener' => true |
||
32 | ] |
||
33 | ); |
||
34 | } |
||
35 | } |
||
36 | |||
37 | public function testMonitorWithOneEvent() |
||
38 | { |
||
39 | $task = new \Robo\Task\Base\Watch($this); |
||
40 | |||
41 | $task->monitor( |
||
42 | 'src', |
||
43 | function () { |
||
44 | //do nothing |
||
45 | }, |
||
46 | 1 // CREATE |
||
47 | )->run(); |
||
48 | |||
49 | $this->resourceWatcher->verifyInvokedOnce('track'); |
||
50 | } |
||
51 | |||
52 | public function testMonitorWithTwoEvents() |
||
53 | { |
||
54 | $task = new \Robo\Task\Base\Watch($this); |
||
55 | |||
56 | $task->monitor( |
||
57 | 'src', |
||
58 | function () { |
||
59 | //do nothing |
||
60 | }, |
||
61 | [ |
||
0 ignored issues
–
show
array(1, 4) is of type array<integer,integer,{"...nteger","1":"integer"}> , but the function expects a integer .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
62 | 1, //CREATE |
||
63 | 4, //DELETE |
||
64 | ] |
||
65 | )->run(); |
||
66 | |||
67 | $this->resourceWatcher->verifyInvokedMultipleTimes('track', 2); |
||
68 | } |
||
69 | } |
||
70 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.