Bläddra i källkod

Fix deprecated BlockService::setDefaultSettings usage

Sullivan SENECHAL 9 år sedan
förälder
incheckning
4a7ef8c16d

+ 6 - 6
Block/AdminListBlockService.php

@@ -16,21 +16,21 @@ use Sonata\BlockBundle\Block\BaseBlockService;
 use Sonata\BlockBundle\Block\BlockContextInterface;
 use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
 use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\OptionsResolver\OptionsResolverInterface;
+use Symfony\Component\OptionsResolver\OptionsResolver;
 
 /**
  * Class AdminListBlockService.
  *
- * @author  Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  */
 class AdminListBlockService extends BaseBlockService
 {
     protected $pool;
 
     /**
-     * @param string                                                     $name
-     * @param \Symfony\Bundle\FrameworkBundle\Templating\EngineInterface $templating
-     * @param \Sonata\AdminBundle\Admin\Pool                             $pool
+     * @param string          $name
+     * @param EngineInterface $templating
+     * @param Pool            $pool
      */
     public function __construct($name, EngineInterface $templating, Pool $pool)
     {
@@ -74,7 +74,7 @@ class AdminListBlockService extends BaseBlockService
     /**
      * {@inheritdoc}
      */
-    public function setDefaultSettings(OptionsResolverInterface $resolver)
+    public function configureSettings(OptionsResolver $resolver)
     {
         $resolver->setDefaults(array(
             'groups' => false,

+ 2 - 2
Block/AdminSearchBlockService.php

@@ -19,7 +19,7 @@ use Sonata\BlockBundle\Block\BlockContextInterface;
 use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
 use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
 use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\OptionsResolver\OptionsResolverInterface;
+use Symfony\Component\OptionsResolver\OptionsResolver;
 use Symfony\Component\Security\Core\Exception\AccessDeniedException;
 
 /**
@@ -91,7 +91,7 @@ class AdminSearchBlockService extends BaseBlockService
     /**
      * {@inheritdoc}
      */
-    public function setDefaultSettings(OptionsResolverInterface $resolver)
+    public function configureSettings(OptionsResolver $resolver)
     {
         $resolver->setDefaults(array(
             'admin_code' => false,

+ 2 - 2
Block/AdminStatsBlockService.php

@@ -16,7 +16,7 @@ use Sonata\BlockBundle\Block\BaseBlockService;
 use Sonata\BlockBundle\Block\BlockContextInterface;
 use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
 use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\OptionsResolver\OptionsResolverInterface;
+use Symfony\Component\OptionsResolver\OptionsResolver;
 
 /**
  * Class AdminStatsBlockService.
@@ -81,7 +81,7 @@ class AdminStatsBlockService extends BaseBlockService
     /**
      * {@inheritdoc}
      */
-    public function setDefaultSettings(OptionsResolverInterface $resolver)
+    public function configureSettings(OptionsResolver $resolver)
     {
         $resolver->setDefaults(array(
             'icon'     => 'fa-line-chart',

+ 55 - 0
Tests/Block/AdminListBlockServiceTest.php

@@ -0,0 +1,55 @@
+<?php
+
+/*
+ * 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\AdminBundle\Tests\Block;
+
+use Sonata\AdminBundle\Admin\Pool;
+use Sonata\AdminBundle\Block\AdminListBlockService;
+use Sonata\BlockBundle\Tests\Block\AbstractBlockServiceTest;
+
+/**
+ * @author Sullivan Senechal <soullivaneuh@gmail.com>
+ */
+class AdminListBlockServiceTest extends AbstractBlockServiceTest
+{
+    /**
+     * @var Pool
+     */
+    private $pool;
+
+    protected function setUp()
+    {
+        parent::setUp();
+
+        $this->pool = $this->getMockBuilder('Sonata\AdminBundle\Admin\Pool')->disableOriginalConstructor()->getMock();
+    }
+
+    public function testDefaultSettings()
+    {
+        $blockService = new AdminListBlockService('foo', $this->templating, $this->pool);
+        $blockContext = $this->getBlockContext($blockService);
+
+        $this->assertSettings(array(
+            'groups' => false,
+        ), $blockContext);
+    }
+
+    public function testOverriddenDefaultSettings()
+    {
+        $blockService = new FakeBlockService('foo', $this->templating, $this->pool);
+        $blockContext = $this->getBlockContext($blockService);
+
+        $this->assertSettings(array(
+            'foo'    => 'bar',
+            'groups' => true,
+        ), $blockContext);
+    }
+}

+ 54 - 0
Tests/Block/AdminSearchBlockServiceTest.php

@@ -0,0 +1,54 @@
+<?php
+
+/*
+ * 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\AdminBundle\Tests\Block;
+
+use Sonata\AdminBundle\Admin\Pool;
+use Sonata\AdminBundle\Block\AdminSearchBlockService;
+use Sonata\AdminBundle\Search\SearchHandler;
+use Sonata\BlockBundle\Tests\Block\AbstractBlockServiceTest;
+
+/**
+ * @author Sullivan Senechal <soullivaneuh@gmail.com>
+ */
+class AdminSearchBlockServiceTest extends AbstractBlockServiceTest
+{
+    /**
+     * @var Pool
+     */
+    private $pool;
+
+    /**
+     * @var SearchHandler
+     */
+    private $searchHandler;
+
+    protected function setUp()
+    {
+        parent::setUp();
+
+        $this->pool = $this->getMockBuilder('Sonata\AdminBundle\Admin\Pool')->disableOriginalConstructor()->getMock();
+        $this->searchHandler = $this->getMockBuilder('Sonata\AdminBundle\Search\SearchHandler')->disableOriginalConstructor()->getMock();
+    }
+
+    public function testDefaultSettings()
+    {
+        $blockService = new AdminSearchBlockService('foo', $this->templating, $this->pool, $this->searchHandler);
+        $blockContext = $this->getBlockContext($blockService);
+
+        $this->assertSettings(array(
+            'admin_code' => false,
+            'query'      => '',
+            'page'       => 0,
+            'per_page'   => 10,
+        ), $blockContext);
+    }
+}

+ 50 - 0
Tests/Block/AdminStatsBlockServiceTest.php

@@ -0,0 +1,50 @@
+<?php
+
+/*
+ * 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\AdminBundle\Tests\Block;
+
+use Sonata\AdminBundle\Admin\Pool;
+use Sonata\AdminBundle\Block\AdminStatsBlockService;
+use Sonata\BlockBundle\Tests\Block\AbstractBlockServiceTest;
+
+/**
+ * @author Sullivan Senechal <soullivaneuh@gmail.com>
+ */
+class AdminStatsBlockServiceTest extends AbstractBlockServiceTest
+{
+    /**
+     * @var Pool
+     */
+    private $pool;
+
+    protected function setUp()
+    {
+        parent::setUp();
+
+        $this->pool = $this->getMockBuilder('Sonata\AdminBundle\Admin\Pool')->disableOriginalConstructor()->getMock();
+    }
+
+    public function testDefaultSettings()
+    {
+        $blockService = new AdminStatsBlockService('foo', $this->templating, $this->pool);
+        $blockContext = $this->getBlockContext($blockService);
+
+        $this->assertSettings(array(
+            'icon'     => 'fa-line-chart',
+            'text'     => 'Statistics',
+            'color'    => 'bg-aqua',
+            'code'     => false,
+            'filters'  => array(),
+            'limit'    => 1000,
+            'template' => 'SonataAdminBundle:Block:block_stats.html.twig',
+        ), $blockContext);
+    }
+}

+ 33 - 0
Tests/Block/FakeBlockService.php

@@ -0,0 +1,33 @@
+<?php
+
+/*
+ * 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\AdminBundle\Tests\Block;
+
+use Sonata\AdminBundle\Block\AdminListBlockService;
+use Symfony\Component\OptionsResolver\OptionsResolverInterface;
+
+/**
+ * @author Sullivan Senechal <soullivaneuh@gmail.com>
+ */
+class FakeBlockService extends AdminListBlockService
+{
+    public function setDefaultSettings(OptionsResolverInterface $resolver)
+    {
+        parent::setDefaultSettings($resolver);
+
+        $resolver
+            ->setDefaults(array(
+                'foo'    => 'bar',
+                'groups' => true,
+            ))
+        ;
+    }
+}

+ 1 - 1
composer.json

@@ -33,7 +33,7 @@
         "twig/twig": "~1.15",
         "twig/extensions": "~1.0",
         "sonata-project/exporter": "~1.0",
-        "sonata-project/block-bundle": "~2.3",
+        "sonata-project/block-bundle": "^2.3.8",
         "sonata-project/core-bundle": "^2.3.6",
         "doctrine/common": "~2.2",
         "doctrine/inflector": "~1.0",