mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-10-31 23:30:18 +01:00 
			
		
		
		
	Merge pull request #176 from claudioflagbit/task-factory-test
Task factory test
This commit is contained in:
		
						commit
						288d7304be
					
				| @ -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,11 +27,10 @@ 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 | ||||||
|      * @throws \Exception|\Mage\Task\ErrorWithMessageException |      * @throws \Exception | ||||||
|      */ |      */ | ||||||
|     public static function get($taskData, Config $taskConfig, $inRollback = false, $stage = null) |     public static function get($taskData, Config $taskConfig, $inRollback = false, $stage = null) | ||||||
|     { |     { | ||||||
|  | |||||||
							
								
								
									
										97
									
								
								tests/MageTest/Task/FactoryTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								tests/MageTest/Task/FactoryTest.php
									
									
									
									
									
										Normal 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); | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user