Skip to content
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

PHP 7.4 and higher, dropped old dependencies, GitHub Actions #47

Closed
wants to merge 1 commit into from
Closed
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
42 changes: 42 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Test

on:
pull_request: ~
push:
branches:
- "master"

jobs:
test:
name: "PHP ${{ matrix.php-version }} ${{ matrix.dependency-versions }} ${{ matrix.composer-stability }}"
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04]
php-version: [8.1, 8.0, 7.4]
dependency-versions: [prefer-lowest, prefer-stable]

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

- name: Install and configure PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer:v2
coverage: none

- name: Set composer stability
if: ${{ matrix.composer-stability }}
run: composer config minimum-stability ${{ matrix.composer-stability }}

- name: Install composer dependencies
uses: ramsey/composer-install@v1
with:
dependency-versions: ${{ matrix.dependency-versions }}

- name: Run tests
run: ./vendor/bin/phpunit --verbose
26 changes: 0 additions & 26 deletions .travis.yml

This file was deleted.

17 changes: 10 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"name": "alchemy/binary-driver",
"type": "library",
"description": "A set of tools to build binary drivers",
"keywords": ["binary", "driver"],
"keywords": [
"binary",
"driver"
],
"license": "MIT",
"authors": [
{
Expand All @@ -27,17 +30,17 @@
}
],
"require": {
"php" : ">=5.5",
"evenement/evenement" : "^3.0|^2.0|^1.0",
"psr/log" : "^1.0",
"symfony/process" : "^2.3|^3.0|^4.0|^5.0"
"php": "^7.4|^8.0",
"evenement/evenement": "^3.0",
"psr/log": "^1.0|^2.0|^3.0",
"symfony/process": "^5.0|^6.0"
},
"require-dev": {
"phpunit/phpunit" : "^4.0|^5.0"
"phpunit/phpunit": "^9.4"
},
"autoload": {
"psr-0": {
"Alchemy": "src"
}
}
}
}
21 changes: 16 additions & 5 deletions src/Alchemy/BinaryDriver/BinaryDriverTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace Alchemy\BinaryDriver;

use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Symfony\Component\Process\Process;

/**
* Convenient PHPUnit methods for testing BinaryDriverInterface implementations.
*/
class BinaryDriverTestCase extends \PHPUnit_Framework_TestCase
class BinaryDriverTestCase extends TestCase
{
/**
* @return ProcessBuilderFactoryInterface
Expand All @@ -18,6 +19,16 @@ public function createProcessBuilderFactoryMock()
return $this->getMock('Alchemy\BinaryDriver\ProcessBuilderFactoryInterface');
}

/**
* Creates a mock object.
*
* @psalm-return MockObject&MockedType
*/
protected function getMock(string $className)
{
return $this->getMockBuilder($className)->getMock();
}

/**
* @param integer $runs The number of runs expected
* @param Boolean $success True if the process expects to be successfull
Expand All @@ -44,11 +55,11 @@ public function createProcessMock($runs = 1, $success = true, $commandLine = nul
->method('isSuccessful')
->will($this->returnValue($success));

foreach (array(
'getOutput' => $output,
'getErrorOutput' => $error,
foreach ([
'getOutput' => is_null($output) ? '' : $output,
'getErrorOutput' => is_null($error) ? '' : $error,
'getCommandLine' => $commandLine,
) as $command => $value) {
] as $command => $value) {
$process
->expects($this->any())
->method($command)
Expand Down
96 changes: 11 additions & 85 deletions src/Alchemy/BinaryDriver/ProcessBuilderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Alchemy\BinaryDriver\Exception\InvalidArgumentException;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\ProcessBuilder;

class ProcessBuilderFactory implements ProcessBuilderFactoryInterface
{
Expand All @@ -31,25 +30,6 @@ class ProcessBuilderFactory implements ProcessBuilderFactoryInterface
*/
private $timeout;

/**
* An internal ProcessBuilder.
*
* Note that this one is used only if Symfony ProcessBuilder has method
* setPrefix (2.3)
*
* @var ProcessBuilder
*/
private $builder;

/**
* Tells whether Symfony LTS ProcessBuilder should be emulated or not.
*
* This symfony version provided a brand new ::setPrefix method.
*
* @var Boolean
*/
public static $emulateSfLTS;

/**
* Constructor
*
Expand All @@ -59,38 +39,9 @@ class ProcessBuilderFactory implements ProcessBuilderFactoryInterface
*/
public function __construct($binary)
{
$this->detectEmulation();

if (!self::$emulateSfLTS) {
$this->builder = new ProcessBuilder();
}

$this->useBinary($binary);
}

/**
* Covenient method for unit testing
*
* @return type
*/
public function getBuilder()
{
return $this->builder;
}

/**
* Covenient method for unit testing
*
* @param ProcessBuilder $builder
* @return ProcessBuilderFactory
*/
public function setBuilder(ProcessBuilder $builder)
{
$this->builder = $builder;

return $this;
}

/**
* @inheritdoc
*/
Expand All @@ -110,10 +61,6 @@ public function useBinary($binary)

$this->binary = $binary;

if (!static::$emulateSfLTS) {
$this->builder->setPrefix($binary);
}

return $this;
}

