Skip to content

Commit

Permalink
Allow PHP 7.2 (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Dec 7, 2022
1 parent f7442af commit df1f05d
Show file tree
Hide file tree
Showing 14 changed files with 199 additions and 87 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,36 @@ jobs:
- name: "Run the PHPUnit tests"
run: "make phpunit"

legacy-tests:
name: "Legacy Tests"
runs-on: "ubuntu-latest"
strategy:
matrix:
php-version:
- "7.2"
- "7.3"
steps:
- name: "Checkout"
uses: "actions/[email protected]"

- name: "Remove incompatible dev dependencies"
run: |
composer remove --dev fidry/makefile --no-update --no-install;
composer remove --dev theofidry/php-cs-fixer-config --no-update --no-install;
composer remove --dev webmozarts/strict-phpunit --no-update --no-install;
- name: "Set up PHP"
uses: "shivammathur/[email protected]"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"

- name: "Install Composer dependencies"
uses: "ramsey/composer-install@v2"

- name: "Run the PHPUnit tests"
run: "vendor/bin/phpunit --configuration phpunit_legacy.xml.dist"

infection:
name: "Infection"
runs-on: "ubuntu-latest"
Expand Down
11 changes: 9 additions & 2 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
EOF,
74_000,
72000,
);
$config->addRules(['mb_str_functions' => false]);
$config->addRules([
// For PHP 7.2 compat
'heredoc_indentation' => false,
'trailing_comma_in_multiline' => false,

'mb_str_functions' => false,
'no_trailing_whitespace_in_string' => false,
]);
$config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache');

