mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 00:50:18 +01:00 
			
		
		
		
	Add CompileCommand tests
This commit is contained in:
		
							parent
							
								
									ee8bb3c2f9
								
							
						
					
					
						commit
						5602bf83fe
					
				@ -28,7 +28,7 @@ class CompileCommand extends AbstractCommand
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function __construct()
 | 
					    public function __construct()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->compiler = new Compiler();
 | 
					        $this->setCompiler(new Compiler());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function setCompiler(Compiler $compiler)
 | 
					    public function setCompiler(Compiler $compiler)
 | 
				
			||||||
@ -46,8 +46,7 @@ class CompileCommand extends AbstractCommand
 | 
				
			|||||||
            return 200;
 | 
					            return 200;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $compiler = new Compiler;
 | 
					        $this->compiler->compile();
 | 
				
			||||||
        $compiler->compile();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Console::output('<light_purple>mage.phar</light_purple> compiled <light_green>successfully</light_green>', 0, 2);
 | 
					        Console::output('<light_purple>mage.phar</light_purple> compiled <light_green>successfully</light_green>', 0, 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -4,12 +4,20 @@ namespace MageTest\Command\BuiltIn;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
use Mage\Command\BuiltIn\CompileCommand;
 | 
					use Mage\Command\BuiltIn\CompileCommand;
 | 
				
			||||||
use MageTest\TestHelper\BaseTest;
 | 
					use MageTest\TestHelper\BaseTest;
 | 
				
			||||||
 | 
					use malkusch\phpmock\FixedValueFunction;
 | 
				
			||||||
 | 
					use malkusch\phpmock\Mock;
 | 
				
			||||||
 | 
					use malkusch\phpmock\MockBuilder;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Class CompileCommandTest
 | 
					 * Class CompileCommandTest
 | 
				
			||||||
 * @package MageTest\Command\BuiltIn
 | 
					 * @package MageTest\Command\BuiltIn
 | 
				
			||||||
 * @coversDefaultClass Mage\Command\BuiltIn\CompileCommand
 | 
					 * @coversDefaultClass Mage\Command\BuiltIn\CompileCommand
 | 
				
			||||||
 * @uses Mage\Compiler
 | 
					 * @uses Mage\Compiler
 | 
				
			||||||
 | 
					 * @uses malkusch\phpmock\FixedValueFunction
 | 
				
			||||||
 | 
					 * @uses malkusch\phpmock\Mock
 | 
				
			||||||
 | 
					 * @uses malkusch\phpmock\MockBuilder
 | 
				
			||||||
 | 
					 * @uses Mage\Console
 | 
				
			||||||
 | 
					 * @uses Mage\Console\Colors
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class CompileCommandTest extends BaseTest
 | 
					class CompileCommandTest extends BaseTest
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -18,26 +26,48 @@ class CompileCommandTest extends BaseTest
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    private $compileCommand;
 | 
					    private $compileCommand;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @var FixedValueFunction
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private $iniGetValue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @var Mock
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private $iniGetMock;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @before
 | 
					     * @before
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function before()
 | 
					    public function before()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->compileCommand = new CompileCommand();
 | 
					        $this->compileCommand = new CompileCommand();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->iniGetValue = new FixedValueFunction();
 | 
				
			||||||
 | 
					        $mockBuilder = new MockBuilder();
 | 
				
			||||||
 | 
					        $this->iniGetMock = $mockBuilder->setNamespace('Mage\Command\BuiltIn')
 | 
				
			||||||
 | 
					            ->setName("ini_get")
 | 
				
			||||||
 | 
					            ->setCallableProvider($this->iniGetValue)
 | 
				
			||||||
 | 
					            ->build();
 | 
				
			||||||
 | 
					        $this->iniGetMock->disable();
 | 
				
			||||||
 | 
					        $this->iniGetMock->enable();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->setUpConsoleStatics();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @covers ::__construct
 | 
					     * @covers ::__construct
 | 
				
			||||||
 | 
					     * @covers ::setCompiler
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function testConstruct()
 | 
					    public function testConstruct()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $compileCommand = new CompileCommand();
 | 
					        $compilerProperty = $this->getPropertyValue($this->compileCommand, 'compiler');
 | 
				
			||||||
 | 
					 | 
				
			||||||
        $compilerProperty = $this->getPropertyValue($compileCommand, 'compiler');
 | 
					 | 
				
			||||||
        $this->assertInstanceOf('Mage\Compiler', $compilerProperty);
 | 
					        $this->assertInstanceOf('Mage\Compiler', $compilerProperty);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
					     * @covers ::__construct
 | 
				
			||||||
     * @covers ::setCompiler
 | 
					     * @covers ::setCompiler
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function testSetCompiler()
 | 
					    public function testSetCompiler()
 | 
				
			||||||
@ -48,4 +78,43 @@ class CompileCommandTest extends BaseTest
 | 
				
			|||||||
        $compilerProperty = $this->getPropertyValue($this->compileCommand, 'compiler');
 | 
					        $compilerProperty = $this->getPropertyValue($this->compileCommand, 'compiler');
 | 
				
			||||||
        $this->assertEquals($compilerMock, $compilerProperty);
 | 
					        $this->assertEquals($compilerMock, $compilerProperty);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @covers ::__construct
 | 
				
			||||||
 | 
					     * @covers ::setCompiler
 | 
				
			||||||
 | 
					     * @covers ::run
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function testRun()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $expectedOutput = "mage.phar compiled successfully\n\n";
 | 
				
			||||||
 | 
					        $expectedExitCode = 0;
 | 
				
			||||||
 | 
					        $this->expectOutputString($expectedOutput);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $compilerMock = $this->getMock('Mage\Compiler');
 | 
				
			||||||
 | 
					        $compilerMock->expects($this->once())
 | 
				
			||||||
 | 
					            ->method('compile');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->iniGetValue->setValue(false);
 | 
				
			||||||
 | 
					        $this->compileCommand->setCompiler($compilerMock);
 | 
				
			||||||
 | 
					        $actualExitCode = $this->compileCommand->run();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertEquals($expectedExitCode, $actualExitCode);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @covers ::__construct
 | 
				
			||||||
 | 
					     * @covers ::setCompiler
 | 
				
			||||||
 | 
					     * @covers ::run
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function testRunWhenPharReadonlyEnabled()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $expectedOutput = "\tThe php.ini variable phar.readonly must be Off.\n\n";
 | 
				
			||||||
 | 
					        $expectedExitCode = 200;
 | 
				
			||||||
 | 
					        $this->expectOutputString($expectedOutput);
 | 
				
			||||||
 | 
					        $this->iniGetValue->setValue(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $actualExitCode = $this->compileCommand->run();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertEquals($expectedExitCode, $actualExitCode);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user