Merge pull request #116 from php-flasher/feat/add-symfony-tests

feat: symplify symfony tests
This commit is contained in:
Younes KHOUBZA
2023-01-17 03:52:03 +01:00
committed by GitHub
9 changed files with 237 additions and 104 deletions
+3 -3
View File
@@ -7,7 +7,7 @@ jobs:
symfony-test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
fail-fast: false
matrix:
os: [ubuntu-latest]
symfony: [ 6.2.*, 6.1.*, 6.0.*, 5.4.*, 5.3.*, 5.2.*, 5.1.*, 5.0.*, 4.4.*, 4.3.*, 4.2.*, 4.1.*, 4.0.*, 3.4.*, 3.3.*, 3.2.*, 3.1.*, 3.0.*, 2.8.*, 2.7.*, 2.6.*, 2.5.*, 2.4.*, 2.3.*, 2.2.*, 2.1.*, 2.0.* ]
@@ -64,7 +64,7 @@ jobs:
sed -i '/\"require\": {/,/},/d; /\"require-dev\": {/,/},/d' composer.json
composer config --global allow-plugins true
composer config extra.symfony.require "${{ matrix.symfony }}"
composer require "symfony/symfony:${{ matrix.symfony }}" "phpunit/phpunit:${{ matrix.phpunit }}" --no-interaction --no-update
composer require "symfony/symfony:${{ matrix.symfony }}" "phpunit/phpunit:${{ matrix.phpunit }}" "monolog/monolog" --no-interaction --no-update
composer update --prefer-stable --prefer-dist
- name: Execute tests
@@ -73,7 +73,7 @@ jobs:
laravel-test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
fail-fast: false
matrix:
os: [ubuntu-latest]
laravel: [ 9.*, 8.*, 7.*, 6.*, 5.8.*, 5.7.*, 5.6.*, 5.5.*, 5.4.*, 5.3.*, 5.2.*, 5.1.*, 5.0.*, 4.2.*, 4.1.*, 4.0.* ]
@@ -43,6 +43,12 @@ final class FlasherExtension extends Extension implements CompilerPassInterface
* @return void
*/
public function process(ContainerBuilder $container)
{
$this->registerFlasherTranslator($container);
$this->registerFlasherTemplateEngine($container);
}
private function registerFlasherTranslator(ContainerBuilder $container)
{
$config = $container->getDefinition('flasher.config')->getArgument(0);
@@ -57,6 +63,18 @@ final class FlasherExtension extends Extension implements CompilerPassInterface
$translationListener->replaceArgument(0, null);
}
private function registerFlasherTemplateEngine(ContainerBuilder $container)
{
if ($container->has('twig')) {
return;
}
$container->removeDefinition('flasher.template_engine');
$listener = $container->getDefinition('flasher.resource_manager');
$listener->replaceArgument(1, null);
}
/**
* @phpstan-param ConfigType $config
*
@@ -125,7 +143,7 @@ final class FlasherExtension extends Extension implements CompilerPassInterface
}
$container->register('flasher.session_listener', 'Flasher\Symfony\EventListener\SessionListener')
->setPublic(false)
->setPublic(true)
->addArgument(new Reference('flasher.request_extension'))
->addTag('kernel.event_listener', array('event' => 'kernel.response'));
}
@@ -142,7 +160,7 @@ final class FlasherExtension extends Extension implements CompilerPassInterface
}
$container->register('flasher.flasher_listener', 'Flasher\Symfony\EventListener\FlasherListener')
->setPublic(false)
->setPublic(true)
->addArgument(new Reference('flasher.response_extension'))
->addTag('kernel.event_listener', array('event' => 'kernel.response', 'priority' => -256));
}
+1
View File
@@ -23,6 +23,7 @@ final class ServiceProviderTest extends TestCase
$this->assertTrue($this->app->bound('flasher.sweetalert'));
$this->assertTrue($this->app->bound('flasher.toastr'));
$this->assertInstanceOf('Flasher\Prime\Flasher', $this->app->make('flasher'));
$this->assertInstanceOf('Flasher\Noty\Prime\NotyFactory', $this->app->make('flasher.noty'));
$this->assertInstanceOf('Flasher\Notyf\Prime\NotyfFactory', $this->app->make('flasher.notyf'));
$this->assertInstanceOf('Flasher\Pnotify\Prime\PnotifyFactory', $this->app->make('flasher.pnotify'));
+36
View File
@@ -0,0 +1,36 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
namespace Flasher\Tests\Symfony;
use Flasher\Symfony\Bridge\Bridge;
class FlasherBundleTest extends TestCase
{
public function testFlasherIntegration()
{
if (Bridge::versionCompare('2.1', '<')) {
self::markTestSkipped('ErrorException: 8192: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/RegisterKernelListenersPass.php line 39');
}
$container = $this->getContainer();
$this->assertTrue($container->has('flasher'));
$this->assertTrue($container->has('flasher.noty'));
$this->assertTrue($container->has('flasher.notyf'));
$this->assertTrue($container->has('flasher.pnotify'));
$this->assertTrue($container->has('flasher.sweetalert'));
$this->assertTrue($container->has('flasher.toastr'));
$this->assertInstanceOf('Flasher\Prime\Flasher', $container->get('flasher'));
$this->assertInstanceOf('Flasher\Noty\Prime\NotyFactory', $container->get('flasher.noty'));
$this->assertInstanceOf('Flasher\Notyf\Prime\NotyfFactory', $container->get('flasher.notyf'));
$this->assertInstanceOf('Flasher\Pnotify\Prime\PnotifyFactory', $container->get('flasher.pnotify'));
$this->assertInstanceOf('Flasher\SweetAlert\Prime\SweetAlertFactory', $container->get('flasher.sweetalert'));
$this->assertInstanceOf('Flasher\Toastr\Prime\ToastrFactory', $container->get('flasher.toastr'));
}
}
-97
View File
@@ -1,97 +0,0 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
namespace Flasher\Tests\Symfony;
use Flasher\Noty\Prime\NotyPlugin;
use Flasher\Noty\Symfony\FlasherNotySymfonyBundle;
use Flasher\Notyf\Prime\NotyfPlugin;
use Flasher\Notyf\Symfony\FlasherNotyfSymfonyBundle;
use Flasher\Pnotify\Prime\PnotifyPlugin;
use Flasher\Pnotify\Symfony\FlasherPnotifySymfonyBundle;
use Flasher\SweetAlert\Prime\SweetAlertPlugin;
use Flasher\SweetAlert\Symfony\FlasherSweetAlertSymfonyBundle;
use Flasher\Symfony\DependencyInjection\FlasherExtension;
use Flasher\Symfony\FlasherSymfonyBundle;
use Flasher\Symfony\Support\Extension;
use Flasher\Tests\Prime\TestCase;
use Flasher\Toastr\Prime\ToastrPlugin;
use Flasher\Toastr\Symfony\FlasherToastrSymfonyBundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class FlasherExtensionTest extends TestCase
{
/**
* @return void
*/
public function testContainerContainFlasherServices()
{
$container = $this->getContainer();
$this->assertTrue($container->has('flasher'));
$this->assertTrue($container->has('flasher.noty'));
$this->assertTrue($container->has('flasher.notyf'));
$this->assertTrue($container->has('flasher.pnotify'));
$this->assertTrue($container->has('flasher.sweetalert'));
$this->assertTrue($container->has('flasher.toastr'));
}
/**
* @return ContainerBuilder
*/
private function getContainer()
{
$container = new ContainerBuilder();
$container->registerExtension(new FlasherExtension());
$plugins = array(
new NotyPlugin(),
new NotyfPlugin(),
new PnotifyPlugin(),
new SweetAlertPlugin(),
new ToastrPlugin(),
);
foreach ($plugins as $plugin) {
$container->registerExtension(new Extension($plugin));
}
$bundles = array(
new FlasherSymfonyBundle(),
new FlasherNotySymfonyBundle(),
new FlasherNotyfSymfonyBundle(),
new FlasherPnotifySymfonyBundle(),
new FlasherSweetAlertSymfonyBundle(),
new FlasherToastrSymfonyBundle(),
);
foreach ($bundles as $bundle) {
$bundle->build($container); // @phpstan-ignore-line
}
$container->getCompilerPassConfig()->setOptimizationPasses(array());
$container->getCompilerPassConfig()->setRemovingPasses(array());
$container->getCompilerPassConfig()->setAfterRemovingPasses(array());
$extensions = array(
'flasher',
'flasher_noty',
'flasher_notyf',
'flasher_pnotify',
'flasher_sweetalert',
'flasher_toastr',
);
foreach ($extensions as $extension) {
$container->loadFromExtension($extension, array());
}
$container->compile();
return $container;
}
}
+152
View File
@@ -0,0 +1,152 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
namespace Flasher\Tests\Symfony;
use Flasher\Noty\Symfony\FlasherNotySymfonyBundle;
use Flasher\Notyf\Symfony\FlasherNotyfSymfonyBundle;
use Flasher\Pnotify\Symfony\FlasherPnotifySymfonyBundle;
use Flasher\SweetAlert\Symfony\FlasherSweetAlertSymfonyBundle;
use Flasher\Symfony\Bridge\Bridge;
use Flasher\Symfony\FlasherSymfonyBundle;
use Flasher\Toastr\Symfony\FlasherToastrSymfonyBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
abstract class AbstractFlasherKernel extends Kernel
{
public function __construct()
{
parent::__construct('test', true);
}
public function doRegisterBundles()
{
return array(
new FrameworkBundle(),
new TwigBundle(),
new FlasherSymfonyBundle(),
new FlasherNotySymfonyBundle(),
new FlasherNotyfSymfonyBundle(),
new FlasherPnotifySymfonyBundle(),
new FlasherSweetAlertSymfonyBundle(),
new FlasherToastrSymfonyBundle(),
);
}
public function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
{
$framework = array(
'secret' => 'foo',
'test' => true,
'session' => array('handler_id' => null, 'storage_factory_id' => 'session.storage.factory.mock_file'),
'router' => array('resource' => 'kernel:loadRoutes', 'type' => 'service'),
);
if (Bridge::versionCompare('6.0', '<')) {
unset($framework['session']);
$framework['session']['storage_id'] = 'session.storage.filesystem';
}
if (Bridge::versionCompare('3', '<')) {
$framework['templating']['engines'] = 'twig';
}
$container->loadFromExtension('framework', $framework);
$twig = array('debug' => true, 'strict_variables' => true);
$container->loadFromExtension('twig', $twig);
}
public function doGetCacheDir()
{
return sys_get_temp_dir().'/cache'.spl_object_hash($this);
}
public function doGetLogDir()
{
return sys_get_temp_dir().'/logs'.spl_object_hash($this);
}
protected function configureRoutes(RouteCollectionBuilder $routes)
{
}
/**
* {@inheritDoc}
*/
public function registerContainerConfiguration(LoaderInterface $loader)
{
$that = $this;
$loader->load(function (ContainerBuilder $container) use ($loader, $that) {
if ($that instanceof EventSubscriberInterface) {
$class = get_class($that);
$container->register('kernel', $class)
->setSynthetic(true)
->setPublic(true)
->addTag('kernel.event_subscriber')
;
}
$that->configureContainer($container, $loader);
$container->addObjectResource($that);
});
}
}
if (Bridge::versionCompare('6.0', '>=')) {
eval('
namespace Flasher\Tests\Symfony;
class FlasherKernel extends AbstractFlasherKernel
{
public function registerBundles(): iterable
{
return $this->doRegisterBundles();
}
public function getCacheDir(): string
{
return $this->doGetLogDir();
}
public function getLogDir(): string
{
return $this->doGetLogDir();
}
public function getProjectDir(): string
{
return \dirname(__DIR__);
}
}
');
} else {
class FlasherKernel extends AbstractFlasherKernel
{
public function registerBundles()
{
return $this->doRegisterBundles();
}
public function getCacheDir()
{
return $this->doGetLogDir();
}
public function getLogDir()
{
return $this->doGetLogDir();
}
}
}
-1
View File
@@ -13,7 +13,6 @@ use Flasher\Prime\Stamp\PriorityStamp;
use Flasher\Prime\Stamp\UuidStamp;
use Flasher\Prime\Storage\StorageBag;
use Flasher\Symfony\Storage\SessionBag;
use Flasher\Tests\Prime\TestCase;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\HttpFoundation\SessionStorage\ArraySessionStorage;
+25
View File
@@ -0,0 +1,25 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
namespace Flasher\Tests\Symfony;
use Flasher\Symfony\Bridge\Bridge;
class TestCase extends \Flasher\Tests\Prime\TestCase
{
protected function getContainer()
{
$kernel = new FlasherKernel();
$kernel->boot();
if (Bridge::versionCompare('4.1', '>=')) {
return $kernel->getContainer()->get('test.service_container');
}
return $kernel->getContainer();
}
}
-1
View File
@@ -8,7 +8,6 @@
namespace Flasher\Tests\Symfony;
use Flasher\Symfony\Translation\Translator;
use Flasher\Tests\Prime\TestCase;
class TranslatorTest extends TestCase
{