return $config->setFinder($finder);
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"require": {
"php": "^7.4 || ^8.0"
"php": "^7.2 || ^8.0"
},
"require-dev": {
"fidry/makefile": "^0.2.0",
Expand All @@ -23,7 +23,7 @@
"phpstan/phpstan-deprecation-rules": "^1.0.0",
"phpstan/phpstan-phpunit": "^1.2.2",
"phpstan/phpstan-strict-rules": "^1.4.4",
"phpunit/phpunit": "^9.5.26",
"phpunit/phpunit": "^9.5.26 || ^8.5.31",
"theofidry/php-cs-fixer-config": "^1.0",
"webmozarts/strict-phpunit": "^7.5"
},
Expand All @@ -35,7 +35,10 @@
"autoload-dev": {
"psr-4": {
"Fidry\\CpuCoreCounter\\Test\\": "tests/"
}
},
"classmap": [
"stubs"
]
},
"config": {
"allow-plugins": {
Expand Down
2 changes: 1 addition & 1 deletion infection.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "./tools/infection/resources/schema.json",
"$schema": "https://raw.githubusercontent.com/infection/infection/0.26.16/resources/schema.json",
"ignoreMsiWithNoMutations": true,
"logs": {
"text": ".build/infection/infection-log.txt"
Expand Down
18 changes: 18 additions & 0 deletions phpunit_legacy.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
bootstrap="vendor/autoload.php"
failOnRisky="true"
failOnWarning="true"
cacheResultFile=".build/phpunit/.phpunit.result.cache">
<php>
<ini name="error_reporting" value="-1"/>
</php>

<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
8 changes: 4 additions & 4 deletions src/CpuCoreCounter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ final class CpuCoreCounter
/**
* @var list<CpuCoreFinder>
*/
private array $finders;
private $finders;

/**
* @var positive-int
* @var positive-int|null
*/
private int $count;
private $count;

/**
* @param list<CpuCoreFinder>|null $finders
Expand All @@ -41,7 +41,7 @@ public function __construct(?array $finders = null)
public function getCount(): int
{
// Memoize result
if (!isset($this->count)) {
if (null === $this->count) {
$this->count = $this->findCount();
}

Expand Down
2 changes: 1 addition & 1 deletion src/NumberOfCpuCoreNotFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class NumberOfCpuCoreNotFound extends RuntimeException
public static function create(): self
{
return new self(
'Could not find the number of CPU cores available.',
'Could not find the number of CPU cores available.'
);
}
}
33 changes: 33 additions & 0 deletions stubs/BaseMakefileTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* This file is part of the Fidry CPUCounter Config package.
*
* (c) Théo FIDRY <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Fidry\Makefile\Test;

use Composer\InstalledVersions;
use PHPUnit\Framework\TestCase;

// When testing 7.2 or 7.3, fidry/makefile is not installed hence this stub.
if (InstalledVersions::isInstalled('fidry/makefile')) {
return;
}

/**
* @internal
*/
class BaseMakefileTestCase extends TestCase
{
public function test_dummy(): void
{
$this->addToAssertionCount(1);
}
}
59 changes: 31 additions & 28 deletions tests/CpuInfoFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,48 +40,51 @@ public static function cpuInfoProvider(): iterable
yield 'empty' => [
<<<'EOF'

EOF,
EOF
,
null,
];

yield 'whitespace' => [
<<<'EOF'

EOF,

EOF
,
null,
];

// $ docker run --tty --rm --platform linux/amd64 alpine:3.14 cat /proc/cpuinfo
yield 'example from an alpine Docker image' => [
<<<'EOF'
processor : 0
BogoMIPS : 48.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp flagm2 frint
CPU implementer : 0x00
CPU architecture: 8
CPU variant : 0x0
CPU part : 0x000
CPU revision : 0
processor : 0
BogoMIPS : 48.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp flagm2 frint
CPU implementer : 0x00
CPU architecture: 8
CPU variant : 0x0
CPU part : 0x000
CPU revision : 0
processor : 1
BogoMIPS : 48.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp flagm2 frint
CPU implementer : 0x00
CPU architecture: 8
CPU variant : 0x0
CPU part : 0x000
CPU revision : 0
processor : 1
BogoMIPS : 48.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp flagm2 frint
CPU implementer : 0x00
CPU architecture: 8
CPU variant : 0x0
CPU part : 0x000
CPU revision : 0
processor : 2
BogoMIPS : 48.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp flagm2 frint
CPU implementer : 0x00
CPU architecture: 8
CPU variant : 0x0
CPU part : 0x000
CPU revision : 0
processor : 2
BogoMIPS : 48.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp flagm2 frint
CPU implementer : 0x00
CPU architecture: 8
CPU variant : 0x0
CPU part : 0x000
CPU revision : 0

EOF,
EOF
,
3,
];
}
Expand Down
5 changes: 4 additions & 1 deletion tests/DummyCpuCoreFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

final class DummyCpuCoreFinder implements CpuCoreFinder
{
private ?int $count;
/**
* @var int|null
*/
private $count;

public function __construct(?int $count)
{
Expand Down
23 changes: 14 additions & 9 deletions tests/HwFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,43 @@ public static function processProvider(): iterable
yield 'empty' => [
<<<'EOF'

EOF,
EOF
,
null,
];

yield 'whitespace' => [
<<<'EOF'

EOF,

EOF
,
null,
];

// MyMachine™
yield 'example from an OSX machine' => [
<<<'EOF'
3
3

EOF,
EOF
,
3,
];
yield 'example with extra spaces' => [
<<<'EOF'
3
3

EOF,
EOF
,
3,
];

yield 'no processor' => [
<<<'EOF'
0
0

EOF,
EOF
,
null,
];
}
Expand Down
40 changes: 20 additions & 20 deletions tests/MakefileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@ protected static function getMakefilePath(): string
protected function getExpectedHelpOutput(): string
{
return <<<'EOF'
[33mUsage:[0m
make TARGET
[32m#
# Commands
#---------------------------------------------------------------------------[0m
[33mdefault:[0m Runs the default task
[33mphive:[0m Updates a (registered) tool. E.g. make phive TOOL=infection
[33mcs:[0m Fixes CS
[33mcs_lint:[0m Lints CS
[33mautoreview:[0m Runs the AutoReview tests
[33mtest:[0m Runs all the tests
[33mphpunit:[0m Runs PHPUnit
[33mphpunit_coverage_infection:[0m Runs PHPUnit with code coverage for Infection
[33mphpunit_coverage_html:[0m Runs PHPUnit with code coverage with HTML report
[33minfection:[0m Runs infection
[33msecurity:[0m Runs the security check
[33mcomposer_audit:[0m Runs a security analysis with Composer

EOF;
[33mUsage:[0m
make TARGET
[32m#
# Commands
#---------------------------------------------------------------------------[0m
[33mdefault:[0m Runs the default task
[33mphive:[0m Updates a (registered) tool. E.g. make phive TOOL=infection
[33mcs:[0m Fixes CS
[33mcs_lint:[0m Lints CS
[33mautoreview:[0m Runs the AutoReview tests
[33mtest:[0m Runs all the tests
[33mphpunit:[0m Runs PHPUnit
[33mphpunit_coverage_infection:[0m Runs PHPUnit with code coverage for Infection
[33mphpunit_coverage_html:[0m Runs PHPUnit with code coverage with HTML report
[33minfection:[0m Runs infection
[33msecurity:[0m Runs the security check
[33mcomposer_audit:[0m Runs a security analysis with Composer

EOF;
}
}
Loading

0 comments on commit df1f05d

Please sign in to comment.