Pārlūkot izejas kodu

Merge pull request #2258 from pulzarraider/bundle_test

Added test for SonataAdminBundle and configureQuery in AdminEventExtension
Thomas 10 gadi atpakaļ
vecāks
revīzija
9b437bf42d

+ 8 - 1
Tests/Event/AdminEventExtensionTest.php

@@ -123,6 +123,13 @@ class AdminEventExtensionTest extends \PHPUnit_Framework_TestCase
         ))->preUpdate($this->getMock('Sonata\AdminBundle\Admin\AdminInterface'), new \stdClass);
     }
 
+    public function testConfigureQuery()
+    {
+        $this->getExtension(array(
+            $this->equalTo('sonata.admin.event.configure.query'),
+        ))->configureQuery($this->getMock('Sonata\AdminBundle\Admin\AdminInterface'), $this->getMock('Sonata\AdminBundle\Datagrid\ProxyQueryInterface'));
+    }
+
     public function testPostUpdate()
     {
         $this->getExtension(array(
@@ -163,4 +170,4 @@ class AdminEventExtensionTest extends \PHPUnit_Framework_TestCase
         ))->postRemove($this->getMock('Sonata\AdminBundle\Admin\AdminInterface'), new \stdClass);
     }
 
-}
+}

+ 54 - 0
Tests/SonataAdminBundleTest.php

@@ -0,0 +1,54 @@
+<?php
+
+/*
+ * This file is part of the Sonata 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;
+
+use Sonata\AdminBundle\SonataAdminBundle;
+use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+use Symfony\Component\DependencyInjection\Compiler\PassConfig;
+use Sonata\AdminBundle\DependencyInjection\Compiler\AddDependencyCallsCompilerPass;
+use Sonata\AdminBundle\DependencyInjection\Compiler\AddFilterTypeCompilerPass;
+use Sonata\AdminBundle\DependencyInjection\Compiler\ExtensionCompilerPass;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+
+/**
+ * Test for SonataAdminBundle
+ *
+ * @author Andrej Hudec <pulzarraider@gmail.com>
+ */
+class SonataAdminBundleTest extends \PHPUnit_Framework_TestCase
+{
+    public function testBuild()
+    {
+        $containerBuilder = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
+
+        $containerBuilder->expects($this->exactly(3))
+            ->method('addCompilerPass')
+            ->will($this->returnCallback(function (CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION) {
+                if ($pass instanceof AddDependencyCallsCompilerPass) {
+                    return;
+                }
+
+                if ($pass instanceof AddFilterTypeCompilerPass) {
+                    return;
+                }
+
+                if ($pass instanceof ExtensionCompilerPass) {
+                    return;
+                }
+
+                $this->fail(sprintf('Compiler pass is not one of the expected types. Expects "Sonata\AdminBundle\DependencyInjection\Compiler\AddDependencyCallsCompilerPass", "Sonata\AdminBundle\DependencyInjection\Compiler\AddFilterTypeCompilerPass" or "Sonata\AdminBundle\DependencyInjection\Compiler\ExtensionCompilerPass", but got "%s".', get_class($pass)));
+            }));
+
+        $bundle = new SonataAdminBundle();
+        $bundle->build($containerBuilder);
+    }
+}