MagentoComposerApplicationTest.php 2.29 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
<?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

use Composer\Console\Application;
use Magento\Composer\MagentoComposerApplication;
use Magento\Composer\ConsoleArrayInputFactory;
use Symfony\Component\Console\Output\BufferedOutput;

class MagentoComposerApplicationTest extends \PHPUnit\Framework\TestCase
{
    /**
     * @var MagentoComposerApplication
     */
    protected $application;

    /**
     * @var Application|\PHPUnit_Framework_MockObject_MockObject
     */
    protected $composerApplication;

    /**
     * @var ConsoleArrayInputFactory|\PHPUnit_Framework_MockObject_MockObject
     */
    protected $inputFactory;

    /**
     * @var BufferedOutput|\PHPUnit_Framework_MockObject_MockObject
     */
    protected $consoleOutput;

    protected function setUp()
    {
        $this->composerApplication = $this->createMock(\Composer\Console\Application::class);
        $this->inputFactory = $this->createMock(\Magento\Composer\ConsoleArrayInputFactory::class);
        $this->consoleOutput = $this->createMock(\Symfony\Component\Console\Output\BufferedOutput::class);

        $this->application = new MagentoComposerApplication(
            'path1',
            'path2',
            $this->composerApplication,
            $this->inputFactory,
            $this->consoleOutput
        );
    }

    /**
     * @expectedException \RuntimeException
     * @expectedExceptionMessage Command "update" failed
     */
    function testWrongExitCode()
    {
        $this->composerApplication->expects($this->once())->method('run')->willReturn(1);

        $this->application->runComposerCommand(['command'=>'update']);
    }

    function testRunCommand()
    {
        $inputData = ['command' => 'update', MagentoComposerApplication::COMPOSER_WORKING_DIR => '.'];

        $this->composerApplication->expects($this->once())->method('resetComposer');

        $this->inputFactory->expects($this->once())->method('create')->with($inputData);

        $this->consoleOutput->expects($this->once())->method('fetch')->willReturn('Nothing to update');

        $this->composerApplication->expects($this->once())->method('run')->willReturn(0);

        $message = $this->application->runComposerCommand($inputData);
        $this->assertEquals('Nothing to update', $message);
    }
}