Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 9 additions & 21 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="true"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="tests/bootstrap.php"
>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="true" backupStaticAttributes="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" bootstrap="tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory>./src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Symfony Flex Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>

<php>
<ini name="error_reporting" value="-1" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
<env name="LC_ALL" value="C" />
<ini name="error_reporting" value="-1"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
<env name="LC_ALL" value="C"/>
</php>

<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
10 changes: 5 additions & 5 deletions src/Command/DumpEnvCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(Config $config, Options $options)
parent::__construct();
}

protected function configure()
protected function configure(): void
{
$this->setName('symfony:dump-env')
->setAliases(['dump-env'])
Expand Down Expand Up @@ -67,13 +67,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$vars = var_export($vars, true);
$vars = <<<EOF
<?php
<?php

// This file was generated by running "composer dump-env $env"
// This file was generated by running "composer dump-env $env"

return $vars;
return $vars;

EOF;
EOF;
file_put_contents($path.'.local.php', $vars, \LOCK_EX);

$this->getIO()->writeError('Successfully dumped .env files in <info>.env.local.php</>');
Expand Down
2 changes: 1 addition & 1 deletion src/Command/InstallRecipesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(/* cannot be type-hinted */ $flex, string $rootDir,
parent::__construct();
}

protected function configure()
protected function configure(): void
{
$this->setName('symfony:recipes:install')
->setAliases(['recipes:install', 'symfony:sync-recipes', 'sync-recipes', 'fix-recipes'])
Expand Down
2 changes: 1 addition & 1 deletion src/Command/RecipesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(/* cannot be type-hinted */ $flex, Lock $symfonyLock
parent::__construct();
}

protected function configure()
protected function configure(): void
{
$this->setName('symfony:recipes')
->setAliases(['recipes'])
Expand Down
2 changes: 1 addition & 1 deletion src/Command/UpdateRecipesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct(/* cannot be type-hinted */ $flex, Downloader $downl
parent::__construct();
}

protected function configure()
protected function configure(): void
{
$this->setName('symfony:recipes:update')
->setAliases(['recipes:update'])
Expand Down
16 changes: 8 additions & 8 deletions src/Configurator/MakefileConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ private function configureMakefile(Recipe $recipe, array $definitions, bool $upd
file_put_contents(
$this->options->get('root-dir').'/Makefile',
<<<EOF
ifndef {$envKey}
include {$dotenvPath}
endif
ifndef {$envKey}
include {$dotenvPath}
endif

.DEFAULT_GOAL := help
.PHONY: help
help:
@awk 'BEGIN {FS = ":.*?## "}; /^[a-zA-Z-]+:.*?## .*$$/ {printf "\033[32m%-15s\033[0m %s\\n", $$1, $$2}' Makefile | sort
.DEFAULT_GOAL := help
.PHONY: help
help:
@awk 'BEGIN {FS = ":.*?## "}; /^[a-zA-Z-]+:.*?## .*$$/ {printf "\033[32m%-15s\033[0m %s\\n", $$1, $$2}' Makefile | sort

EOF
EOF
);
}

Expand Down
9 changes: 5 additions & 4 deletions src/Flex.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,11 @@ class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__)
BasePackage::$stabilities['dev'] = 1 + BasePackage::STABILITY_STABLE;
}

$app->add(new Command\RecipesCommand($this, $this->lock, $rfs));
$app->add(new Command\InstallRecipesCommand($this, $this->options->get('root-dir'), $this->options->get('runtime')['dotenv_path'] ?? '.env'));
$app->add(new Command\UpdateRecipesCommand($this, $this->downloader, $rfs, $this->configurator, $this->options->get('root-dir')));
$app->add(new Command\DumpEnvCommand($this->config, $this->options));
$addCommand = 'add'.(method_exists($app, 'addCommand') ? 'Command' : '');
$app->$addCommand(new Command\RecipesCommand($this, $this->lock, $rfs));
$app->$addCommand(new Command\InstallRecipesCommand($this, $this->options->get('root-dir'), $this->options->get('runtime')['dotenv_path'] ?? '.env'));
$app->$addCommand(new Command\UpdateRecipesCommand($this, $this->downloader, $rfs, $this->configurator, $this->options->get('root-dir')));
$app->$addCommand(new Command\DumpEnvCommand($this->config, $this->options));

break;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Command/DumpEnvCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private function createCommandDumpEnv(array $options = [])
);

$application = new Application();
$application->add($command);
$application->{'add'.(method_exists($application, 'addCommand') ? 'Command' : '')}($command);
$command = $application->find('dump-env');

return new CommandTester($command);
Expand Down
2 changes: 1 addition & 1 deletion tests/Command/InstallRecipesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testCommandFlagsPassedDown()

$command = new InstallRecipesCommand($flex, __DIR__);
$application = new Application();
$application->add($command);
$application->{'add'.(method_exists($application, 'addCommand') ? 'Command' : '')}($command);
$command = $application->find('symfony:recipes:install');

$tester = new CommandTester($command);
Expand Down
2 changes: 1 addition & 1 deletion tests/Command/UpdateRecipesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private function createCommandUpdateRecipes(): CommandTester
$command->setComposer($composer);

$application = new Application();
$application->add($command);
$application->{'add'.(method_exists($application, 'addCommand') ? 'Command' : '')}($command);
$command = $application->find('recipes:update');

return new CommandTester($command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class CopyDirectoryFromPackageConfiguratorTest extends TestCase
private $targetDirectory;
private $io;
private $recipe;
private $composer;

public function testConfigureDirectory()
{
Expand Down
33 changes: 26 additions & 7 deletions tests/Configurator/CopyFromPackageConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CopyFromPackageConfiguratorTest extends TestCase
private $targetDirectory;
private $io;
private $recipe;
private $composer;

public function testNoFilesCopied()
{
Expand All @@ -55,8 +56,8 @@ public function testConfigureAndOverwriteFiles()
file_put_contents($this->targetFile, '-');
$lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock();

$this->io->expects($this->at(0))->method('writeError')->with([' Copying files from package']);
$this->io->expects($this->at(2))->method('writeError')->with([' Created <fg=green>"./public/file"</>']);
$ioCalls = [];
$this->io->method('writeError')->willReturnCallback(static function (array $lines) use (&$ioCalls) { $ioCalls[] = $lines; });
$this->io->method('askConfirmation')->with('File "build/public/file" has uncommitted changes, overwrite? [y/N] ')->willReturn(true);

$this->assertFileExists($this->targetFile);
Expand All @@ -68,6 +69,12 @@ public function testConfigureAndOverwriteFiles()
);
$this->assertFileExists($this->targetFile);
$this->assertFileEquals($this->sourceFile, $this->targetFile);

$expected = [
[' Copying files from package'],
[' Created <fg=green>"./public/file"</>'],
];
$this->assertSame($expected, $ioCalls);
}

public function testSourceFileNotExist()
Expand All @@ -88,20 +95,26 @@ public function testConfigure()
file_put_contents($this->sourceFile, '');
}

$this->io->expects($this->at(0))->method('writeError')->with([' Copying files from package']);
$this->io->expects($this->at(1))->method('writeError')->with([' Created <fg=green>"./public/"</>']);
$this->io->expects($this->at(2))->method('writeError')->with([' Created <fg=green>"./public/file"</>']);
$ioCalls = [];
$this->io->method('writeError')->willReturnCallback(static function (array $lines) use (&$ioCalls) { $ioCalls[] = $lines; });

$this->assertFileDoesNotExist($this->targetFile);
$lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock();
$this->createConfigurator()->configure($this->recipe, [$this->sourceFileRelativePath => $this->targetFileRelativePath], $lock);
$this->assertFileExists($this->targetFile);

$expected = [
[' Copying files from package'],
[' Created <fg=green>"./public/"</>'],
[' Created <fg=green>"./public/file"</>'],
];
$this->assertSame($expected, $ioCalls);
}

