Skip to content

Commit

Permalink
Update repository requirements and some CS fixes from #26
Browse files Browse the repository at this point in the history
  • Loading branch information
egulias committed Aug 10, 2014
2 parents 4db12f4 + 6427dec commit e83274a
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 2,634 deletions.
33 changes: 20 additions & 13 deletions Command/ListenersCommand.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
<?php

/**
* This file is part of ListenersDebugCommandBundle
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Egulias\ListenersDebugCommandBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerDebugCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Bundle\FrameworkBundle\Command\ContainerDebugCommand;
use Egulias\ListenersDebug\Listener\ListenerFetcher;
use Egulias\ListenersDebug\Listener\ListenerFilter;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Definition;

use Egulias\ListenersDebug\Listener\ListenerFetcher;
use Egulias\ListenersDebug\Listener\ListenerFilter;

/**
* ListenersCommand
*
Expand Down Expand Up @@ -88,8 +96,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
/**
* outputListeners
*
* @param OutputInterface $output Output
* @param array $options array of options from the console
* @param OutputInterface $output Output
* @param array $options array of options from the console
*
*/
protected function outputListeners(OutputInterface $output, $options = array())
Expand Down Expand Up @@ -139,25 +147,22 @@ protected function outputListener(OutputInterface $output, $serviceId)

if ($definition instanceof Alias) {
$output->writeln(sprintf('This service is an alias for the service <info>%s</info>', (string) $definition));

return;
}

$output->writeln(sprintf('<comment>Listener Id</comment> %s', $serviceId));
$output->writeln(sprintf('<comment>Class</comment> %s', $definition->getClass()));

if ($definition instanceof Definition) {
return;
}

$type = ($fetcher->isSubscriber($definition)) ? 'subscriber' : 'listener';
$output->writeln(sprintf('<comment>Type</comment> %s', $type));
$output->writeln(sprintf('<comment>Listens to</comment>', ''));
$events = array();

$tags = $definition->getTags();
foreach ($tags as $tag => $details) {
if (preg_match(self::SUBSCRIBER_PATTERN, $tag)) {
$subscribed = $this->getEventSubscriberInformation($definition->getClass());
if (preg_match(ListenerFetcher::SUBSCRIBER_PATTERN, $tag)) {
$subscribed = $fetcher->getEventSubscriberInformation($definition->getClass());
foreach ($subscribed as $name => $current) {
//Exception when event only has the method name
if (!is_array($current)) {
Expand All @@ -169,12 +174,14 @@ protected function outputListener(OutputInterface $output, $serviceId)
$event['name'] = $name;
$event['method'] = $current[0];
$event['priority'] = (isset($current[1])) ? $current[1] : 0;
$events[] = $event;
}
} elseif (preg_match(self::LISTENER_PATTERN, $tag)) {
} elseif (preg_match(ListenerFetcher::LISTENER_PATTERN, $tag)) {
foreach ($details as $current) {
$event['name'] = $current['event'];
$event['method'] = (isset($current['method'])) ? $current['method'] : $current['event'];
$event['priority'] = isset($current['priority']) ? $current['priority'] : 0;
$events[] = $event;
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions EguliasListenersDebugCommandBundle.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
<?php

/**
* This file is part of ListenersDebugCommandBundle
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Egulias\ListenersDebugCommandBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
* EguliasListenersDebugCommandBundle
*
* @author Eduardo Gulias <me@egulias.com>
*/
class EguliasListenersDebugCommandBundle extends Bundle
{
}
67 changes: 62 additions & 5 deletions Tests/Command/ListenersCommandTest.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
<?php

/**
* This file is part of ListenersDebugCommandBundle
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Egulias\ListenersDebugCommandBundle\Test\Command;

use Egulias\ListenersDebugCommandBundle\Command\ListenersCommand;
use PHPUnit_Framework_TestCase;

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;

class ListenersCommandTest extends \PHPUnit_Framework_TestCase
use Egulias\ListenersDebugCommandBundle\Command\ListenersCommand;

/**
* ListenersCommand test
*
* @author Eduardo Gulias <me@egulias.com>
*/
class ListenersCommandTest extends PHPUnit_Framework_TestCase
{
protected $application;

Expand All @@ -35,12 +50,41 @@ public function testBaseCommand()
$this->assertRegExp('/Class Name/', $display);
}

public function testEventNameFilter()
public function testEventNameFilterForListener()
{
$display = $this->executeCommand(array('name' => 'acme.demo.listener'));
$display = $this->executeCommand(array('name' => 'dummy_listener'));

$this->assertRegExp('/Class/', $display);
$this->assertRegExp('/ControllerListener/', $display);
$this->assertRegExp('/DummyListener/', $display);
$this->assertRegExp('/Event/', $display);
$this->assertRegExp('/Method/', $display);
$this->assertRegExp('/Type/', $display);
$this->assertRegExp('/Priority/', $display);
$this->assertRegExp('/listener/', $display);
$this->assertRegExp('/listen/', $display);
$this->assertRegExp('/8/', $display);
}

public function testEventNameFilterForSubscriber()
{
$display = $this->executeCommand(array('name' => 'dummy_listener_subscriber'));

$this->assertRegExp('/Class/', $display);
$this->assertRegExp('/DummySubscriber/', $display);
$this->assertRegExp('/Event/', $display);
$this->assertRegExp('/Method/', $display);
$this->assertRegExp('/Priority/', $display);
$this->assertRegExp('/Type/', $display);
$this->assertRegExp('/subscriber/', $display);
$this->assertRegExp('/listen/', $display);
$this->assertRegExp('/8/', $display);
}

public function testEventNameFilterForAlias()
{
$display = $this->executeCommand(array('name' => 'dummy_listener_subscriber_alias'));

$this->assertRegExp('/alias for the service dummy_listener_subscriber/', $display);
}

public function testFilterByEventName()
Expand All @@ -63,6 +107,19 @@ public function testShowOnlySubscribers()

$this->assertNotRegExp('/\|listener\|/', $display);
}

public function testShowPrivate()
{
$display = $this->executeCommand(array('--show-private' => null));

$this->assertNotRegExp('/\|private\|/', $display);
}

public function testShowOnlyOneListener()
{

}

private function executeCommand(array $options)
{
$command = $this->application->find('container:debug:listeners');
Expand Down
11 changes: 11 additions & 0 deletions Tests/DummyListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Egulias\ListenersDebugCommandBundle\Tests;

class DummyListener
{
public function listen()
{

}
}
22 changes: 22 additions & 0 deletions Tests/DummySubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Egulias\ListenersDebugCommandBundle\Tests;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class DummySubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return array (
'kernel.terminate',
'kernel.view' => array('listen', 8),
'rare.condition' => array(array('listen', 8))
);
}

public function listen()
{

}
}
Loading

0 comments on commit e83274a

Please sign in to comment.