Skip to content

Commit

Permalink
Upgrade dependencies + code for 8.1 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
veewee committed Nov 26, 2021
1 parent 2d906ce commit 44ee028
Show file tree
Hide file tree
Showing 22 changed files with 101 additions and 82 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/grumphp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest, macos-latest] #windows-latest currently not working
php-versions: ['7.3', '7.4', '8.0']
php-versions: ['8.0', '8.1']
composer-options: ['', '--prefer-lowest']
composer-versions: ['composer:v1', 'composer:v2']
composer-versions: ['composer:v2']
fail-fast: false
name: PHP ${{ matrix.php-versions }} @ ${{ matrix.operating-system }} with ${{ matrix.composer-versions }} ${{ matrix.composer-options }}
steps:
Expand All @@ -36,7 +36,11 @@ jobs:
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
if: matrix.php-versions != '8.1'
run: composer update --prefer-dist --no-progress --no-suggest ${{ matrix.composer-options }}
- name: Install dependencies (Ignore platform)
if: matrix.php-versions == '8.1'
run: composer update --prefer-dist --no-progress --no-suggest ${{ matrix.composer-options }} --ignore-platform-req=php
- name: Set git variables
run: |
git config --global user.email "[email protected]"
Expand All @@ -47,3 +51,4 @@ jobs:
- name: Run the tests on unix
if: runner.os != 'Windows'
run: php vendor/bin/grumphp run --no-interaction
continue-on-error: ${{ matrix.php-versions == '8.1' && matrix.composer-options == '--prefer-lowest' }}
17 changes: 7 additions & 10 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ shallow_clone: false
platform:
- x64

matrix:
allow_failures:
- php_version: 8.0
#matrix:
# allow_failures:
# - php_version: 8.1

environment:
matrix:
- dependencies: highest
php_version: 7.3
- dependencies: highest
php_version: 7.4.3 # OpenSSL issue will be resolved in 7.4.6
php_version: 8.1
- dependencies: highest
php_version: 8.0

Expand All @@ -33,13 +31,12 @@ cache:

init:
- ps: $Env:php_directory = $Env:php_root_directory + '\' + $Env:php_version
# TODO: This is a workaround for https://github.com/chocolatey/choco/issues/1843. Once this is fixed we
# should go back to latest version in appveyor saving ourselves test time
- ps: choco install chocolatey -y --version 0.10.13 --allow-downgrade
- ps: $Env:exact_php_version = (((choco search php --exact --all --limit-output | Select-String -pattern $Env:php_version) -replace '[php|]', '') | %{ New-Object System.Version $_ } | Sort-Object | Select-Object -Last 1).ToString()
- ps: $Env:PATH = $Env:php_directory + ';' + $Env:composer_directory + ';' + $Env:PATH
- ps: $Env:COMPOSER_NO_INTERACTION = 1
- ps: $Env:ANSICON = '121x90 (121x90)'
- ps: $Env:AMP_DEBUG = '1'

install:
# Install PHP
Expand Down Expand Up @@ -68,8 +65,8 @@ install:

# Install dependencies
- ps: cd $Env:project_directory
- IF %dependencies%==lowest composer update --prefer-dist --prefer-lowest --prefer-stable --no-progress --no-scripts --no-suggest --profile
- IF %dependencies%==highest composer update --prefer-dist --no-progress --no-scripts --no-suggest --profile
- IF %dependencies%==lowest composer update --prefer-dist --prefer-lowest --prefer-stable --no-progress --no-scripts --no-suggest --profile --ignore-platform-req=php
- IF %dependencies%==highest composer update --prefer-dist --no-progress --no-scripts --no-suggest --profile --ignore-platform-req=php
- git config --global user.email "[email protected]"
- git config --global user.name "GrumPHP"

