Merge pull request #176 from claudioflagbit/task-factory-test

Task factory test
This commit is contained in:
Kuba Turek 2015-03-24 20:27:11 +01:00
commit 288d7304be
2 changed files with 99 additions and 2 deletions

View file

@ -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)
{

View file

@ -0,0 +1,97 @@
<?php
namespace MageTest\Task;
use Mage\Task\Factory;
use PHPUnit_Framework_TestCase;
/**
* @group MageTest_Task_Factory
* @group MageTest_Task
* @group issue-176
*
* @uses Mage\Task\AbstractTask
* @coversDefaultClass Mage\Task\Factory
*/
class FactoryTest extends PHPUnit_Framework_TestCase
{
private $config;
protected function setUp()
{
$this->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);
}
}