Completed
Push — master ( ac5a7d...5524a5 )
by Jeroen
46:00 queued 31:00
created

EventListener/ConsoleExceptionSubscriberTest.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

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');
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);
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