From 2c27e2c46d394ff7a60ff9bc09e6dd51ee057dfe Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Mon, 5 Jan 2015 13:31:14 +0100 Subject: [PATCH] unittests for task factory and dummy task classes for tests created --- Mage/Task/Factory.php | 2 +- tests/Dummies/Task/MyInconsistentTask.php | 27 ++++++++ tests/Dummies/Task/MyTask.php | 36 ++++++++++ tests/MageTest/Task/FactoryTest.php | 83 +++++++++++++++++++++++ 4 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 tests/Dummies/Task/MyInconsistentTask.php create mode 100644 tests/Dummies/Task/MyTask.php create mode 100644 tests/MageTest/Task/FactoryTest.php diff --git a/Mage/Task/Factory.php b/Mage/Task/Factory.php index 57dff35..e177f6b 100644 --- a/Mage/Task/Factory.php +++ b/Mage/Task/Factory.php @@ -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 diff --git a/tests/Dummies/Task/MyInconsistentTask.php b/tests/Dummies/Task/MyInconsistentTask.php new file mode 100644 index 0000000..93d3cb7 --- /dev/null +++ b/tests/Dummies/Task/MyInconsistentTask.php @@ -0,0 +1,27 @@ +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'), + ); + } +} + \ No newline at end of file