Skip to content

Commit

Permalink
Merge 4aaf9a8 into 932fc1a
Browse files Browse the repository at this point in the history
  • Loading branch information
covex-nn committed Jun 18, 2018
2 parents 932fc1a + 4aaf9a8 commit fc2ccc7
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 93 deletions.
3 changes: 1 addition & 2 deletions composer.json
Expand Up @@ -26,7 +26,7 @@
"doctrine/common": "^2.7",
"doctrine/inflector": "^1.1",
"knplabs/knp-menu-bundle": "^2.2",
"sonata-project/block-bundle": "^3.11 || ^4.0@dev",
"sonata-project/block-bundle": "^4.0@dev",
"sonata-project/core-bundle": "^3.9",
"sonata-project/exporter": "^1.8",
"symfony/asset": "^2.8 || ^3.2 || ^4.0",
Expand All @@ -47,7 +47,6 @@
"symfony/security-bundle": "^2.8 || ^3.2 || ^4.0",
"symfony/security-core": "^2.8 || ^3.2 || ^4.0",
"symfony/security-csrf": "^2.8 || ^3.2 || ^4.0",
"symfony/templating": "^2.8 || ^3.2 || ^4.0",
"symfony/translation": "^2.8 || ^3.2 || ^4.0",
"symfony/twig-bridge": "^2.8 || ^3.2 || ^4.0",
"symfony/twig-bundle": "^2.8 || ^3.2 || ^4.0",
Expand Down
6 changes: 3 additions & 3 deletions src/Block/AdminListBlockService.php
Expand Up @@ -18,9 +18,9 @@
use Sonata\AdminBundle\Templating\TemplateRegistryInterface;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Twig\Environment;

