diff --git a/Mage/Task/Factory.php b/Mage/Task/Factory.php index 57dff35..db53818 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,11 +27,10 @@ class Factory * * @param string|array $taskData * @param \Mage\Config $taskConfig - * @param Config $taskConfig * @param boolean $inRollback * @param string $stage * @return \Mage\Task\AbstractTask - * @throws \Exception|\Mage\Task\ErrorWithMessageException + * @throws \Exception */ public static function get($taskData, Config $taskConfig, $inRollback = false, $stage = null) { diff --git a/tests/MageTest/Task/FactoryTest.php b/tests/MageTest/Task/FactoryTest.php new file mode 100644 index 0000000..2dfb56b --- /dev/null +++ b/tests/MageTest/Task/FactoryTest.php @@ -0,0 +1,97 @@ +config = $this->getMock('Mage\\Config'); + } + + /** + * @covers Mage\Task\Factory::get + */ + public function testGet() + { + $task = Factory::get('composer/install', $this->config); + $this->assertInstanceOf('\\Mage\\Task\\BuiltIn\\Composer\\InstallTask', $task); + } + + /** + * @covers Mage\Task\Factory::get + */ + public function testGetTaskDataIsArray() + { + $taskData = array( + 'name' => 'composer/install', + 'parameters' => array(), + ); + + $task = Factory::get($taskData, $this->config); + $this->assertInstanceOf('\\Mage\\Task\\BuiltIn\\Composer\\InstallTask', $task); + } + + /** + * @covers Mage\Task\Factory::get + */ + public function testGetCustomTask() + { + $this->getMockBuilder('Mage\\Task\\AbstractTask') + ->setConstructorArgs(array($this->config)) + ->setMockClassName('MyTask') + ->getMock(); + + /* + * current workaround + * @link https://github.com/sebastianbergmann/phpunit-mock-objects/issues/134 + */ + class_alias('MyTask', 'Task\\MyTask'); + + $task = Factory::get('my-task', $this->config); + $this->assertInstanceOf('Task\\MyTask', $task); + } + + /** + * @covers Mage\Task\Factory::get + */ + public function testGetWithOptionalParams() + { + $task = Factory::get('composer/install', $this->config, true, 'production'); + $this->assertInstanceOf('\\Mage\\Task\\BuiltIn\\Composer\\InstallTask', $task); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage The Task MyInconsistentTask must be an instance of Mage\Task\AbstractTask. + * @covers Mage\Task\Factory::get + */ + public function testGetInconsistentException() + { + $this->getMock('Task\\MyInconsistentTask'); + Factory::get('my-inconsistent-task', $this->config); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage Task "Unknowntask" not found. + * @covers Mage\Task\Factory::get + */ + public function testGetClassDoesNotExist() + { + Factory::get('unknowntask', $this->config); + } +}