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 Kunstmaan\AdminBundle\Tests\EventListener; |
||
4 | |||
5 | use Kunstmaan\AdminBundle\EventListener\ConsoleExceptionSubscriber; |
||
6 | use PHPUnit\Framework\TestCase; |
||
7 | use Psr\Log\LoggerInterface; |
||
8 | use Symfony\Component\Console\Command\Command; |
||
9 | use Symfony\Component\Console\Event\ConsoleErrorEvent; |
||
10 | use Symfony\Component\Console\Input\ArgvInput; |
||
11 | use Symfony\Component\Console\Output\OutputInterface; |
||
12 | |||
13 | class ConsoleExceptionSubscriberTest extends TestCase |
||
14 | { |
||
15 | public function testListener() |
||
16 | { |
||
17 | // Remove when sf3.4 support is removed |
||
18 | if (!class_exists(ConsoleErrorEvent::class)) { |
||
19 | // Nothing to test |
||
20 | return; |
||
21 | } |
||
22 | |||
23 | $error = new \TypeError('An error occurred'); |
||
0 ignored issues
–
show
|
|||
24 | $output = $this->createMock(OutputInterface::class); |
||
25 | $logger = $this->createMock(LoggerInterface::class); |
||
26 | $logger->expects($this->once())->method('critical'); |
||
27 | |||
28 | $subscriber = new ConsoleExceptionSubscriber($logger); |
||
0 ignored issues
–
show
$logger is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Psr\Log\LoggerInterface> .
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...
|
|||
29 | $subscriber->onConsoleError(new ConsoleErrorEvent(new ArgvInput(['console.php', 'test:run', '--foo=baz', 'buzz']), $output, $error, new Command('test:run'))); |
||
0 ignored issues
–
show
$output is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Symfony\Component...Output\OutputInterface> .
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...
|
|||
30 | } |
||
31 | } |
||
32 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.