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
|
<?php
namespace Illuminate\Tests\Support;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Composer;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Process;
class SupportComposerTest extends TestCase
{
protected function tearDown(): void
{
m::close();
}
public function testDumpAutoloadRunsTheCorrectCommand()
{
$composer = $this->mockComposer(['composer', 'dump-autoload']);
$composer->dumpAutoloads();
}
public function testDumpAutoloadRunsTheCorrectCommandWhenCustomComposerPharIsPresent()
{
$escape = '\\' === DIRECTORY_SEPARATOR ? '"' : '\'';
$expectedProcessArguments = [$escape.PHP_BINARY.$escape, 'composer.phar', 'dump-autoload'];
$customComposerPhar = true;
$composer = $this->mockComposer($expectedProcessArguments, $customComposerPhar);
$composer->dumpAutoloads();
}
public function testDumpAutoloadRunsTheCorrectCommandWithExtraArguments()
{
$composer = $this->mockComposer(['composer', 'dump-autoload', '--no-scripts']);
$composer->dumpAutoloads('--no-scripts');
}
public function testDumpOptimizedTheCorrectCommand()
{
$composer = $this->mockComposer(['composer', 'dump-autoload', '--optimize']);
$composer->dumpOptimized();
}
private function mockComposer(array $expectedProcessArguments, $customComposerPhar = false)
{
$directory = __DIR__;
$files = m::mock(Filesystem::class);
$files->shouldReceive('exists')->once()->with($directory.'/composer.phar')->andReturn($customComposerPhar);
$process = m::mock(Process::class);
$process->shouldReceive('run')->once();
$composer = $this->getMockBuilder(Composer::class)
->setMethods(['getProcess'])
->setConstructorArgs([$files, $directory])
->getMock();
$composer->expects($this->once())
->method('getProcess')
->with($expectedProcessArguments)
->willReturn($process);
return $composer;
}
}
|