public function testUnconfigure()
{
$this->io->expects($this->at(0))->method('writeError')->with([' Removing files from package']);
$this->io->expects($this->at(1))->method('writeError')->with([' Removed <fg=green>"./public/file"</>']);
$ioCalls = [];
$this->io->method('writeError')->willReturnCallback(static function (array $lines) use (&$ioCalls) { $ioCalls[] = $lines; });

if (!file_exists($this->targetDirectory)) {
mkdir($this->targetDirectory);
Expand All @@ -115,6 +128,12 @@ public function testUnconfigure()
$lock
);
$this->assertFileDoesNotExist($this->targetFile);

$expected = [
[' Removing files from package'],
[' Removed <fg=green>"./public/file"</>'],
];
$this->assertSame($expected, $ioCalls);
}

public function testNoFilesRemoved()
Expand Down
30 changes: 24 additions & 6 deletions tests/Configurator/CopyFromRecipeConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public function testConfigureAndOverwriteFiles()
file_put_contents($this->targetFile, '-');
$lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock();

$this->io->expects($this->at(0))->method('writeError')->with([' Copying files from recipe']);
$this->io->expects($this->at(2))->method('writeError')->with([' Created <fg=green>"./config/file"</>']);
$ioCalls = [];
$this->io->method('writeError')->willReturnCallback(static function (array $lines) use (&$ioCalls) { $ioCalls[] = $lines; });
$this->io->method('askConfirmation')->with('File "build/config/file" has uncommitted changes, overwrite? [y/N] ')->willReturn(true);

$this->assertFileExists($this->targetFile);
Expand All @@ -79,12 +79,18 @@ public function testConfigureAndOverwriteFiles()
);
$this->assertFileExists($this->targetFile);
$this->assertSame('somecontent', file_get_contents($this->targetFile));

$expected = [
[' Copying files from recipe'],
[' Created <fg=green>"./config/file"</>'],
];
$this->assertSame($expected, $ioCalls);
}

public function testConfigure()
{
$this->io->expects($this->at(0))->method('writeError')->with([' Copying files from recipe']);
$this->io->expects($this->at(1))->method('writeError')->with([' Created <fg=green>"./config/file"</>']);
$ioCalls = [];
$this->io->method('writeError')->willReturnCallback(static function (array $lines) use (&$ioCalls) { $ioCalls[] = $lines; });

$this->assertFileDoesNotExist($this->targetFile);
$lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock();
Expand All @@ -94,6 +100,12 @@ public function testConfigure()
$lock
);
$this->assertFileExists($this->targetFile);

$expected = [
[' Copying files from recipe'],
[' Created <fg=green>"./config/file"</>'],
];
$this->assertSame($expected, $ioCalls);
}

public function testUnconfigureKeepsLockedFiles()
Expand All @@ -119,8 +131,8 @@ public function testUnconfigureKeepsLockedFiles()

public function testUnconfigure()
{
$this->io->expects($this->at(0))->method('writeError')->with([' Removing files from recipe']);
$this->io->expects($this->at(1))->method('writeError')->with([' Removed <fg=green>"./config/file"</>']);
$ioCalls = [];
$this->io->method('writeError')->willReturnCallback(static function (array $lines) use (&$ioCalls) { $ioCalls[] = $lines; });

if (!file_exists($this->targetDirectory)) {
@mkdir($this->targetDirectory, 0777, true);
Expand All @@ -131,6 +143,12 @@ public function testUnconfigure()
$this->recipe->method('getName')->willReturn('test-recipe');
$this->createConfigurator()->unconfigure($this->recipe, [$this->targetFileRelativePath], $lock);
$this->assertFileDoesNotExist($this->targetFile);

$expected = [
[' Removing files from recipe'],
[' Removed <fg=green>"./config/file"</>'],
];
$this->assertSame($expected, $ioCalls);
}

public function testNoFilesRemoved()
Expand Down
11 changes: 4 additions & 7 deletions tests/FlexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,10 @@ public function testPostInstall()
$this->assertSame(
<<<EOF

Symfony operations: 1 recipe ()
- Configuring dummy/dummy (>=1.0): From github.com/symfony/recipes:main
Symfony operations: 1 recipe ()
- Configuring dummy/dummy (>=1.0): From github.com/symfony/recipes:main

EOF
,
EOF,
str_replace("\r\n", "\n", $io->getOutput())
);
}
Expand Down Expand Up @@ -506,15 +505,13 @@ private function mockManager(): RepositoryManager

private function mockFlexCustom(BufferIO $io, Composer $composer, Configurator $configurator, Downloader $downloader, Lock $lock): Flex
{
return \Closure::bind(function () use ($composer, $io, $configurator, $downloader, $lock) {
return \Closure::bind(static function () use ($composer, $io, $configurator, $downloader, $lock) {
$flex = new Flex();
$flex->composer = $composer;
$flex->config = $composer->getConfig();
$flex->io = $io;
$flex->configurator = $configurator;
$flex->downloader = $downloader;
$flex->runningCommand = function () {
};
$flex->options = new Options(['config-dir' => 'config', 'var-dir' => 'var', 'root-dir' => '.']);
$flex->lock = $lock;

Expand Down
Loading