Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests/</directory>
<exclude>tests/Maker</exclude>
<exclude>tests/fixtures</exclude>
<exclude>tests/tmp</exclude>
</testsuite>
<testsuite name="Maker Test Suite">
<directory>tests/Maker</directory>
</testsuite>
</testsuites>

<filter>
Expand Down
12 changes: 10 additions & 2 deletions src/EventRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ public function __construct(EventDispatcherInterface $eventDispatcher)
foreach (self::$newEventsMap as $eventName => $newEventClass) {
//Check if the new event classes exist, if so replace the old one with the new.
if (isset(self::$eventsMap[$eventName]) && class_exists($newEventClass)) {
unset(self::$eventsMap[$eventName]);
self::$eventsMap[$newEventClass] = $newEventClass;
self::$eventsMap[$eventName] = $newEventClass;
}
}
}
Expand Down Expand Up @@ -160,4 +159,13 @@ public function getEventClassName(string $event)

return null;
}

public function listActiveEvents(array $events)
{
foreach ($events as $key => $event) {
$events[$key] = sprintf('%s (<fg=yellow>%s</>)', $event, self::$eventsMap[$event]);
}

return $events;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you describe what this is doing exactly? I have a hard time just reading the code to figure it out :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It generates more verbose event describing
Screen Shot 2019-12-16 at 16 23 34

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I restored old-style event keys like kernel.request because it's still described in symfony5 before it command asked the user to enter long FQCN for RequestEvent class.

}
}
2 changes: 1 addition & 1 deletion src/Maker/MakeSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
$events = $this->eventRegistry->getAllActiveEvents();

$io->writeln(' <fg=green>Suggested Events:</>');
$io->listing($events);
$io->listing($this->eventRegistry->listActiveEvents($events));
$question = new Question(sprintf(' <fg=green>%s</>', $command->getDefinition()->getArgument('event')->getDescription()));
$question->setAutocompleterValues($events);
$question->setValidator([Validator::class, 'notBlank']);
Expand Down
29 changes: 28 additions & 1 deletion src/Test/MakerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,23 @@
namespace Symfony\Bundle\MakerBundle\Test;

use PHPUnit\Framework\TestCase;
use Symfony\Bundle\MakerBundle\MakerInterface;
use Symfony\Bundle\MakerBundle\Str;

class MakerTestCase extends TestCase
abstract class MakerTestCase extends TestCase
{
private $kernel;

/**
* @dataProvider getTestDetails
*/
public function testExecute(MakerTestDetails $makerTestDetails)
{
$this->executeMakerCommand($makerTestDetails);
}

abstract public function getTestDetails();

protected function executeMakerCommand(MakerTestDetails $testDetails)
{
if (!$testDetails->isSupportedByCurrentPhpVersion()) {
Expand Down Expand Up @@ -68,4 +82,17 @@ protected function assertContainsCount(string $needle, string $haystack, int $co
{
$this->assertEquals(1, substr_count($haystack, $needle), sprintf('Found more than %d occurrences of "%s" in "%s"', $count, $needle, $haystack));
}

protected function getMakerInstance(string $makerClass): MakerInterface
{
if (null === $this->kernel) {
$this->kernel = new MakerTestKernel('dev', true);
$this->kernel->boot();
}

// a cheap way to guess the service id
$serviceId = $serviceId ?? sprintf('maker.maker.%s', Str::asRouteName((new \ReflectionClass($makerClass))->getShortName()));

return $this->kernel->getContainer()->get($serviceId);
}
}
77 changes: 77 additions & 0 deletions src/Test/MakerTestKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

/*
* This file is part of the Symfony MakerBundle package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\MakerBundle\Test;

use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Bundle\MakerBundle\DependencyInjection\CompilerPass\MakeCommandRegistrationPass;
use Symfony\Bundle\MakerBundle\MakerBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
use Symfony\Component\Routing\RouteCollectionBuilder;

class MakerTestKernel extends Kernel implements CompilerPassInterface
{
use MicroKernelTrait;

private $testRootDir;

public function __construct(string $environment, bool $debug)
{
$this->testRootDir = sys_get_temp_dir().'/'.uniqid('sf_maker_', true);

parent::__construct($environment, $debug);
}

public function registerBundles()
{
return [
new FrameworkBundle(),
new MakerBundle(),
];
}

protected function configureRoutes(RouteCollectionBuilder $routes)
{
}

protected function configureRouting(RoutingConfigurator $routes)
{
}

protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
{
$c->setParameter('kernel.secret', 123);
}

public function getProjectDir()
{
return $this->getRootDir();
}

public function getRootDir()
{
return $this->testRootDir;
}

public function process(ContainerBuilder $container)
{
// makes all makers public to help the tests
foreach ($container->findTaggedServiceIds(MakeCommandRegistrationPass::MAKER_TAG) as $id => $tags) {
$defn = $container->getDefinition($id);
$defn->setPublic(true);
}
}
}
3 changes: 2 additions & 1 deletion tests/EventRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class EventRegistryTest extends TestCase
{
Expand Down Expand Up @@ -81,7 +82,7 @@ public function testGetNewEventClassNameFromStandardList()
->method('getListeners');

$registry = new EventRegistry($dispatcher);
$this->assertSame(ExceptionEvent::class, $registry->getEventClassName(ExceptionEvent::class));
$this->assertSame(ExceptionEvent::class, $registry->getEventClassName(KernelEvents::EXCEPTION));
}
}

Expand Down
Loading