1
0
Fork 0
composer/tests/Composer/Test/Command/RunScriptCommandTest.php

112 lines
3.2 KiB
PHP
Raw Normal View History

2016-07-21 22:20:56 +00:00
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Test\Command;
use Composer\Composer;
use Composer\Config;
use Composer\Script\Event as ScriptEvent;
use Composer\Test\TestCase;
2016-07-21 22:20:56 +00:00
class RunScriptCommandTest extends TestCase
{
/**
* @dataProvider getDevOptions
* @param bool $dev
* @param bool $noDev
*/
public function testDetectAndPassDevModeToEventAndToDispatching($dev, $noDev): void
2016-07-21 22:20:56 +00:00
{
$scriptName = 'testScript';
$input = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock();
2016-07-21 22:20:56 +00:00
$input
->method('getOption')
->will($this->returnValueMap(array(
array('list', false),
array('dev', $dev),
array('no-dev', $noDev),
)));
$input
->method('getArgument')
->will($this->returnValueMap(array(
array('script', $scriptName),
array('args', array()),
)));
$input
->method('hasArgument')
->with('command')
->willReturn(false);
$input
->method('isInteractive')
->willReturn(false);
2016-07-21 22:20:56 +00:00
$output = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')->getMock();
2016-07-21 22:20:56 +00:00
$expectedDevMode = $dev || !$noDev;
$ed = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')
->disableOriginalConstructor()
->getMock();
$ed->expects($this->once())
->method('hasEventListeners')
->with($this->callback(function (ScriptEvent $event) use ($scriptName, $expectedDevMode) {
return $event->getName() === $scriptName
&& $event->isDevMode() === $expectedDevMode;
}))
->willReturn(true);
$ed->expects($this->once())
->method('dispatchScript')
2020-02-07 22:21:48 +00:00
->with($scriptName, $expectedDevMode, array())
->willReturn(0);
2016-07-21 22:20:56 +00:00
$composer = $this->createComposerInstance();
$composer->setEventDispatcher($ed);
$command = $this->getMockBuilder('Composer\Command\RunScriptCommand')
->onlyMethods(array(
2016-07-21 22:20:56 +00:00
'mergeApplicationDefinition',
'getSynopsis',
'initialize',
'requireComposer',
2016-07-21 22:20:56 +00:00
))
->getMock();
$command->expects($this->any())->method('requireComposer')->willReturn($composer);
2016-07-21 22:20:56 +00:00
$command->run($input, $output);
}
2021-10-26 19:05:03 +00:00
/** @return bool[][] **/
public function getDevOptions(): array
2016-07-21 22:20:56 +00:00
{
return array(
array(true, true),
array(true, false),
array(false, true),
array(false, false),
);
}
2021-10-26 19:05:03 +00:00
/** @return Composer **/
private function createComposerInstance(): Composer
2016-07-21 22:20:56 +00:00
{
$composer = new Composer;
2017-03-08 14:07:29 +00:00
$config = new Config;
2016-07-21 22:20:56 +00:00
$composer->setConfig($config);
return $composer;
}
}