Fixed URL class initialization proble in Unit Test
This commit is contained in:
@@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
namespace Thelia\Tests\Action;
|
namespace Thelia\Tests\Action;
|
||||||
|
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Symfony\Component\Routing\Router;
|
||||||
use Thelia\Action\Category;
|
use Thelia\Action\Category;
|
||||||
use Thelia\Core\Event\Category\CategoryDeleteEvent;
|
use Thelia\Core\Event\Category\CategoryDeleteEvent;
|
||||||
use Thelia\Core\Event\Category\CategoryUpdateEvent;
|
use Thelia\Core\Event\Category\CategoryUpdateEvent;
|
||||||
@@ -30,6 +32,7 @@ use Thelia\Core\Event\UpdateSeoEvent;
|
|||||||
use Thelia\Model\Category as CategoryModel;
|
use Thelia\Model\Category as CategoryModel;
|
||||||
use Thelia\Core\Event\Category\CategoryCreateEvent;
|
use Thelia\Core\Event\Category\CategoryCreateEvent;
|
||||||
use Thelia\Model\CategoryQuery;
|
use Thelia\Model\CategoryQuery;
|
||||||
|
use Thelia\Tests\TestCaseWithURLToolSetup;
|
||||||
use Thelia\Tools\URL;
|
use Thelia\Tools\URL;
|
||||||
|
|
||||||
|
|
||||||
@@ -38,19 +41,8 @@ use Thelia\Tools\URL;
|
|||||||
* @package Thelia\Tests\Action
|
* @package Thelia\Tests\Action
|
||||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||||
*/
|
*/
|
||||||
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()
|
protected function getRandomCategory()
|
||||||
{
|
{
|
||||||
@@ -81,7 +73,7 @@ class CategoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
->setPostscriptum('bar postscriptum')
|
->setPostscriptum('bar postscriptum')
|
||||||
->setVisible(0)
|
->setVisible(0)
|
||||||
->setParent(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 = new UpdateSeoEvent($category->getId());
|
||||||
$event->setDispatcher($this->dispatcher);
|
$event->setDispatcher($this->getDispatcher());
|
||||||
$event
|
$event
|
||||||
->setLocale($category->getLocale())
|
->setLocale($category->getLocale())
|
||||||
->setMetaTitle($category->getMetaTitle())
|
->setMetaTitle($category->getMetaTitle())
|
||||||
@@ -127,7 +119,7 @@ class CategoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
->setParent(0)
|
->setParent(0)
|
||||||
->setTitle('foo')
|
->setTitle('foo')
|
||||||
->setVisible(1)
|
->setVisible(1)
|
||||||
->setDispatcher($this->dispatcher);
|
->setDispatcher($this->getDispatcher());
|
||||||
|
|
||||||
$action = new Category();
|
$action = new Category();
|
||||||
$action->create($event);
|
$action->create($event);
|
||||||
@@ -165,7 +157,7 @@ class CategoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
->setPostscriptum('bar postscriptum')
|
->setPostscriptum('bar postscriptum')
|
||||||
->setVisible(0)
|
->setVisible(0)
|
||||||
->setParent(0)
|
->setParent(0)
|
||||||
->setDispatcher($this->dispatcher)
|
->setDispatcher($this->getDispatcher())
|
||||||
;
|
;
|
||||||
|
|
||||||
$action = new Category();
|
$action = new Category();
|
||||||
@@ -192,7 +184,7 @@ class CategoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testDelete(CategoryModel $category)
|
public function testDelete(CategoryModel $category)
|
||||||
{
|
{
|
||||||
$event = new CategoryDeleteEvent($category->getId());
|
$event = new CategoryDeleteEvent($category->getId());
|
||||||
$event->setDispatcher($this->dispatcher);
|
$event->setDispatcher($this->getDispatcher());
|
||||||
|
|
||||||
$action = new Category();
|
$action = new Category();
|
||||||
$action->delete($event);
|
$action->delete($event);
|
||||||
@@ -201,8 +193,5 @@ class CategoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertInstanceOf('Thelia\Model\Category', $deletedCategory);
|
$this->assertInstanceOf('Thelia\Model\Category', $deletedCategory);
|
||||||
$this->assertTrue($deletedCategory->isDeleted());
|
$this->assertTrue($deletedCategory->isDeleted());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -23,6 +23,9 @@
|
|||||||
|
|
||||||
namespace Thelia\Tests;
|
namespace Thelia\Tests;
|
||||||
|
|
||||||
|
use Symfony\Component\Routing\RequestContext;
|
||||||
|
use Thelia\Tools\URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides URL Tool class initialisation
|
* This class provides URL Tool class initialisation
|
||||||
*
|
*
|
||||||
@@ -31,21 +34,22 @@ namespace Thelia\Tests;
|
|||||||
class TestCaseWithURLToolSetup extends \PHPUnit_Framework_TestCase
|
class TestCaseWithURLToolSetup extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
private $container = null;
|
private $container = null;
|
||||||
|
private $dispatcher = null;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->container = new \Symfony\Component\DependencyInjection\ContainerBuilder();
|
$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();
|
$this->setupURLTool();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setupURLTool()
|
protected function setupURLTool()
|
||||||
{
|
{
|
||||||
$context = new \Symfony\Component\Routing\RequestContext(
|
$context = new RequestContext(
|
||||||
'/thelia/index.php',
|
'/thelia/index.php',
|
||||||
'GET',
|
'GET',
|
||||||
'localhost',
|
'localhost',
|
||||||
@@ -65,11 +69,16 @@ class TestCaseWithURLToolSetup extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->container->set("router.admin", $router);
|
$this->container->set("router.admin", $router);
|
||||||
|
|
||||||
new \Thelia\Tools\URL($this->container);
|
new URL($this->container);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getContainer()
|
public function getContainer()
|
||||||
{
|
{
|
||||||
return $this->container;
|
return $this->container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDispatcher()
|
||||||
|
{
|
||||||
|
return $this->dispatcher;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user