mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 00:50:18 +01:00 
			
		
		
		
	tests for command factory created
This commit is contained in:
		
							parent
							
								
									5e43c4e044
								
							
						
					
					
						commit
						5b63f4b5d0
					
				@ -43,14 +43,17 @@ class Factory
 | 
			
		||||
            // try a custom command
 | 
			
		||||
            $className = 'Command\\' . $commandName;
 | 
			
		||||
 | 
			
		||||
            // TODO use a custom exception
 | 
			
		||||
            if (!class_exists($className)) {
 | 
			
		||||
                throw new Exception('Command "' . $commandName . '" not found.');
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /** @var AbstractCommand $instance */
 | 
			
		||||
        // TODO dependencies like $config should be injected into constructor
 | 
			
		||||
        $instance = new $className;
 | 
			
		||||
        if (! $instance instanceOf AbstractCommand) {
 | 
			
		||||
            // TODO use a custom exception
 | 
			
		||||
            throw new Exception('The command ' . $commandName . ' must be an instance of Mage\Command\AbstractCommand.');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										55
									
								
								tests/MageTest/Command/FactoryTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								tests/MageTest/Command/FactoryTest.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,55 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace MageTest\Command;
 | 
			
		||||
 | 
			
		||||
use Mage\Command\Factory;
 | 
			
		||||
use PHPUnit_Framework_TestCase;
 | 
			
		||||
use PHPUnit_Framework_Constraint_IsInstanceOf;
 | 
			
		||||
 | 
			
		||||
require_once(__DIR__ . '/../../Dummies/Command/MyCommand.php');
 | 
			
		||||
require_once(__DIR__ . '/../../Dummies/Command/MyInconsistentCommand.php');
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @group Mage_Command
 | 
			
		||||
 * @group Mage_Command_Factory
 | 
			
		||||
 *
 | 
			
		||||
 * @todo test case for naming convention
 | 
			
		||||
 */
 | 
			
		||||
class FactoryTest extends PHPUnit_Framework_TestCase
 | 
			
		||||
{
 | 
			
		||||
    private $config;
 | 
			
		||||
 | 
			
		||||
    protected function setUp()
 | 
			
		||||
    {
 | 
			
		||||
        $this->config = $this->getMock('Mage\Config');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGet()
 | 
			
		||||
    {
 | 
			
		||||
        $command = Factory::get('add', $this->config);
 | 
			
		||||
        $this->assertInstanceOf('Mage\\Command\\BuiltIn\\AddCommand', $command);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @expectedException \Exception
 | 
			
		||||
     */
 | 
			
		||||
    public function testGetClassNotFoundException()
 | 
			
		||||
    {
 | 
			
		||||
        $command = Factory::get('commanddoesntexist', $this->config);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testGetCustomCommand()
 | 
			
		||||
    {
 | 
			
		||||
        $command = Factory::get('my-command', $this->config);
 | 
			
		||||
        $this->assertInstanceOf('Command\\MyCommand', $command);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @expectedException \Exception
 | 
			
		||||
     * @expectedExceptionMessage The command MyInconsistentCommand must be an instance of Mage\Command\AbstractCommand.
 | 
			
		||||
     */
 | 
			
		||||
    public function testGetInconsistencyException()
 | 
			
		||||
    {
 | 
			
		||||
        $command = Factory::get('my-inconsistent-command', $this->config);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user