unittests for task factory and dummy task classes for tests created

This commit is contained in:
Claudio Zizza 2015-01-05 13:31:14 +01:00 committed by Claudio Zizza
parent 0406c7de8a
commit 2c27e2c46d
4 changed files with 147 additions and 1 deletions

View file

@ -11,6 +11,7 @@
namespace Mage\Task;
use Mage\Config;
use Mage\Task\AbstractTask;
use Exception;
@ -26,7 +27,6 @@ class Factory
*
* @param string|array $taskData
* @param \Mage\Config $taskConfig
* @param Config $taskConfig
* @param boolean $inRollback
* @param string $stage
* @return \Mage\Task\AbstractTask

View file

@ -0,0 +1,27 @@
<?php
namespace Task;
class MyInconsistentTask
{
/**
* Returns the Title of the Task
*
* @return string
*/
public function getName()
{
return 'my task';
}
/**
* Runs the task
*
* @return boolean
*/
public function run()
{
return true;
}
}

View file

@ -0,0 +1,36 @@
<?php
namespace Task;
use Exception;
use Mage\Task\AbstractTask;
use Mage\Task\ErrorWithMessageException;
use Mage\Task\SkipException;
class MyTask extends AbstractTask
{
/**
* Returns the Title of the Task
*
* @return string
*/
public function getName()
{
return 'my task';
}
/**
* Runs the task
*
* @return boolean
* @throws Exception
* @throws ErrorWithMessageException
* @throws SkipException
*/
public function run()
{
return true;
}
}

View file

@ -0,0 +1,83 @@
<?php
namespace MageTest\Task;
use Mage\Task\Factory;
use PHPUnit_Framework_TestCase;
require_once(__DIR__ . '/../../Dummies/Task/MyTask.php');
require_once(__DIR__ . '/../../Dummies/Task/MyInconsistentTask.php');
/**
* @group MageTest_Task
* @group MageTest_Task_Factory
*/
class FactoryTest extends PHPUnit_Framework_TestCase
{
private $config;
protected function setUp()
{
$this->config = $this->getMock('Mage\Config');
}
/**
* @dataProvider taskDataProvider
*/
public function testGet($taskData)
{
$task = Factory::get($taskData, $this->config);
$this->assertInstanceOf('\\Mage\\Task\\AbstractTask', $task);
}
/**
* @expectedException \Exception
* @expectedExceptionMessage The Task MyInconsistentTask must be an instance of Mage\Task\AbstractTask.
*/
public function testGetInconsistentException()
{
Factory::get('my-inconsistent-task', $this->config);
}
/**
* @expectedException \Exception
* @expectedExceptionMessage Task "Notknowntask" not found.
*/
public function testGetClassDoesNotExist()
{
Factory::get('notknowntask', $this->config);
}
/**
* Only build in tasks contains a slash
*
* @return array
*/
public function taskDataProvider()
{
return array(
array(
array(
'name' => 'my-task',
'parameters' => array(),
)
),
array('my-task'),
array(
array(
'name' => 'composer/install',
'parameters' => array(),
)
),
array('composer/install'),
array(
array(
'name' => 'magento/clear-cache',
'parameters' => array(),
)
),
array('magento/clear-cache'),
);
}
}