diff --git a/core/lib/Thelia/Tests/Action/CategoryTest.php b/core/lib/Thelia/Tests/Action/CategoryTest.php index 480c6f437..50d60f01a 100644 --- a/core/lib/Thelia/Tests/Action/CategoryTest.php +++ b/core/lib/Thelia/Tests/Action/CategoryTest.php @@ -23,6 +23,8 @@ namespace Thelia\Tests\Action; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\Routing\Router; use Thelia\Action\Category; use Thelia\Core\Event\Category\CategoryDeleteEvent; use Thelia\Core\Event\Category\CategoryUpdateEvent; @@ -30,6 +32,7 @@ use Thelia\Core\Event\UpdateSeoEvent; use Thelia\Model\Category as CategoryModel; use Thelia\Core\Event\Category\CategoryCreateEvent; use Thelia\Model\CategoryQuery; +use Thelia\Tests\TestCaseWithURLToolSetup; use Thelia\Tools\URL; @@ -38,19 +41,8 @@ use Thelia\Tools\URL; * @package Thelia\Tests\Action * @author Manuel Raynaud */ -class CategoryTest extends \PHPUnit_Framework_TestCase +class CategoryTest extends TestCaseWithURLToolSetup { - use RewrittenUrlTestTrait; - - /** - * @var EventDispatcherInterface - */ - protected $dispatcher; - - public function setUp() - { - $this->dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"); - } protected function getRandomCategory() { @@ -81,7 +73,7 @@ class CategoryTest extends \PHPUnit_Framework_TestCase ->setPostscriptum('bar postscriptum') ->setVisible(0) ->setParent(0) - ->setDispatcher($this->dispatcher) + ->setDispatcher($this->getDispatcher()) ; } @@ -92,7 +84,7 @@ class CategoryTest extends \PHPUnit_Framework_TestCase } $event = new UpdateSeoEvent($category->getId()); - $event->setDispatcher($this->dispatcher); + $event->setDispatcher($this->getDispatcher()); $event ->setLocale($category->getLocale()) ->setMetaTitle($category->getMetaTitle()) @@ -127,7 +119,7 @@ class CategoryTest extends \PHPUnit_Framework_TestCase ->setParent(0) ->setTitle('foo') ->setVisible(1) - ->setDispatcher($this->dispatcher); + ->setDispatcher($this->getDispatcher()); $action = new Category(); $action->create($event); @@ -165,7 +157,7 @@ class CategoryTest extends \PHPUnit_Framework_TestCase ->setPostscriptum('bar postscriptum') ->setVisible(0) ->setParent(0) - ->setDispatcher($this->dispatcher) + ->setDispatcher($this->getDispatcher()) ; $action = new Category(); @@ -192,7 +184,7 @@ class CategoryTest extends \PHPUnit_Framework_TestCase public function testDelete(CategoryModel $category) { $event = new CategoryDeleteEvent($category->getId()); - $event->setDispatcher($this->dispatcher); + $event->setDispatcher($this->getDispatcher()); $action = new Category(); $action->delete($event); @@ -201,8 +193,5 @@ class CategoryTest extends \PHPUnit_Framework_TestCase $this->assertInstanceOf('Thelia\Model\Category', $deletedCategory); $this->assertTrue($deletedCategory->isDeleted()); - - } - } \ No newline at end of file diff --git a/core/lib/Thelia/Tests/TestCaseWithURLToolSetup.php b/core/lib/Thelia/Tests/TestCaseWithURLToolSetup.php index 41a955f87..1320c3020 100644 --- a/core/lib/Thelia/Tests/TestCaseWithURLToolSetup.php +++ b/core/lib/Thelia/Tests/TestCaseWithURLToolSetup.php @@ -23,6 +23,9 @@ namespace Thelia\Tests; +use Symfony\Component\Routing\RequestContext; +use Thelia\Tools\URL; + /** * This class provides URL Tool class initialisation * @@ -31,21 +34,22 @@ namespace Thelia\Tests; class TestCaseWithURLToolSetup extends \PHPUnit_Framework_TestCase { private $container = null; + private $dispatcher = null; public function __construct() { $this->container = new \Symfony\Component\DependencyInjection\ContainerBuilder(); - $dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"); + $this->dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"); - $this->container->set("event_dispatcher", $dispatcher); + $this->container->set("event_dispatcher", $this->dispatcher); $this->setupURLTool(); } protected function setupURLTool() { - $context = new \Symfony\Component\Routing\RequestContext( + $context = new RequestContext( '/thelia/index.php', 'GET', 'localhost', @@ -65,11 +69,16 @@ class TestCaseWithURLToolSetup extends \PHPUnit_Framework_TestCase $this->container->set("router.admin", $router); - new \Thelia\Tools\URL($this->container); + new URL($this->container); } public function getContainer() { return $this->container; } + + public function getDispatcher() + { + return $this->dispatcher; + } }