Expand All @@ -124,10 +71,6 @@ public function setTimeout($timeout)
{
$this->timeout = $timeout;

if (!static::$emulateSfLTS) {
$this->builder->setTimeout($this->timeout);
}

return $this;
}

Expand All @@ -142,45 +85,28 @@ public function getTimeout()
/**
* @inheritdoc
*/
public function create($arguments = array())
public function create($arguments = [])
{
if (null === $this->binary) {
throw new InvalidArgumentException('No binary set');
}

if (!is_array($arguments)) {
$arguments = array($arguments);
$arguments = [$arguments];
}

if (static::$emulateSfLTS) {
array_unshift($arguments, $this->binary);
if (method_exists('Symfony\Component\Process\ProcessUtils', 'escapeArgument')) {
$script = implode(' ', array_map(array('Symfony\Component\Process\ProcessUtils', 'escapeArgument'), $arguments));
} else {
$script = $arguments;
}

$env = array_replace($_ENV, $_SERVER);
$env = array_filter($env, function ($value) {
return !is_array($value);
});

return new Process($script, null, $env, null, $this->timeout);
array_unshift($arguments, $this->binary);
if (method_exists('Symfony\Component\Process\ProcessUtils', 'escapeArgument')) {
$script = implode(' ', array_map(['Symfony\Component\Process\ProcessUtils', 'escapeArgument'], $arguments));
} else {
return $this->builder
->setArguments($arguments)
->getProcess();
$script = $arguments;
}
}

private function detectEmulation()
{
if (null !== static::$emulateSfLTS) {
return $this;
}
$env = array_replace($_ENV, $_SERVER);
$env = array_filter($env, function ($value) {
return !is_array($value);
});

static::$emulateSfLTS = !method_exists('Symfony\Component\Process\ProcessBuilder', 'setPrefix');

return $this;
return new Process($script, null, $env, null, $this->timeout);
}
}
23 changes: 14 additions & 9 deletions src/Alchemy/BinaryDriver/ProcessRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,17 @@ class ProcessRunner implements ProcessRunnerInterface
public function __construct(LoggerInterface $logger, $name)
{
$this->logger = $logger;
$this->name = $name;
$this->name = $name;
}

/**
* {@inheritdoc}
*
* @return ProcessRunner
*/
public function setLogger(LoggerInterface $logger)
public function setLogger(LoggerInterface $logger): void
{
$this->logger = $logger;

return $this;
}

/**
Expand All @@ -57,7 +55,9 @@ public function getLogger()
public function run(Process $process, SplObjectStorage $listeners, $bypassErrors)
{
$this->logger->info(sprintf(
'%s running command %s', $this->name, $process->getCommandLine()
'%s running command %s',
$this->name,
$process->getCommandLine()
));

try {
Expand All @@ -68,7 +68,6 @@ public function run(Process $process, SplObjectStorage $listeners, $bypassErrors
}
}


if (!$bypassErrors && !$process->isSuccessful()) {
$this->doExecutionFailure($process->getCommandLine(), $process->getErrorOutput());
} elseif (!$process->isSuccessful()) {
Expand All @@ -92,11 +91,17 @@ private function buildCallback(SplObjectStorage $listeners)
private function doExecutionFailure($command, $errorOutput, \Exception $e = null)
{
$this->logger->error($this->createErrorMessage($command, $errorOutput));
throw new ExecutionFailureException($this->name, $command, $errorOutput,
$e ? $e->getCode() : 0, $e ?: null);
throw new ExecutionFailureException(
$this->name,
$command,
$errorOutput,
$e ? $e->getCode() : 0,
$e ?: null
);
}

private function createErrorMessage($command, $errorOutput){
private function createErrorMessage($command, $errorOutput)
{
return sprintf('%s failed to execute command %s: %s', $this->name, $command, $errorOutput);
}
}
Loading