2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2019-06-13 18:51:27 +00:00
|
|
|
|
2019-07-29 14:43:24 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2019-06-13 18:51:27 +00:00
|
|
|
|
|
|
|
namespace Composer\Test\Script;
|
|
|
|
|
|
|
|
use Composer\Composer;
|
|
|
|
use Composer\Config;
|
|
|
|
use Composer\Script\Event;
|
|
|
|
use Composer\Test\TestCase;
|
|
|
|
|
2019-07-29 14:43:24 +00:00
|
|
|
class EventTest extends TestCase
|
|
|
|
{
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testEventSetsOriginatingEvent(): void
|
2019-07-29 14:43:24 +00:00
|
|
|
{
|
|
|
|
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
|
|
|
$composer = $this->createComposerInstance();
|
|
|
|
|
|
|
|
$originatingEvent = new \Composer\EventDispatcher\Event('originatingEvent');
|
|
|
|
|
|
|
|
$scriptEvent = new Event('test', $composer, $io, true);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertNull(
|
2019-07-29 14:43:24 +00:00
|
|
|
$scriptEvent->getOriginatingEvent(),
|
|
|
|
'originatingEvent is initialized as null'
|
|
|
|
);
|
|
|
|
|
|
|
|
$scriptEvent->setOriginatingEvent($originatingEvent);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(
|
2019-07-29 14:43:24 +00:00
|
|
|
$originatingEvent,
|
|
|
|
$scriptEvent->getOriginatingEvent(),
|
|
|
|
'getOriginatingEvent() SHOULD return test event'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testEventCalculatesNestedOriginatingEvent(): void
|
2019-07-29 14:43:24 +00:00
|
|
|
{
|
|
|
|
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
|
|
|
$composer = $this->createComposerInstance();
|
|
|
|
|
|
|
|
$originatingEvent = new \Composer\EventDispatcher\Event('upperOriginatingEvent');
|
|
|
|
$intermediateEvent = new Event('intermediate', $composer, $io, true);
|
|
|
|
$intermediateEvent->setOriginatingEvent($originatingEvent);
|
|
|
|
|
|
|
|
$scriptEvent = new Event('test', $composer, $io, true);
|
|
|
|
$scriptEvent->setOriginatingEvent($intermediateEvent);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertNotSame(
|
2019-07-29 14:43:24 +00:00
|
|
|
$intermediateEvent,
|
|
|
|
$scriptEvent->getOriginatingEvent(),
|
|
|
|
'getOriginatingEvent() SHOULD NOT return intermediate events'
|
|
|
|
);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(
|
2019-07-29 14:43:24 +00:00
|
|
|
$originatingEvent,
|
|
|
|
$scriptEvent->getOriginatingEvent(),
|
|
|
|
'getOriginatingEvent() SHOULD return upper-most event'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-02-18 10:22:01 +00:00
|
|
|
private function createComposerInstance(): Composer
|
2019-07-29 14:43:24 +00:00
|
|
|
{
|
|
|
|
$composer = new Composer;
|
|
|
|
$config = new Config;
|
|
|
|
$composer->setConfig($config);
|
|
|
|
$package = $this->getMockBuilder('Composer\Package\RootPackageInterface')->getMock();
|
|
|
|
$composer->setPackage($package);
|
|
|
|
|
|
|
|
return $composer;
|
|
|
|
}
|
|
|
|
}
|