Skip to content

Commit

Permalink
Check PHP requirement without Box
Browse files Browse the repository at this point in the history
  • Loading branch information
villfa committed Feb 3, 2022
1 parent 132add3 commit cd9c198
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 21 deletions.
44 changes: 41 additions & 3 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ jobs:
with:
coverage: "none"
ini-values: "error_reporting=-1, display_errors=On, display_startup_errors=On, zend.assertions=1"
php-version: "7.2"
php-version: "8.0"
tools: composer:v2

- name: Get composer cache directory
Expand Down Expand Up @@ -257,7 +257,7 @@ jobs:
path: ./churn.phar
if-no-files-found: error

tests-oldphp:
tests-phar-oldphp:
name: "Test Phar error message with PHP ${{ matrix.php-version }}"
runs-on: ubuntu-latest
# We need the phar file
Expand Down Expand Up @@ -291,5 +291,43 @@ jobs:

- name: Test churn.phar error message
run: |
php -r "passthru('./churn.phar', \$code); if (\$code !== 1) exit('Invalid error code. Expected 1, got ' . \$code);" > error
php -r "passthru('./churn.phar', \$code); if (\$code !== 1) exit('Invalid error code. Expected 1, got ' . \$code);" &> error
echo "Error code is OK. Now testing error message..."
grep 'The application requires the version ">=7.1.3" or greater' error
echo "Everything is OK."
tests-phar:
name: "Test Phar with PHP ${{ matrix.php-version }}"
runs-on: ubuntu-latest
# We need the phar file
needs: [build]

strategy:
matrix:
php-version:
- "7.1"
- "8.1"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
ini-values: "error_reporting=-1, display_errors=On, display_startup_errors=On, zend.assertions=1"
php-version: ${{ matrix.php-version }}
tools: none

- name: Download churn.phar
uses: actions/download-artifact@v2
with:
name: churn.phar

- name: Make churn.phar executable
run: chmod +x churn.phar

- name: "Run Phar"
run: ./churn.phar
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "7.4"
php-version: "8.0"
tools: composer:v2

- name: "Print tag message"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ help:
.PHONY: box
box: ## Download box.phar
box:
test -e build/box.phar || curl -sL https://github.com/box-project/box/releases/download/3.9.1/box.phar -o build/box.phar
test -e build/box.phar || curl -sL https://github.com/box-project/box/releases/download/3.14.0/box.phar -o build/box.phar
chmod +x build/box.phar

.PHONY: build
Expand Down
23 changes: 23 additions & 0 deletions bin/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

use Churn\Command\AssessComplexityCommand;
use Churn\Command\RunCommand;
use Composer\InstalledVersions;
use Symfony\Component\Console\Application;

$application = new Application('churn-php', (function (string $package): string {
$version = InstalledVersions::getPrettyVersion($package);
$ref = InstalledVersions::getReference($package);
if ($ref) {
$version .= '@' . \substr($ref, 0, 7);
}

return $version;
})('bmitch/churn-php'));
$application->add(new AssessComplexityCommand());
$application->add($run = RunCommand::newInstance());
$application->setDefaultCommand($run->getName());

return $application;
44 changes: 28 additions & 16 deletions bin/churn
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
#!/usr/bin/env php
<?php

require_once __DIR__ . '/bootstrap.php';
if (!version_compare(PHP_VERSION, PHP_VERSION, '=')) {
fwrite(
STDERR,
sprintf(
'%s declares an invalid value for PHP_VERSION.' . PHP_EOL .
'This breaks fundamental functionality such as version_compare().' . PHP_EOL .
'Please use a different PHP interpreter.' . PHP_EOL,
PHP_BINARY
)
);

die(1);
}

use Churn\Command\AssessComplexityCommand;
use Churn\Command\RunCommand;
use Composer\InstalledVersions;
use Symfony\Component\Console\Application;
if (version_compare('7.1.3', PHP_VERSION, '>=')) {
fwrite(
STDERR,
sprintf(
'The application requires the version ">=7.1.3" or greater.' . PHP_EOL .
'You are using PHP %s (%s).' . PHP_EOL,
PHP_VERSION,
PHP_BINARY
)
);

$application = new Application('churn-php', (function (string $package): string {
$version = InstalledVersions::getPrettyVersion($package);
$ref = InstalledVersions::getReference($package);
if ($ref) {
$version .= '@' . \substr($ref, 0, 7);
}
die(1);
}

require_once __DIR__ . '/bootstrap.php';

return $version;
})('bmitch/churn-php'));
$application->add(new AssessComplexityCommand());
$application->add($run = RunCommand::newInstance());
$application->setDefaultCommand($run->getName());
$application = require_once __DIR__ . '/app.php';
$application->run();
1 change: 1 addition & 0 deletions box.json.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"check-requirements": false,
"compactors": [
"KevinGH\\Box\\Compactor\\Php"
],
Expand Down

0 comments on commit cd9c198

Please sign in to comment.