Refactor tests to add abstract class for controller tests

modifié:         core/lib/Thelia/ImportExport/Import/Type/ProductStockImport.php
	renommé:         core/lib/Thelia/Tests/ImportExport/Import/ImportTestBase.php -> core/lib/Thelia/Tests/Controller/ControllerTestBase.php
	nouveau fichier: core/lib/Thelia/Tests/Controller/ImportExportControllerTest.php
	modifié:         core/lib/Thelia/Tests/ImportExport/Import/ProductStockImportTest.php
This commit is contained in:
Benjamin Perche
2014-07-21 09:44:28 +02:00
parent a03d15b5b9
commit a731873ff3
4 changed files with 76 additions and 23 deletions

View File

@@ -0,0 +1,91 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Tests\Controller;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Thelia\Controller\Admin\ImportController;
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarArchiveBuilder;
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarBz2ArchiveBuilder;
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarGzArchiveBuilder;
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\ZipArchiveBuilder;
use Thelia\Core\FileFormat\Archive\ArchiveBuilderManager;
use Thelia\Core\FileFormat\Formatting\Formatter\JsonFormatter;
use Thelia\Core\FileFormat\Formatting\Formatter\XMLFormatter;
use Thelia\Core\FileFormat\Formatting\FormatterManager;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\HttpFoundation\Session\Session;
use Thelia\Core\Translation\Translator;
use Thelia\Log\Tlog;
/**
* Class ControllerTestBase
* @package Thelia\Tests\ImportExport\Import
* @author Benjamin Perche <bperche@openstudio.fr>
*/
abstract class ControllerTestBase extends \PHPUnit_Framework_TestCase
{
protected $import;
protected $container;
protected $session;
/** @var ImportController */
protected $controller;
public function getContainer()
{
$container = new \Symfony\Component\DependencyInjection\ContainerBuilder();
$container->set("thelia.translator", new Translator(new Container()));
$dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
$container->set("event_dispatcher", $dispatcher);
$this->buildContainer($container);
$request = new Request();
$request->setSession($this->session);
$container->set("request", $request);
return $container;
}
public function getSession()
{
return new Session();
}
public function setUp()
{
Tlog::getNewInstance();
$this->session = $this->getSession();
$this->container = $this->getContainer();
$this->controller = $this->getController();
$this->controller->setContainer($this->container);
}
/**
* @return \Thelia\Controller\BaseController The controller you want to test
*/
abstract function getController();
/**
* Use this method to build the container with the services that you need.
*/
abstract function buildContainer(ContainerBuilder $container);
}

View File

@@ -0,0 +1,56 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Tests\Controller;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Thelia\Controller\Admin\ImportController;
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarArchiveBuilder;
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarBz2ArchiveBuilder;
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarGzArchiveBuilder;
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\ZipArchiveBuilder;
use Thelia\Core\FileFormat\Archive\ArchiveBuilderManager;
use Thelia\Core\FileFormat\Formatting\Formatter\CSVFormatter;
use Thelia\Core\FileFormat\Formatting\Formatter\JsonFormatter;
use Thelia\Core\FileFormat\Formatting\Formatter\XMLFormatter;
use Thelia\Core\FileFormat\Formatting\FormatterManager;
/**
* Class ControllerExportControllerTest
* @package Thelia\Tests\Controller
* @author Benjamin Perche <bperche@openstudio.fr>
*/
abstract class ControllerExportControllerTest extends ControllerTestBase
{
/**
* @return mixed
*/
function buildContainer(ContainerBuilder $container)
{
$archiveBuilderManager = (new ArchiveBuilderManager("dev"))
->add(new ZipArchiveBuilder())
->add(new TarArchiveBuilder())
->add(new TarBz2ArchiveBuilder())
->add(new TarGzArchiveBuilder())
;
$container->set("thelia.manager.archive_builder_manager", $archiveBuilderManager);
$formatterManager = (new FormatterManager())
->add(new XMLFormatter())
->add(new JsonFormatter())
->add(new CSVFormatter())
;
$container->set("thelia.manager.formatter_manager", $archiveBuilderManager);
}
}