Expand Down
46 changes: 23 additions & 23 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,38 @@
}
],
"require": {
"php": "^7.3 || ^8.0",
"php": "^8.0",
"ext-json": "*",
"composer-plugin-api": "~1.0 || ~2.0",
"amphp/amp": "^2.4",
"composer-plugin-api": "~2.0",
"amphp/amp": "^2.6",
"amphp/parallel": "^1.4",
"amphp/parallel-functions": "^1.0",
"doctrine/collections": "^1.6.7",
"gitonomy/gitlib": "^1.0.3",
"monolog/monolog": "~1.16 || ^2.0",
"ondram/ci-detector": "^3.5 || ^4.0",
"opis/closure": "^3.5",
"psr/container": "^1.0",
"seld/jsonlint": "~1.1",
"symfony/config": "~4.4 || ~5.0",
"symfony/console": "~4.4 || ~5.0",
"symfony/dependency-injection": "~4.4 || ~5.0",
"symfony/dotenv": "~4.4 || ~5.0",
"symfony/event-dispatcher": "~4.4 || ~5.0",
"symfony/filesystem": "~4.4 || ~5.0",
"symfony/finder": "~4.4 || ~5.0",
"symfony/options-resolver": "~4.4 || ~5.0",
"symfony/process": "~4.4 || ~5.0",
"symfony/yaml": "~4.4 || ~5.0"
"doctrine/collections": "^1.6.8",
"gitonomy/gitlib": "^1.3",
"monolog/monolog": "^2.0",
"ondram/ci-detector": "^4.0",
"opis/closure": "^3.6",
"psr/container": "^1.1",
"seld/jsonlint": "~1.8",
"symfony/config": "~5.3 || ~6.0",
"symfony/console": "~5.3 || ~6.0",
"symfony/dependency-injection": "~5.3 || ~6.0",
"symfony/dotenv": "~5.3 || ~6.0",
"symfony/event-dispatcher": "~5.3 || ~6.0",
"symfony/filesystem": "~5.3 || ~6.0",
"symfony/finder": "~5.3 || ~6.0",
"symfony/options-resolver": "~5.3 || ~6.0",
"symfony/process": "~5.3 || ~6.0",
"symfony/yaml": "~5.3 || ~6.0"
},
"require-dev": {
"brianium/paratest": "^6.3",
"composer/composer": "^1.10.22 || ^2.0.13",
"nikic/php-parser": "~4.0",
"composer/composer": "^2.1.8",
"nikic/php-parser": "~4.13",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpspec/phpspec": "^7.1",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^9.5.10"
},
"suggest": {
"atoum/atoum": "Lets GrumPHP run your unit tests.",
Expand Down
8 changes: 4 additions & 4 deletions phive.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="psalm" version="^4.10.0" installed="4.10.0" location="./tools/psalm" copy="true"/>
<phar name="phpcs" version="^3.5.5" installed="3.6.0" location="./tools/phpcs" copy="true"/>
<phar name="phpcbf" version="^3.5.5" installed="3.6.0" location="./tools/phpcbf" copy="true"/>
<phar name="composer-normalize" version="^2.6.1" installed="2.15.0" location="./tools/composer-normalize" copy="true"/>
<phar name="psalm" version="^4.13.1" installed="4.13.1" location="./tools/psalm" copy="true"/>
<phar name="phpcs" version="^3.6.1" installed="3.6.1" location="./tools/phpcs" copy="true"/>
<phar name="phpcbf" version="^3.6.1" installed="3.6.1" location="./tools/phpcbf" copy="true"/>
<phar name="composer-normalize" version="^2.16.0" installed="2.16.0" location="./tools/composer-normalize" copy="true"/>
</phive>
1 change: 1 addition & 0 deletions resources/config/util.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ services:
'7.3': '2021-12-06 23:59:59'
'7.4': '2022-11-28 23:59:59'
'8.0': '2023-11-26 23:59:59'
'8.1': '2024-11-25 23:59:59'
1 change: 1 addition & 0 deletions spec/Parser/Php/Context/ParserContextSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ParserContextSpec extends ObjectBehavior
{
function let(SplFileInfo $file, ParseErrorsCollection $errors)
{
$file->beConstructedWith(['somefile']);
$this->beConstructedWith($file, $errors);
}

Expand Down
1 change: 1 addition & 0 deletions spec/Parser/Php/PhpParserSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function it_parses_a_file(NodeTraverser $traverser, Filesystem $filesystem)

function it_catches_parse_exceptions(Parser $parser, Filesystem $filesystem, SplFileInfo $file)
{
$file->beConstructedWith(['somefile']);
$file->getRealPath()->willReturn('a real path');

$filesystem->readFromFileInfo($file)->willReturn('file content');
Expand Down
36 changes: 18 additions & 18 deletions src/Collection/FilesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
use Traversable;

/**
* @extends ArrayCollection<int, \SplFileInfo>
* @extends ArrayCollection<array-key, \SplFileInfo>
*/
class FilesCollection extends ArrayCollection implements \Serializable
class FilesCollection extends ArrayCollection
{
/**
* Adds a rule that files must match.
Expand Down Expand Up @@ -47,7 +47,7 @@ public function names(array $patterns): self
{
$filter = new Iterator\FilenameFilterIterator($this->getIterator(), $patterns, []);

return new self(iterator_to_array($filter));
return new self([...$filter]);
}

/**
Expand All @@ -63,7 +63,7 @@ public function notName(string $pattern): self
{
$filter = new Iterator\FilenameFilterIterator($this->getIterator(), [], [$pattern]);

return new self(iterator_to_array($filter));
return new self([...$filter]);
}

/**
Expand All @@ -85,7 +85,7 @@ public function paths(array $patterns): self
{
$filter = new Iterator\PathFilterIterator($this->getIterator(), $patterns, []);

return new self(iterator_to_array($filter));
return new self([...$filter]);
}

/**
Expand All @@ -111,7 +111,7 @@ public function notPaths(array $pattern): self
{
$filter = new Iterator\PathFilterIterator($this->getIterator(), [], $pattern);

return new self(iterator_to_array($filter));
return new self([...$filter]);
}

public function extensions(array $extensions): self
Expand Down Expand Up @@ -139,7 +139,7 @@ public function size(string $size): self
$comparator = new Comparator\NumberComparator($size);
$filter = new Iterator\SizeRangeFilterIterator($this->getIterator(), [$comparator]);

return new self(iterator_to_array($filter));
return new self([...$filter]);
}

/**
Expand All @@ -161,7 +161,7 @@ public function date(string $date): self
$comparator = new Comparator\DateComparator($date);
$filter = new Iterator\DateRangeFilterIterator($this->getIterator(), [$comparator]);

return new self(iterator_to_array($filter));
return new self([...$filter]);
}

/**
Expand All @@ -182,14 +182,14 @@ public function filter(Closure $p): self
{
$filter = new Iterator\CustomFilterIterator($this->getIterator(), [$p]);

return new self(iterator_to_array($filter));
return new self([...$filter]);
}

public function filterByFileList(Traversable $fileList): FilesCollection
{
$allowedFiles = array_map(function (SplFileInfo $file) {
return $file->getPathname();
}, iterator_to_array($fileList));
}, [...$fileList]);

return $this->filter(function (SplFileInfo $file) use ($allowedFiles) {
return \in_array($file->getPathname(), $allowedFiles, true);
Expand All @@ -216,26 +216,26 @@ public function ignoreSymlinks(): FilesCollection
});
}

/*
/**
* SplFileInfo cannot be serialized. Therefor, we help PHP a bit.
* This stuff is used for running tasks in parallel.
*/
public function serialize(): string
public function __serialize(): array
{
return serialize($this->map(function (SplFileInfo $fileInfo): string {
return $this->map(function (SplFileInfo $fileInfo): string {
return $fileInfo instanceof SymfonySplFileInfo
? $fileInfo->getRelativePathname()
: $fileInfo->getPathname();
})->toArray());
})->toArray();
}

/*
/**
* SplFileInfo cannot be serialized. Therefor, we help PHP a bit.
* This stuff is used for running tasks in parallel.
*/
public function unserialize($serialized): void
public function __unserialize(array $data): void
{
$files = unserialize($serialized, ['allowed_classes' => false]);
$files = $data;
$this->clear();
foreach ($files as $file) {
$this->add(new SymfonySplFileInfo($file, dirname($file), $file));
Expand All @@ -245,7 +245,7 @@ public function unserialize($serialized): void
/**
* Help Psalm out a bit:
*
* @return \ArrayIterator<int, SplFileInfo>
* @return \ArrayIterator<array-key, SplFileInfo>
*/
public function getIterator(): \ArrayIterator
{
Expand Down
5 changes: 4 additions & 1 deletion src/Composer/GrumPHPPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,10 @@ private function runGrumPhpCommand(string $command): void
// Windows requires double double quotes
// https://bugs.php.net/bug.php?id=49139
$windowsIsInsane = function (string $command): string {
return $this->runsOnWindows() ? '"'.$command.'"' : $command;
return $command;
// Looks like this is not needed anymore since PHP8 - even though the bug is still open.
// Leaving this here for reference if the bug pops up again for some poeple!
// return $this->runsOnWindows() ? '"'.$command.'"' : $command;
};

// Run command
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/GrumPHPExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function getConfiguration(array $config, ContainerBuilder $container): Co
return new Configuration();
}

public function getAlias()
public function getAlias(): string
{
return 'grumphp';
}
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Command/Git/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ public function execute(InputInterface $input, OutputInterface $output): int
foreach (self::$hooks as $hook) {
$gitHook = $this->filesystem->buildPath($gitHooksPath, $hook);
$hookTemplate = $this->filesystem->guessFile(
array_filter([
[
$customHooksPath,
$resourceHooksPath,
]),
],
[$hook]
);

Expand Down
12 changes: 5 additions & 7 deletions src/IO/ConsoleIO.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Symfony\Component\Console\Style\StyleInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class ConsoleIO implements IOInterface, \Serializable
class ConsoleIO implements IOInterface
{
private $input;
private $output;
Expand Down Expand Up @@ -143,27 +143,25 @@ static function (string $message) use ($color) : string {
* Serializing this IO will result in an unwritable resource stream.
* Therefor we serialize the data end build up a new stream instead.
*/
public function serialize()
public function __serialize(): array
{
return serialize([
return [
'input' => [
'arguments' => $this->input->getArguments(),
],
'output' => [
'verbosity' => $this->output->getVerbosity(),
],
]);
];
}

/**
* Use the serialized data to rebuild new input + output streams.
* Note: When you run in parallel mode, the stream will be non-blocking.
* All tasks can write at the same time, which is not optimal.
*/
public function unserialize($serialized)
public function __unserialize(array $data): void
{
$data = unserialize($serialized, ['allowed_classes' => false]);

$this->input = new ArrayInput(
(array) ($data['input']['arguments'] ?? [])
);
Expand Down
Loading

0 comments on commit 44ee028

Please sign in to comment.