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:
@@ -19,7 +19,7 @@ use Thelia\ImportExport\Import\ImportHandler;
|
|||||||
use Thelia\Model\ProductSaleElementsQuery;
|
use Thelia\Model\ProductSaleElementsQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ImportTestBase
|
* Class ControllerTestBase
|
||||||
* @package Thelia\ImportExport\Import
|
* @package Thelia\ImportExport\Import
|
||||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -10,8 +10,9 @@
|
|||||||
/* file that was distributed with this source code. */
|
/* file that was distributed with this source code. */
|
||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
|
|
||||||
namespace Thelia\Tests\ImportExport\Import;
|
namespace Thelia\Tests\Controller;
|
||||||
use Symfony\Component\DependencyInjection\Container;
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Thelia\Controller\Admin\ImportController;
|
use Thelia\Controller\Admin\ImportController;
|
||||||
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarArchiveBuilder;
|
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarArchiveBuilder;
|
||||||
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarBz2ArchiveBuilder;
|
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarBz2ArchiveBuilder;
|
||||||
@@ -27,11 +28,11 @@ use Thelia\Core\Translation\Translator;
|
|||||||
use Thelia\Log\Tlog;
|
use Thelia\Log\Tlog;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ImportTestBase
|
* Class ControllerTestBase
|
||||||
* @package Thelia\Tests\ImportExport\Import
|
* @package Thelia\Tests\ImportExport\Import
|
||||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||||
*/
|
*/
|
||||||
class ImportTestBase extends \PHPUnit_Framework_TestCase
|
abstract class ControllerTestBase extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
protected $import;
|
protected $import;
|
||||||
|
|
||||||
@@ -50,20 +51,7 @@ class ImportTestBase extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$container->set("event_dispatcher", $dispatcher);
|
$container->set("event_dispatcher", $dispatcher);
|
||||||
|
|
||||||
$archiveBuilderManager = (new ArchiveBuilderManager("dev"))
|
$this->buildContainer($container);
|
||||||
->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())
|
|
||||||
;
|
|
||||||
|
|
||||||
$container->set("thelia.manager.formatter_manager", $archiveBuilderManager);
|
|
||||||
|
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
$request->setSession($this->session);
|
$request->setSession($this->session);
|
||||||
@@ -85,9 +73,19 @@ class ImportTestBase extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->session = $this->getSession();
|
$this->session = $this->getSession();
|
||||||
$this->container = $this->getContainer();
|
$this->container = $this->getContainer();
|
||||||
$this->controller = new ImportController();
|
$this->controller = $this->getController();
|
||||||
$this->controller->setContainer($this->container);
|
$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);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -14,15 +14,14 @@ namespace Thelia\Tests\ImportExport\Import;
|
|||||||
use Thelia\Core\FileFormat\Formatting\Formatter\JsonFormatter;
|
use Thelia\Core\FileFormat\Formatting\Formatter\JsonFormatter;
|
||||||
use Thelia\ImportExport\Import\Type\ProductStockImport;
|
use Thelia\ImportExport\Import\Type\ProductStockImport;
|
||||||
use Thelia\Model\ProductSaleElementsQuery;
|
use Thelia\Model\ProductSaleElementsQuery;
|
||||||
|
use Thelia\Tests\Controller\ControllerTestBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ProductStockImportTest
|
* Class ProductStockControllerTest
|
||||||
* @package Thelia\Tests\ImportExport\Import
|
* @package Thelia\Tests\ImportExport\Import
|
||||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||||
*
|
|
||||||
* This class tests the import controller too
|
|
||||||
*/
|
*/
|
||||||
class ProductStockImportTest extends ImportTestBase
|
class ProductStockControllerTest extends ControllerTestBase
|
||||||
{
|
{
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user