Skip to content

Commit

Permalink
fix broken console exception tests (Kunstmaan#2080)
Browse files Browse the repository at this point in the history
  • Loading branch information
Devolicious authored Aug 22, 2018
1 parent 205d70f commit e21649a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,29 @@
use Kunstmaan\AdminBundle\EventListener\ConsoleExceptionListener;
use PHPUnit_Framework_TestCase;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Event\ConsoleErrorEvent;
use Symfony\Component\Console\Event\ConsoleExceptionEvent;

class ConsoleExceptionListenerTest extends PHPUnit_Framework_TestCase
{
public function testListener()
{
$logger = $this->createMock(LoggerInterface::class);
$logger->expects($this->once())->method('error')->willReturn(true);
$listener = new ConsoleExceptionListener($logger);

$command = new ApplyAclCommand();
$exception = new Exception();

$event = $this->createMock(ConsoleExceptionEvent::class);
$event->expects($this->once())->method('getCommand')->willReturn($command);
$event->expects($this->once())->method('getException')->willReturn($exception);
if (class_exists(ConsoleErrorEvent::class)){
$this->assertNull($listener->onConsoleException($event));
} else {
$command = new ApplyAclCommand();
$exception = new Exception();

$logger->expects($this->once())->method('error')->willReturn(true);

$event->expects($this->once())->method('getCommand')->willReturn($command);
$event->expects($this->once())->method('getException')->willReturn($exception);

$listener->onConsoleException($event);
$listener->onConsoleException($event);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Kunstmaan\AdminBundle\Tests\EventListener;

use Exception;
use Codeception\Test\Unit;
use Kunstmaan\AdminBundle\Command\ApplyAclCommand;
use Kunstmaan\AdminBundle\EventListener\ConsoleExceptionSubscriber;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Event\ConsoleErrorEvent;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class ConsoleExceptionSubscriberTest extends Unit
{
public function testListener()
{
if (!class_exists(ConsoleErrorEvent::class)) {
// Nothing to test
return;
}

$logger = $this->createMock(LoggerInterface::class);
$logger->expects($this->once())->method('error')->willReturn(true);
$subscriber = new ConsoleExceptionSubscriber($logger);

$command = new ApplyAclCommand();
$exception = new Exception();

$input = $this->createMock(InputInterface::class);
$output = $this->createMock(OutputInterface::class);
$event = new ConsoleErrorEvent($input, $output, $exception, $command);

$subscriber->onConsoleError($event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testBundle()
$resources = $containerBuilder->getResources();
$extensions = $containerBuilder->getExtensions();

$this->assertCount(6, $resources);
$this->assertCount(7, $resources);
$this->assertCount(1, $extensions);
$this->assertArrayHasKey('kunstmaan_admin', $extensions);
$this->assertInstanceOf(KunstmaanAdminExtension::class, $extensions['kunstmaan_admin']);
Expand Down

0 comments on commit e21649a

Please sign in to comment.