Skip to content

Upgrade to PHP 8.1 & PHPUnit 10 #1056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
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
17 changes: 4 additions & 13 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ name: "CI"
on:
pull_request:
push:
branches:
- '1.x'
- '2.x'

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

jobs:
tests:
Expand All @@ -20,9 +14,8 @@ jobs:
fail-fast: false
matrix:
include:
- php: '8.0'
composer: 2.2.x
- php: '8.1'
composer: 2.2.x
- php: '8.2'
- php: '8.3'
- php: '8.4'
Expand All @@ -40,7 +33,7 @@ jobs:
php-version: ${{ matrix.php }}
tools: composer:${{ matrix.composer }}

- if: matrix.php == '8.0'
- if: matrix.php == '8.1'
name: "Lint PHP files"
run: |
find src/ -name '*.php' | xargs -n1 php -l
Expand All @@ -57,7 +50,5 @@ jobs:
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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
],
"minimum-stability": "dev",
"require": {
"php": ">=8.0",
"php": ">=8.1",
"composer-plugin-api": "^2.1"
},
"require-dev": {
"composer/composer": "^2.1",
"phpunit/phpunit": "^10.5",
"symfony/dotenv": "^5.4|^6.0",
"symfony/filesystem": "^5.4|^6.0",
"symfony/phpunit-bridge": "^5.4|^6.0",
"symfony/process": "^5.4|^6.0"
},
"conflict": {
Expand Down
38 changes: 15 additions & 23 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="true"
backupStaticAttributes="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="true"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
failOnNotice="true"
failOnWarning="true"
bootstrap="tests/bootstrap.php"
cacheDirectory=".phpunit.cache"
>
<testsuites>
<testsuite name="Symfony Flex Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
<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>

<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
<php>
<ini name="error_reporting" value="-1" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
</php>
</phpunit>
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 @@ -321,9 +322,7 @@ public function testLineProcessedIfRequiredPackageIsPresent()
$actualContents);
}

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

public function getUnconfigureTests()
public static function getUnconfigureTests()
{
yield 'found_middle' => [
<<<EOF
Expand Down Expand Up @@ -446,9 +445,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 @@ -472,7 +469,7 @@ public function testUpdate(array $originalFiles, array $originalConfig, array $n
}
}

public function getUpdateTests()
public static function getUpdateTests()
{
$appJsOriginal = <<<EOF
import * as Turbo from '@hotwired/turbo';
Expand Down
9 changes: 3 additions & 6 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,9 +45,7 @@ protected function tearDown(): void
}
}

/**
* @dataProvider providerForConfigureMethod
*/
#[DataProvider('providerForConfigureMethod')]
public function testConfigure($composerSchema, string $expectedComposerJson): void
{
file_put_contents(FLEX_TEST_DIR.'/composer.json', json_encode($composerSchema, \JSON_PRETTY_PRINT));
Expand Down Expand Up @@ -132,9 +131,7 @@ public static function providerForConfigureMethod(): iterable
];
}

/**
* @dataProvider providerForUnconfigureMethod
*/
#[DataProvider('providerForUnconfigureMethod')]
public function testUnconfigure($composerSchema, string $expectedComposerJson): void
{
file_put_contents(FLEX_TEST_DIR.'/composer.json', json_encode($composerSchema, \JSON_PRETTY_PRINT));
Expand Down
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 All @@ -32,6 +33,7 @@ class CopyDirectoryFromPackageConfiguratorTest extends TestCase
private $targetDirectory;
private $io;
private $recipe;
private $composer;

public function testConfigureDirectory()
{
Expand All @@ -56,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 @@ -92,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
32 changes: 24 additions & 8 deletions tests/Configurator/CopyFromPackageConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ class CopyFromPackageConfiguratorTest extends TestCase
private $targetDirectory;
private $io;
private $recipe;
private $composer;

public function testNoFilesCopied()
{
if (!file_exists($this->targetDirectory)) {
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 All @@ -55,8 +56,13 @@ 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"</>']);
$expectedMessages = [
' Copying files from package',
' Created <fg=green>"./public/file"</>',
];
$this->io->expects($this->exactly(2))->method('writeError')->willReturnCallback(function ($message) use (&$expectedMessages) {
$this->assertSame([array_shift($expectedMessages)], $message);
});
$this->io->method('askConfirmation')->with('File "build/public/file" has uncommitted changes, overwrite? [y/N] ')->willReturn(true);

$this->assertFileExists($this->targetFile);
Expand Down Expand Up @@ -88,9 +94,14 @@ 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"</>']);
$expectedMessages = [
' Copying files from package',
' Created <fg=green>"./public/"</>',
' Created <fg=green>"./public/file"</>',
];
$this->io->expects($this->exactly(3))->method('writeError')->willReturnCallback(function ($message) use (&$expectedMessages) {
$this->assertSame([array_shift($expectedMessages)], $message);
});

$this->assertFileDoesNotExist($this->targetFile);
$lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock();
Expand All @@ -100,8 +111,13 @@ public function testConfigure()

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"</>']);
$expectedMessages = [
' Removing files from package',
' Removed <fg=green>"./public/file"</>',
];
$this->io->expects($this->exactly(2))->method('writeError')->willReturnCallback(function ($message) use (&$expectedMessages) {
$this->assertSame([array_shift($expectedMessages)], $message);
});

if (!file_exists($this->targetDirectory)) {
mkdir($this->targetDirectory);
Expand Down
27 changes: 21 additions & 6 deletions tests/Configurator/CopyFromRecipeConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,13 @@ 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"</>']);
$expectedMessages = [
' Copying files from recipe',
' Created <fg=green>"./config/file"</>',
];
$this->io->expects($this->exactly(2))->method('writeError')->willReturnCallback(function ($message) use (&$expectedMessages) {
$this->assertSame([array_shift($expectedMessages)], $message);
});
$this->io->method('askConfirmation')->with('File "build/config/file" has uncommitted changes, overwrite? [y/N] ')->willReturn(true);

$this->assertFileExists($this->targetFile);
Expand All @@ -83,8 +88,13 @@ public function testConfigureAndOverwriteFiles()

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"</>']);
$expectedMessages = [
' Copying files from recipe',
' Created <fg=green>"./config/file"</>',
];
$this->io->expects($this->exactly(2))->method('writeError')->willReturnCallback(function ($message) use (&$expectedMessages) {
$this->assertSame([array_shift($expectedMessages)], $message);
});

$this->assertFileDoesNotExist($this->targetFile);
$lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock();
Expand Down Expand Up @@ -119,8 +129,13 @@ 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"</>']);
$expectedMessages = [
' Removing files from recipe',
' Removed <fg=green>"./config/file"</>',
];
$this->io->expects($this->exactly(2))->method('writeError')->willReturnCallback(function ($message) use (&$expectedMessages) {
$this->assertSame([array_shift($expectedMessages)], $message);
});

if (!file_exists($this->targetDirectory)) {
@mkdir($this->targetDirectory, 0777, true);
Expand Down
Loading