ソースを参照

[DoctrineAbstractBundle] added test for new Loader

Bulat Shakirzyanov 14 年 前
コミット
97679e5bda

+ 1 - 1
src/Symfony/Bundle/DoctrineAbstractBundle/Common/DataFixtures/Loader.php

@@ -19,7 +19,7 @@ class Loader extends BaseLoader
     public function addFixture(FixtureInterface $fixture)
     {
         if ($fixture instanceof ContainerAwareInterface) {
-            $fixture->setContainer($container);
+            $fixture->setContainer($this->container);
         }
 
         parent::addFixture($fixture);

+ 21 - 0
src/Symfony/Bundle/DoctrineAbstractBundle/Tests/Common/ContainerAwareFixture.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace Symfony\Bundle\DoctrineAbstractBundle\Tests\Common;
+
+use Doctrine\Common\DataFixtures\FixtureInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\DependencyInjection\ContainerAwareInterface;
+
+class ContainerAwareFixture implements FixtureInterface, ContainerAwareInterface
+{
+    public $container;
+
+    public function setContainer(ContainerInterface $container = null)
+    {
+        $this->container = $container;
+    }
+
+    public function load($manager)
+    {
+    }
+}

+ 21 - 0
src/Symfony/Bundle/DoctrineAbstractBundle/Tests/Common/DataFixtures/LoaderTest.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace Symfony\Bundle\DoctrineAbstractBundle\Tests\Common\DataFixtures;
+
+use Symfony\Bundle\DoctrineAbstractBundle\Tests\TestCase;
+use Symfony\Bundle\DoctrineAbstractBundle\Tests\Common\ContainerAwareFixture;
+use Symfony\Bundle\DoctrineAbstractBundle\Common\DataFixtures\Loader;
+
+class LoaderTest extends TestCase
+{
+    public function testShouldSetContainerOnContainerAwareFixture()
+    {
+        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
+        $loader    = new Loader($container);
+        $fixture   = new ContainerAwareFixture();
+
+        $loader->addFixture($fixture);
+
+        $this->assertSame($container, $fixture->container);
+    }
+}

+ 13 - 0
src/Symfony/Bundle/DoctrineAbstractBundle/Tests/TestCase.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace Symfony\Bundle\DoctrineAbstractBundle\Tests;
+
+class TestCase extends \PHPUnit_Framework_TestCase
+{
+    protected function setUp()
+    {
+        if (!class_exists('Doctrine\Common\DataFixtures\Loader')) {
+            $this->markTestSkipped('Doctrine Data Fixtures is not available.');
+        }
+    }
+}