mirror of
https://github.com/andres-montanez/Magallanes
synced 2024-06-16 04:25:06 +02:00
unittests for task factory and dummy task classes for tests created
This commit is contained in:
parent
0406c7de8a
commit
2c27e2c46d
|
@ -11,6 +11,7 @@
|
||||||
namespace Mage\Task;
|
namespace Mage\Task;
|
||||||
|
|
||||||
use Mage\Config;
|
use Mage\Config;
|
||||||
|
use Mage\Task\AbstractTask;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
|
@ -26,7 +27,6 @@ class Factory
|
||||||
*
|
*
|
||||||
* @param string|array $taskData
|
* @param string|array $taskData
|
||||||
* @param \Mage\Config $taskConfig
|
* @param \Mage\Config $taskConfig
|
||||||
* @param Config $taskConfig
|
|
||||||
* @param boolean $inRollback
|
* @param boolean $inRollback
|
||||||
* @param string $stage
|
* @param string $stage
|
||||||
* @return \Mage\Task\AbstractTask
|
* @return \Mage\Task\AbstractTask
|
||||||
|
|
27
tests/Dummies/Task/MyInconsistentTask.php
Normal file
27
tests/Dummies/Task/MyInconsistentTask.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
36
tests/Dummies/Task/MyTask.php
Normal file
36
tests/Dummies/Task/MyTask.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
83
tests/MageTest/Task/FactoryTest.php
Normal file
83
tests/MageTest/Task/FactoryTest.php
Normal 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'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue