Skip to content
Open
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
20 changes: 11 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ on:
pull_request:
push:
branches:
- '1.x'
- '2.x'

env:
SYMFONY_PHPUNIT_DIR: "$HOME/symfony-bridge/.phpunit"

jobs:
tests:
name: "PHP ${{ matrix.php }} ${{ matrix.mode }}"
Expand All @@ -22,7 +18,9 @@ jobs:
include:
- php: '8.1'
composer: 2.1.x
phpunit: 10
- php: '8.2'
phpunit: 11
- php: '8.3'
- php: '8.4'
- php: '8.5'
Expand Down Expand Up @@ -50,14 +48,18 @@ jobs:

- name: "Install dependencies"
run: |
if [[ -n "${{ matrix.phpunit }}" ]]; then
composer r --dev --no-update phpunit/phpunit:^${{ matrix.phpunit }} --ansi
fi
if [[ "${{ matrix.phpunit }}" = 10 ]]; then
sed -i 's/ *ignoreIndirectDeprecations="true"//g' phpunit.xml.dist
fi

if [[ "${{ matrix.mode }}" = low-deps ]]; then
composer u --prefer-lowest --prefer-stable --ansi
composer u symfony/phpunit-bridge
else
composer u --ansi
fi

- name: "Install PHPUnit"
run: vendor/bin/simple-phpunit install

- run: vendor/bin/simple-phpunit
- name: "Run tests"
run: vendor/bin/phpunit
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/vendor/
/build/
.phpunit.result.cache
/.phpunit.cache
.php_cs.cache
composer.lock
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
},
"require-dev": {
"composer/composer": "^2.1",
"phpunit/phpunit": "^12.4",
"symfony/dotenv": "^6.4|^7.4|^8.0",
"symfony/filesystem": "^6.4|^7.4|^8.0",
"symfony/phpunit-bridge": "^6.4|^7.4|^8.0",
"symfony/process": "^6.4|^7.4|^8.0"
},
"conflict": {
Expand Down
8 changes: 3 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="true" colors="true" failOnNotice="true" failOnWarning="true" bootstrap="tests/bootstrap.php" xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" cacheDirectory=".phpunit.cache">
<source ignoreIndirectDeprecations="true">
<include>
<directory>./src/</directory>
</include>
</coverage>
</source>
<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"/>
</php>
</phpunit>
8 changes: 6 additions & 2 deletions src/Configurator/DockerComposeConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ private function configureDockerCompose(Recipe $recipe, array $config, bool $upd
}

// Keep end in memory (check break line on previous line)
$endAt[$node] = !$i || '' !== trim($lines[$i - 1]) ? $i : $i - 1;
if (null !== $node) {
$endAt[$node] = !$i || '' !== trim($lines[$i - 1]) ? $i : $i - 1;
}
$node = $matches[1];
if (!isset($nodesLines[$node])) {
$nodesLines[$node] = [];
Expand All @@ -285,7 +287,9 @@ private function configureDockerCompose(Recipe $recipe, array $config, bool $upd
$startAt[$node] = $i + 1;
}
}
$endAt[$node] = \count($lines) + 1;
if (null !== $node) {
$endAt[$node] = \count($lines) + 1;
}

foreach ($extra as $key => $value) {
if (isset($endAt[$key])) {
Expand Down
10 changes: 4 additions & 6 deletions tests/Command/DumpEnvCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use Composer\Config;
use Composer\Console\Application;
use PHPUnit\Framework\Attributes\BackupGlobals;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Flex\Command\DumpEnvCommand;
Expand Down Expand Up @@ -82,9 +84,7 @@ public function testEmptyOptionMustIgnoreContent()
unlink($envLocal);
}

/**
* @backupGlobals enabled
*/
#[BackupGlobals(true)]
public function testEnvCanBeReferenced()
{
@mkdir(FLEX_TEST_DIR);
Expand Down Expand Up @@ -164,9 +164,7 @@ public function testDoesNotRequireToSpecifyEnvArgumentWhenLocalFileIsPresent()
unlink($envLocalPhp);
}

/**
* @runInSeparateProcess
*/
#[RunInSeparateProcess]
public function testLoadLocalEnvWhenTestEnvIsNotEqual()
{
@mkdir(FLEX_TEST_DIR);
Expand Down
6 changes: 0 additions & 6 deletions tests/Command/UpdateRecipesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ protected function tearDown(): void
$filesystem->remove(FLEX_TEST_DIR);
}

/**
* Skip 7.1, simply because there isn't a newer recipe version available
* that we can easily use to assert.
*
* @requires PHP >= 7.2
*/
public function testCommandUpdatesRecipe()
{
@mkdir(FLEX_TEST_DIR);
Expand Down
13 changes: 5 additions & 8 deletions tests/Configurator/AddLinesConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Composer\Package\Package;
use Composer\Repository\InstalledRepositoryInterface;
use Composer\Repository\RepositoryManager;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Flex\Configurator\AddLinesConfigurator;
Expand Down Expand Up @@ -395,9 +396,7 @@ public function testLineProcessedIfRequiredPackageVersionIsRight()
);
}

/**
* @dataProvider getUnconfigureTests
*/
#[DataProvider('getUnconfigureTests')]
public function testUnconfigure(string $originalContents, string $value, string $expectedContents)
{
$this->saveFile('assets/app.js', $originalContents);
Expand Down Expand Up @@ -434,7 +433,7 @@ public function testExpandTargetDirWhenUnconfiguring()
);
}

public function getUnconfigureTests()
public static function getUnconfigureTests()
{
yield 'found_middle' => [
<<<JS
Expand Down Expand Up @@ -515,9 +514,7 @@ public function getUnconfigureTests()
];
}

/**
* @dataProvider getUpdateTests
*/
#[DataProvider('getUpdateTests')]
public function testUpdate(array $originalFiles, array $originalConfig, array $newConfig, array $expectedFiles)
{
foreach ($originalFiles as $filename => $originalContents) {
Expand All @@ -541,7 +538,7 @@ public function testUpdate(array $originalFiles, array $originalConfig, array $n
}
}

public function getUpdateTests()
public static function getUpdateTests()
{
$appJsOriginal = <<<JS
import * as Turbo from '@hotwired/turbo';
Expand Down
15 changes: 6 additions & 9 deletions tests/Configurator/ComposerCommandConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Util\Platform;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Flex\Configurator\ComposerCommandsConfigurator;
use Symfony\Flex\Lock;
Expand Down Expand Up @@ -44,10 +45,8 @@ protected function tearDown(): void
}
}

/**
* @dataProvider providerForConfigureMethod
*/
public function testConfigure($composerSchema, string $expectedComposerJson): void
#[DataProvider('providerForConfigureMethod')]
public function testConfigure($composerSchema, string $expectedComposerJson)
{
file_put_contents(FLEX_TEST_DIR.'/composer.json', json_encode($composerSchema, \JSON_PRETTY_PRINT));

Expand Down Expand Up @@ -132,10 +131,8 @@ public static function providerForConfigureMethod(): iterable
];
}

/**
* @dataProvider providerForUnconfigureMethod
*/
public function testUnconfigure($composerSchema, string $expectedComposerJson): void
#[DataProvider('providerForUnconfigureMethod')]
public function testUnconfigure($composerSchema, string $expectedComposerJson)
{
file_put_contents(FLEX_TEST_DIR.'/composer.json', json_encode($composerSchema, \JSON_PRETTY_PRINT));

Expand Down Expand Up @@ -210,7 +207,7 @@ public static function providerForUnconfigureMethod(): iterable
];
}

public function testUpdate(): void
public function testUpdate()
{
$configurator = new ComposerCommandsConfigurator(
$this->createMock(Composer::class),
Expand Down
13 changes: 6 additions & 7 deletions tests/Configurator/CopyDirectoryFromPackageConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Composer\Installer\InstallationManager;
use Composer\IO\IOInterface;
use Composer\Package\PackageInterface;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Flex\Configurator\CopyFromPackageConfigurator;
use Symfony\Flex\Lock;
Expand Down Expand Up @@ -57,9 +58,7 @@ public function testConfigureDirectory()
}
}

/**
* @dataProvider providerTestConfigureDirectoryWithExistingFiles
*/
#[DataProvider('providerTestConfigureDirectoryWithExistingFiles')]
public function testConfigureDirectoryWithExistingFiles(bool $force, string $sourceFileContent, string $existingTargetFileContent, string $expectedFinalTargetFileContent)
{
if (!is_dir($this->sourceDirectory)) {
Expand Down Expand Up @@ -93,7 +92,7 @@ public function testConfigureDirectoryWithExistingFiles(bool $force, string $sou
}
}

public function providerTestConfigureDirectoryWithExistingFiles(): array
public static function providerTestConfigureDirectoryWithExistingFiles(): array
{
return [
[true, 'NEW_CONTENT', 'OLD_CONTENT', 'NEW_CONTENT'],
Expand Down Expand Up @@ -166,16 +165,16 @@ protected function setUp(): void

$package = $this->getMockBuilder(PackageInterface::class)->getMock();
$this->recipe = $this->getMockBuilder(Recipe::class)->disableOriginalConstructor()->getMock();
$this->recipe->expects($this->exactly(1))->method('getPackage')->willReturn($package);
$this->recipe->expects($this->once())->method('getPackage')->willReturn($package);

$installationManager = $this->getMockBuilder(InstallationManager::class)->disableOriginalConstructor()->getMock();
$installationManager->expects($this->exactly(1))
$installationManager->expects($this->once())
->method('getInstallPath')
->with($package)
->willReturn(FLEX_TEST_DIR)
;
$this->composer = $this->getMockBuilder(Composer::class)->getMock();
$this->composer->expects($this->exactly(1))
$this->composer->expects($this->once())
->method('getInstallationManager')
->willReturn($installationManager)
;
Expand Down
10 changes: 5 additions & 5 deletions tests/Configurator/CopyFromPackageConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testNoFilesCopied()
mkdir($this->targetDirectory);
}
file_put_contents($this->targetFile, '');
$this->io->expects($this->exactly(1))->method('writeError')->with([' Copying files from package']);
$this->io->expects($this->once())->method('writeError')->with([' Copying files from package']);
$lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock();
$this->createConfigurator()->configure($this->recipe, [$this->sourceFileRelativePath => $this->targetFileRelativePath], $lock);
}
Expand Down Expand Up @@ -139,7 +139,7 @@ public function testUnconfigure()
public function testNoFilesRemoved()
{
$this->assertFileDoesNotExist($this->targetFile);
$this->io->expects($this->exactly(1))->method('writeError')->with([' Removing files from package']);
$this->io->expects($this->once())->method('writeError')->with([' Removing files from package']);
$lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock();
$this->createConfigurator()->unconfigure($this->recipe, [$this->sourceFileRelativePath => $this->targetFileRelativePath], $lock);
}
Expand All @@ -160,16 +160,16 @@ protected function setUp(): void

$package = $this->getMockBuilder(PackageInterface::class)->getMock();
$this->recipe = $this->getMockBuilder(Recipe::class)->disableOriginalConstructor()->getMock();
$this->recipe->expects($this->exactly(1))->method('getPackage')->willReturn($package);
$this->recipe->expects($this->once())->method('getPackage')->willReturn($package);

$installationManager = $this->getMockBuilder(InstallationManager::class)->disableOriginalConstructor()->getMock();
$installationManager->expects($this->exactly(1))
$installationManager->expects($this->once())
->method('getInstallPath')
->with($package)
->willReturn(FLEX_TEST_DIR)
;
$this->composer = $this->getMockBuilder(Composer::class)->getMock();
$this->composer->expects($this->exactly(1))
$this->composer->expects($this->once())
->method('getInstallationManager')
->willReturn($installationManager)
;
Expand Down
4 changes: 2 additions & 2 deletions tests/Configurator/CopyFromRecipeConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testNoFilesCopied()
@mkdir($this->targetDirectory, 0777, true);
}
file_put_contents($this->targetFile, '');
$this->io->expects($this->exactly(1))->method('writeError')->with([' Copying files from recipe']);
$this->io->expects($this->once())->method('writeError')->with([' Copying files from recipe']);
$lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock();
$this->createConfigurator()->configure($this->recipe, [$this->sourceFileRelativePath => $this->targetFileRelativePath], $lock);
}
Expand Down Expand Up @@ -154,7 +154,7 @@ public function testUnconfigure()
public function testNoFilesRemoved()
{
$this->assertFileDoesNotExist($this->targetFile);
$this->io->expects($this->exactly(1))->method('writeError')->with([' Removing files from recipe']);
$this->io->expects($this->once())->method('writeError')->with([' Removing files from recipe']);
$lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock();
$this->createConfigurator()->unconfigure($this->recipe, [$this->sourceFileRelativePath => $this->targetFileRelativePath], $lock);
}
Expand Down
11 changes: 4 additions & 7 deletions tests/Configurator/DockerComposeConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Package\RootPackage;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Flex\Configurator\DockerComposeConfigurator;
Expand Down Expand Up @@ -185,9 +186,7 @@ public static function dockerComposerFileProvider(): iterable
yield ['docker-compose.yml'];
}

/**
* @dataProvider dockerComposerFileProvider
*/
#[DataProvider('dockerComposerFileProvider')]
public function testConfigure(string $fileName)
{
$dockerComposeFile = FLEX_TEST_DIR."/$fileName";
Expand Down Expand Up @@ -232,9 +231,7 @@ public function testNotConfiguredIfConfigSet()
$this->assertFileDoesNotExist(FLEX_TEST_DIR.'/docker-compose.yaml');
}

/**
* @dataProvider getInteractiveDockerPreferenceTests
*/
#[DataProvider('getInteractiveDockerPreferenceTests')]
public function testPreferenceAskedInteractively(string $userInput, bool $expectedIsConfigured, bool $expectedIsComposerJsonUpdated)
{
$composerJsonPath = FLEX_TEST_DIR.'/composer.json';
Expand Down Expand Up @@ -262,7 +259,7 @@ public function testPreferenceAskedInteractively(string $userInput, bool $expect
}
}

public function getInteractiveDockerPreferenceTests()
public static function getInteractiveDockerPreferenceTests()
{
yield 'yes_once' => ['y', true, false];
yield 'no_once' => ['n', false, false];
Expand Down
Loading