magallanes/tests/MageTest/Task/FactoryTest.php

92 lines
2.2 KiB
PHP
Raw Normal View History

<?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);
}
/**
* @dataProvider taskDataProvider
*/
2015-01-05 14:28:37 +01:00
public function testGetWithOptionalParams($taskData)
{
2015-01-05 14:28:37 +01:00
$task = Factory::get($taskData, $this->config, true, 'production');
$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 "Unknowntask" not found.
*/
public function testGetClassDoesNotExist()
{
Factory::get('unknowntask', $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'),
);
}
}