GenerateFixturesCommandTest.php 1.79 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
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\Setup\Test\Unit\Console\Command;

use Magento\Setup\Fixtures\FixtureModel;
use Magento\Setup\Console\Command\GenerateFixturesCommand;
use Symfony\Component\Console\Tester\CommandTester;

class GenerateFixturesCommandTest extends \PHPUnit\Framework\TestCase
{
    /**
     * @var FixtureModel|\PHPUnit_Framework_MockObject_MockObject
     */
    private $fixtureModel;

    /**
     * @var GenerateFixturesCommand|\PHPUnit_Framework_MockObject_MockObject
     */
    private $command;

    public function setUp()
    {
        $this->fixtureModel = $this->createMock(\Magento\Setup\Fixtures\FixtureModel::class);
        $this->command = new GenerateFixturesCommand($this->fixtureModel);
    }

    public function testExecute()
    {
        $this->fixtureModel->expects($this->once())->method('loadConfig')->with('path_to_profile.xml');
        $this->fixtureModel->expects($this->once())->method('initObjectManager');
        $this->fixtureModel->expects($this->once())->method('loadFixtures');

        $commandTester = new CommandTester($this->command);
        $commandTester->execute(['profile' => 'path_to_profile.xml']);
    }

    /**
     * @expectedException \RuntimeException
     * @expectedExceptionMessage Not enough arguments
     */
    public function testExecuteInvalidLanguageArgument()
    {

        $commandTester = new CommandTester($this->command);
        $commandTester->execute([]);
    }

    public function testSkipReindexOption()
    {
        $this->fixtureModel->expects($this->never())->method('reindex');

        $commandTester = new CommandTester($this->command);
        $commandTester->execute(['profile' => 'path_to_profile.xml', '--skip-reindex' => true]);
    }
}