Skip to content
This repository has been archived by the owner on Sep 30, 2021. It is now read-only.

Commit

Permalink
Fix pack with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wbloszyk committed May 22, 2020
1 parent f53d95d commit b89c7e3
Show file tree
Hide file tree
Showing 34 changed files with 609 additions and 46 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
"nelmio/api-doc-bundle": "^2.11",
"phpspec/prophecy": "^1.0",
"sonata-project/exporter": "^1.11 || ^2.0",
"symfony/phpunit-bridge": "^4.3"
"symfony/browser-kit": "4.3",
"symfony/phpunit-bridge": "^4.3",
"symfony/twig-bundle": "^4.3"
},
"suggest": {
"sonata-project/doctrine-extensions": "Direct replacement for Doctrine behavioral extensions",
Expand Down
7 changes: 6 additions & 1 deletion src/CoreBundle/DependencyInjection/SonataCoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,12 @@ public function registerFlashTypes(ContainerBuilder $container, array $config)

$identifier = 'sonata.twig.flashmessage.manager';

$definition = $container->getDefinition($identifier);
if ($container->has($identifier)) {
$definition = $container->getDefinition($identifier);
} else {
$definition = $container->getDefinition('sonata.core.flashmessage.manager');
}

$definition->replaceArgument(2, $types);
$definition->replaceArgument(3, $cssClasses);

Expand Down
2 changes: 1 addition & 1 deletion src/CoreBundle/Resources/config/core_form_types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<service id="sonata.core.form.type.datetime_range_picker" alias="sonata.form.type.datetime_range_picker" public="true">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.x and will be removed in 4.0. Use "%alias_id%" instead.</deprecated>
</service>
<service id="sonata.core.form.type.equal" class="sonata.form.type.equal" public="true">
<service id="sonata.core.form.type.equal" class="Sonata\Form\Type\EqualType" public="true">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.x and will be removed in 4.0. Use "%alias_id%" instead.</deprecated>
</service>
</services>
Expand Down
11 changes: 5 additions & 6 deletions src/CoreBundle/Resources/config/core_twig.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sonata.core.twig.extension.wrapping" class="Sonata\Twig\Extension\FormTypeExtension">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.x and will be removed in 4.0. Use "sonata.twig.extension.wrapping" instead.</deprecated>
<tag name="twig.extension"/>
<argument>%sonata.core.form_type%</argument>
<service id="sonata.core.twig.extension.wrapping" alias="sonata.twig.extension.wrapping">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.x and will be removed in 4.0. Use "%alias_id%" instead.</deprecated>
</service>
<service id="sonata.core.twig.extension.text" class="Sonata\CoreBundle\Twig\Extension\DeprecatedTextExtension">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.x and will be removed in 4.0.</deprecated>
Expand All @@ -13,8 +11,9 @@
<service id="sonata.core.twig.status_runtime" alias="sonata.twig.status_runtime">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.x and will be removed in 4.0. Use "%alias_id%" instead.</deprecated>
</service>
<service id="sonata.core.twig.status_extension" alias="sonata.twig.status_extension">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.x and will be removed in 4.0. Use "%alias_id%" instead.</deprecated>
<service id="sonata.core.twig.status_extension" class="Sonata\CoreBundle\Twig\Extension\StatusExtension">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.x and will be removed in 4.0. Use "sonata.twig.status_extension" instead.</deprecated>
<tag name="twig.extension"/>
</service>
<service id="sonata.core.twig.deprecated_template_extension" alias="sonata.twig.deprecated_template_extension">
<deprecated>The "%service_id%" service is deprecated since sonata-project/core-bundle 3.x and will be removed in 4.0. Use "%alias_id%" instead.</deprecated>
Expand Down
6 changes: 3 additions & 3 deletions src/CoreBundle/Twig/Extension/StatusExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
namespace Sonata\CoreBundle\Twig\Extension;

use Sonata\CoreBundle\Component\Status\StatusClassRendererInterface;
use Sonata\Twig\Extension\StatusExtension as BaseStatusExtension;
use Sonata\Twig\Extension\StatusRuntime;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

/**
* @author Hugo Briand <briand@ekino.com>
* @author Titouan Galopin <galopintitouan@gmail.com>
*
* @deprecated since sonata-project/core-bundle 3.13.0, to be removed in 4.0.
* @deprecated since sonata-project/core-bundle 3.13.0, to be removed in 4.0. Use "Sonata\Twig\Extension\StatusExtension" instead.
*/
class StatusExtension extends AbstractExtension
class StatusExtension extends BaseStatusExtension
{
/**
* @var StatusClassRendererInterface[]
Expand Down
5 changes: 5 additions & 0 deletions src/Form/Bridge/Symfony/SonataFormBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@

namespace Sonata\Form\Bridge\Symfony;

use Sonata\Form\Bridge\Symfony\DependencyInjection\SonataFormExtension;
use Symfony\Component\HttpKernel\Bundle\Bundle;

final class SonataFormBundle extends Bundle
{
protected function getContainerExtensionClass()
{
return SonataFormExtension::class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ public function load(array $configs, ContainerBuilder $container): void
/**
* Registers flash message types defined in configuration to flash manager.
*/
public function registerFlashTypes(ContainerBuilder $container, array $config): void
public function registerFlashTypes(ContainerBuilder $container, array $config)
{
$mergedConfig = array_merge_recursive($config['flashmessage'], [
'success' => ['types' => [
'success' => ['domain' => 'SonataTwigBundle'],
'success' => ['domain' => 'SonataCoreBundle'],
'sonata_flash_success' => ['domain' => 'SonataAdminBundle'],
'sonata_user_success' => ['domain' => 'SonataUserBundle'],
'fos_user_success' => ['domain' => 'FOSUserBundle'],
]],
'warning' => ['types' => [
'warning' => ['domain' => 'SonataTwigBundle'],
'warning' => ['domain' => 'SonataCoreBundle'],
'sonata_flash_info' => ['domain' => 'SonataAdminBundle'],
]],
'danger' => ['types' => [
'error' => ['domain' => 'SonataTwigBundle'],
'error' => ['domain' => 'SonataCoreBundle'],
'sonata_flash_error' => ['domain' => 'SonataAdminBundle'],
'sonata_user_error' => ['domain' => 'SonataUserBundle'],
]],
Expand All @@ -71,8 +71,8 @@ public function registerFlashTypes(ContainerBuilder $container, array $config):
$identifier = 'sonata.twig.flashmessage.manager';

$definition = $container->getDefinition($identifier);
$definition->replaceArgument(1, $types);
$definition->replaceArgument(2, $cssClasses);
$definition->replaceArgument(2, $types);
$definition->replaceArgument(3, $cssClasses);

$container->setDefinition($identifier, $definition);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Twig/Bridge/Symfony/Resources/config/flash.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<tag name="sonata.status.renderer"/>
<argument type="service" id="session"/>
<argument type="service" id="translator"/>
<argument/>
<argument/>
<argument type="collection"/>
<argument type="collection"/>
</service>
<service id="sonata.twig.flashmessage.twig.runtime" class="Sonata\Twig\Extension\FlashMessageRuntime">
<tag name="twig.runtime"/>
Expand Down
3 changes: 3 additions & 0 deletions src/Twig/Bridge/Symfony/SonataTwigBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*/
final class SonataTwigBundle extends Bundle
{
public function build(ContainerBuilder $container): void
Expand Down
2 changes: 0 additions & 2 deletions src/Twig/Extension/FlashMessageRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,3 @@ public function getFlashMessagesTypes()
return $this->flashManager->getHandledTypes();
}
}

class_exists(\Sonata\CoreBundle\Twig\Extension\FlashMessageRuntime::class);
36 changes: 36 additions & 0 deletions src/Twig/Extension/StatusExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\Twig\Extension;

use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

/**
* @author Hugo Briand <briand@ekino.com>
* @author Titouan Galopin <galopintitouan@gmail.com>
*/
class StatusExtension extends AbstractExtension
{
public function getFilters()
{
return [
new TwigFilter('sonata_status_class', [StatusRuntime::class, 'statusClass']),
];
}

public function getName()
{
return 'sonata_twig_status';
}
}
79 changes: 79 additions & 0 deletions tests/CoreBundle/App/AppKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\CoreBundle\Tests\App;

use Sonata\CoreBundle\SonataCoreBundle;
use Sonata\Doctrine\Bridge\Symfony\Bundle\SonataDoctrineBundle;
use Symfony\Bundle\FrameworkBundle\Controller\TemplateController;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollectionBuilder;

final class AppKernel extends Kernel
{
use MicroKernelTrait;

public function __construct()
{
parent::__construct('test', false);
}

public function registerBundles(): array
{
return [
new FrameworkBundle(),
new TwigBundle(),
new SonataDoctrineBundle(),
new SonataCoreBundle(),
];
}

public function getCacheDir(): string
{
return $this->getBaseDir().'cache';
}

public function getLogDir(): string
{
return $this->getBaseDir().'log';
}

public function getProjectDir(): string
{
return __DIR__;
}

protected function configureRoutes(RouteCollectionBuilder $routes): void
{
$route = new Route('/');
$route->setDefault('_controller', TemplateController::class.'::templateAction');
$routes->setDefault('template', 'index.html.twig');
$routes->addRoute($route);
}

protected function configureContainer(ContainerBuilder $containerBuilder, LoaderInterface $loader): void
{
$loader->load(__DIR__.'/config.yml');
}

private function getBaseDir(): string
{
return sys_get_temp_dir().'/sonata-project/core-bundle/var/';
}
}
11 changes: 11 additions & 0 deletions tests/CoreBundle/App/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
framework:
secret: secret
test: true
session:
handler_id: ~
storage_id: session.storage.mock_file
name: 'MOCKSESSID'

twig:
paths:
- '%kernel.project_dir%/templates'
9 changes: 9 additions & 0 deletions tests/CoreBundle/App/templates/index.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Welcome!</title>
</head>
<body>
</body>
</html>
46 changes: 46 additions & 0 deletions tests/CoreBundle/Functional/FunctionalTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\CoreBundle\Tests\Functional;

use Sonata\CoreBundle\Tests\App\AppKernel;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpKernel\KernelInterface;

final class FunctionalTest extends WebTestCase
{
public function testRenderFlashes(): void
{
$kernel = new AppKernel();

$client = $this->createClientBC($kernel);
$client->request('GET', '/');

$this->assertSame(200, $client->getResponse()->getStatusCode());
}

protected static function getKernelClass(): string
{
return AppKernel::class;
}

private function createClientBC(KernelInterface $kernel)
{
if (class_exists(KernelBrowser::class)) {
return new KernelBrowser($kernel);
}

return static::createClient();
}
}
Loading

0 comments on commit b89c7e3

Please sign in to comment.