/**
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
Expand All @@ -42,11 +42,11 @@ class AdminListBlockService extends AbstractBlockService
*/
public function __construct(
$name,
EngineInterface $templating,
Environment $twig,
Pool $pool,
TemplateRegistryInterface $templateRegistry = null
) {
parent::__construct($name, $templating);
parent::__construct($name, $twig);

$this->pool = $pool;
$this->templateRegistry = $templateRegistry ?: new TemplateRegistry();
Expand Down
9 changes: 3 additions & 6 deletions src/Block/AdminSearchBlockService.php
Expand Up @@ -18,10 +18,10 @@
use Sonata\AdminBundle\Search\SearchHandler;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Twig\Environment;

/**
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
Expand All @@ -38,12 +38,9 @@ class AdminSearchBlockService extends AbstractBlockService
*/
protected $searchHandler;

/**
* @param string $name
*/
public function __construct($name, EngineInterface $templating, Pool $pool, SearchHandler $searchHandler)
public function __construct(string $name, Environment $twig, Pool $pool, SearchHandler $searchHandler)
{
parent::__construct($name, $templating);
parent::__construct($name, $twig);

$this->pool = $pool;
$this->searchHandler = $searchHandler;
Expand Down
9 changes: 3 additions & 6 deletions src/Block/AdminStatsBlockService.php
Expand Up @@ -16,9 +16,9 @@
use Sonata\AdminBundle\Admin\Pool;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Twig\Environment;

/**
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
Expand All @@ -30,12 +30,9 @@ class AdminStatsBlockService extends AbstractBlockService
*/
protected $pool;

/**
* @param string $name
*/
public function __construct($name, EngineInterface $templating, Pool $pool)
public function __construct(string $name, Environment $twig, Pool $pool)
{
parent::__construct($name, $templating);
parent::__construct($name, $twig);

$this->pool = $pool;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/config/block.xml
Expand Up @@ -4,21 +4,21 @@
<service id="sonata.admin.block.admin_list" class="Sonata\AdminBundle\Block\AdminListBlockService" public="true">
<tag name="sonata.block"/>
<argument>sonata.admin.block.admin_list</argument>
<argument type="service" id="sonata.templating"/>
<argument type="service" id="twig"/>
<argument type="service" id="sonata.admin.pool"/>
<argument type="service" id="sonata.admin.global_template_registry"/>
</service>
<service id="sonata.admin.block.search_result" class="Sonata\AdminBundle\Block\AdminSearchBlockService" public="true">
<tag name="sonata.block"/>
<argument>sonata.admin.block.search_result</argument>
<argument type="service" id="sonata.templating"/>
<argument type="service" id="twig"/>
<argument type="service" id="sonata.admin.pool"/>
<argument type="service" id="sonata.admin.search.handler"/>
</service>
<service id="sonata.admin.block.stats" class="Sonata\AdminBundle\Block\AdminStatsBlockService" public="true">
<tag name="sonata.block"/>
<argument>sonata.admin.block.stats</argument>
<argument type="service" id="sonata.templating"/>
<argument type="service" id="twig"/>
<argument type="service" id="sonata.admin.pool"/>
</service>
</services>
Expand Down
4 changes: 2 additions & 2 deletions tests/Block/AdminListBlockServiceTest.php
Expand Up @@ -45,7 +45,7 @@ protected function setUp(): void

public function testDefaultSettings(): void
{
$blockService = new AdminListBlockService('foo', $this->templating, $this->pool, $this->templateRegistry->reveal());
$blockService = new AdminListBlockService('foo', $this->twig, $this->pool, $this->templateRegistry->reveal());
$blockContext = $this->getBlockContext($blockService);

$this->assertSettings([
Expand All @@ -55,7 +55,7 @@ public function testDefaultSettings(): void

public function testOverriddenDefaultSettings(): void
{
$blockService = new FakeBlockService('foo', $this->templating, $this->pool, $this->templateRegistry->reveal());
$blockService = new FakeBlockService('foo', $this->twig, $this->pool, $this->templateRegistry->reveal());
$blockContext = $this->getBlockContext($blockService);

$this->assertSettings([
Expand Down
10 changes: 5 additions & 5 deletions tests/Block/AdminSearchBlockServiceTest.php
Expand Up @@ -18,7 +18,7 @@
use Sonata\AdminBundle\Block\AdminSearchBlockService;
use Sonata\AdminBundle\Search\SearchHandler;
use Sonata\BlockBundle\Test\AbstractBlockServiceTestCase;
use Sonata\BlockBundle\Test\FakeTemplating;
use Twig\Environment;

/**
* @author Sullivan Senechal <soullivaneuh@gmail.com>
Expand All @@ -45,7 +45,7 @@ protected function setUp(): void

public function testDefaultSettings(): void
{
$blockService = new AdminSearchBlockService('foo', $this->templating, $this->pool, $this->searchHandler);
$blockService = new AdminSearchBlockService('foo', $this->twig, $this->pool, $this->searchHandler);
$blockContext = $this->getBlockContext($blockService);

$this->assertSettings([
Expand All @@ -60,9 +60,9 @@ public function testDefaultSettings(): void
public function testGlobalSearchReturnsEmptyWhenFiltersAreDisabled(): void
{
$admin = $this->getMockBuilder(AbstractAdmin::class)->disableOriginalConstructor()->getMock();
$templating = $this->getMockBuilder(FakeTemplating::class)->disableOriginalConstructor()->getMock();
$twig = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock();

$blockService = new AdminSearchBlockService('foo', $templating, $this->pool, $this->searchHandler);
$blockService = new AdminSearchBlockService('foo', $twig, $this->pool, $this->searchHandler);
$blockContext = $this->getBlockContext($blockService);

$this->searchHandler->expects(self::once())->method('search')->willReturn(false);
Expand All @@ -71,7 +71,7 @@ public function testGlobalSearchReturnsEmptyWhenFiltersAreDisabled(): void

// Make sure the template is never generated (empty response is required,
// but the FakeTemplate always returns an empty response)
$templating->expects(self::never())->method('renderResponse');
$twig->expects(self::never())->method('render');

$response = $blockService->execute($blockContext);

Expand Down
2 changes: 1 addition & 1 deletion tests/Block/AdminStatsBlockServiceTest.php
Expand Up @@ -36,7 +36,7 @@ protected function setUp(): void

public function testDefaultSettings(): void
{
$blockService = new AdminStatsBlockService('foo', $this->templating, $this->pool);
$blockService = new AdminStatsBlockService('foo', $this->twig, $this->pool);
$blockContext = $this->getBlockContext($blockService);

$this->assertSettings([
Expand Down
27 changes: 7 additions & 20 deletions tests/Controller/CRUDControllerTest.php
Expand Up @@ -40,7 +40,6 @@
use Symfony\Bridge\Twig\Extension\FormExtension;
use Symfony\Bridge\Twig\Form\TwigRenderer;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormRenderer;
Expand Down Expand Up @@ -164,11 +163,7 @@ protected function setUp(): void

$this->templateRegistry = $this->prophesize(TemplateRegistryInterface::class);

$templating = $this->getMockBuilder(DelegatingEngine::class)
->setConstructorArgs([$this->container, []])
->getMock();

$templatingRenderReturnCallback = $this->returnCallback(function (
$twigRenderReturnCallback = $this->returnCallback(function (
$view,
array $parameters = [],
Response $response = null
Expand All @@ -184,15 +179,6 @@ protected function setUp(): void
return $response;
});

// SF < 3.3.10 BC
$templating->expects($this->any())
->method('renderResponse')
->will($templatingRenderReturnCallback);

$templating->expects($this->any())
->method('render')
->will($templatingRenderReturnCallback);

$this->session = new Session(new MockArraySessionStorage());

$twig = $this->getMockBuilder(\Twig_Environment::class)
Expand All @@ -219,6 +205,10 @@ protected function setUp(): void
}
}));

$twig->expects($this->any())
->method('render')
->will($twigRenderReturnCallback);

// NEXT_MAJOR : require sonata/exporter ^1.7 and remove conditional
if (class_exists(Exporter::class)) {
$exporter = new Exporter([new JsonWriter('/tmp/sonataadmin/export.json')]);
Expand Down Expand Up @@ -267,7 +257,6 @@ protected function setUp(): void
$this->container->expects($this->any())
->method('get')
->will($this->returnCallback(function ($id) use (
$templating,
$twig,
$exporter,
$requestStack
Expand All @@ -281,8 +270,6 @@ protected function setUp(): void
return $this->admin;
case 'foo.admin.template_registry':
return $this->templateRegistry->reveal();
case 'templating':
return $templating;
case 'twig':
return $twig;
case 'session':
Expand Down Expand Up @@ -319,11 +306,11 @@ protected function setUp(): void
return true;
}

if ('templating' == $id) {
if ('translator' == $id) {
return true;
}

if ('translator' == $id) {
if ('twig' == $id) {
return true;
}

Expand Down
14 changes: 7 additions & 7 deletions tests/Controller/CoreControllerTest.php
Expand Up @@ -19,11 +19,11 @@
use Sonata\AdminBundle\Admin\Pool;
use Sonata\AdminBundle\Controller\CoreController;
use Sonata\AdminBundle\Templating\MutableTemplateRegistryInterface;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;

class CoreControllerTest extends TestCase
{
Expand All @@ -42,7 +42,7 @@ public function testdashboardActionStandardRequest(): void
$pool = new Pool($container, 'title', 'logo.png');
$pool->setTemplateRegistry($templateRegistry->reveal());

$templating = $this->createMock(EngineInterface::class);
$twig = $this->createMock(Environment::class);
$request = new Request();

$requestStack = new RequestStack();
Expand All @@ -57,7 +57,7 @@ public function testdashboardActionStandardRequest(): void
$templateRegistry->reveal(),
$pool
),
'templating' => $templating,
'twig' => $twig,
'request_stack' => $requestStack,
];
$dashboardAction->setContainer($container);
Expand All @@ -69,7 +69,7 @@ public function testdashboardActionStandardRequest(): void
$container->expects($this->any())
->method('has')
->will($this->returnCallback(function ($id) {
return 'templating' === $id;
return 'twig' === $id;
}));

$controller = new CoreController();
Expand All @@ -94,7 +94,7 @@ public function testdashboardActionAjaxLayout(): void
$pool = new Pool($container, 'title', 'logo.png');
$pool->setTemplateRegistry($templateRegistry->reveal());

$templating = $this->createMock(EngineInterface::class);
$twig = $this->createMock(Environment::class);
$request = new Request();
$request->headers->set('X-Requested-With', 'XMLHttpRequest');

Expand All @@ -108,7 +108,7 @@ public function testdashboardActionAjaxLayout(): void
$templateRegistry->reveal(),
$pool
),
'templating' => $templating,
'twig' => $twig,
'request_stack' => $requestStack,
];
$dashboardAction->setContainer($container);
Expand All @@ -120,7 +120,7 @@ public function testdashboardActionAjaxLayout(): void
$container->expects($this->any())
->method('has')
->will($this->returnCallback(function ($id) {
return 'templating' === $id;
return 'twig' === $id;
}));

$controller = new CoreController();
Expand Down
Expand Up @@ -20,14 +20,11 @@
use Sonata\AdminBundle\DependencyInjection\Compiler\AddDependencyCallsCompilerPass;
use Sonata\AdminBundle\DependencyInjection\SonataAdminExtension;
use Sonata\AdminBundle\Route\RoutesCache;
use Sonata\BlockBundle\DependencyInjection\SonataBlockExtension;
use Sonata\DoctrinePHPCRAdminBundle\Route\PathInfoBuilderSlashes;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Bundle\FrameworkBundle\Translation\Translator;
use Symfony\Bundle\FrameworkBundle\Translation\TranslatorInterface;
use Symfony\Bundle\FrameworkBundle\Validator\ConstraintValidatorFactory;
use Symfony\Bundle\FrameworkBundle\Validator\Validator;
use Symfony\Component\Config\FileLocatorInterface;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
Expand All @@ -36,9 +33,9 @@
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\PropertyAccess\PropertyAccessor;
use Symfony\Component\Routing\RouterInterface;
use Twig\Environment;

/**
* @author Tiago Garcia
Expand Down Expand Up @@ -640,10 +637,7 @@ private function getContainer()
// Add dependencies for SonataAdminBundle (these services will never get called so dummy classes will do)
$container
->register('twig')
->setClass(EngineInterface::class);
$container
->register('templating')
->setClass(EngineInterface::class);
->setClass(Environment::class);
$container
->register('translator')
->setClass(TranslatorInterface::class);
Expand Down Expand Up @@ -763,17 +757,6 @@ private function getContainer()
->setClass(Translator::class);
$container->setAlias('translator', 'translator.default');

// Add definitions for sonata.templating service
$container
->register('kernel')
->setClass(KernelInterface::class);
$container
->register('file_locator')
->setClass(FileLocatorInterface::class);

$blockExtension = new SonataBlockExtension();
$blockExtension->load([], $container);

return $container;
}
}

0 comments on commit fc2ccc7

Please sign in to comment.