Skip to content

Commit

Permalink
Fix Symfony 4.2 deprecations (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos authored and keradus committed Dec 23, 2018
1 parent 4f93a5f commit 6c42d7e
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ EOF;
return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules(array(
'@PHPUnit60Migration:risky' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'array_syntax' => array('syntax' => 'long'),
Expand All @@ -27,7 +28,13 @@ return PhpCsFixer\Config::create()
'no_useless_return' => true,
'ordered_class_elements' => true,
'ordered_imports' => true,
'php_unit_internal_class' => true,
'php_unit_ordered_covers' => true,
'php_unit_set_up_tear_down_visibility' => true,
'php_unit_strict' => true,
'php_unit_test_annotation' => true,
'php_unit_test_case_static_method_calls' => ['call_type' => 'this'],
'php_unit_test_class_requires_covers' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_order' => true,
'semicolon_after_instruction' => true,
Expand Down
33 changes: 31 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
language: php

sudo: false

git:
depth: 1

Expand Down Expand Up @@ -32,3 +30,34 @@ jobs:
script:
- ./vendor/bin/php-cs-fixer fix -v --dry-run
- ./vendor/bin/composer-require-checker check composer.json

- &STANDARD_TEST_JOB
stage: Test
php: 7.0
install:
- travis_retry composer update $DEFAULT_COMPOSER_FLAGS $COMPOSER_FLAGS
- composer info -D | sort
script:
- vendor/bin/phpunit || travis_terminate 1

-
<<: *STANDARD_TEST_JOB
stage: Test
php: 5.6
env: COMPOSER_FLAGS="--ignore-platform-reqs --prefer-stable --prefer-lowest"

-
<<: *STANDARD_TEST_JOB
stage: Test
php: 7.1

-
<<: *STANDARD_TEST_JOB
stage: Test
php: 7.2

-
<<: *STANDARD_TEST_JOB
stage: Test
php: 7.3
env: COMPOSER_FLAGS="--ignore-platform-reqs"
15 changes: 12 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,26 @@
],
"require": {
"php": "^5.3.6 || ^7.0",
"symfony/process": "^2.3 | ^3 | ^4"
"symfony/process": "^2.3 || ^3 || ^4"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.9",
"maglnet/composer-require-checker": "^0.1.6",
"friendsofphp/php-cs-fixer": "^2.9"
"phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1",
"symfony/phpunit-bridge": "^4.0"
},
"config": {
"optimize-autoloader": true,
"sort-packages": true
},
"autoload": {
"psr-4": { "Keradus\\CliExecutor\\": "src/" }
"psr-4": {
"Keradus\\CliExecutor\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Keradus\\Tests\\": "tests/"
}
}
}
28 changes: 28 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
colors="true"
columns="max"
verbose="true"
>
<testsuites>
<testsuite name="all">
<directory>./tests</directory>
</testsuite>
</testsuites>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>

<filter>
<whitelist>
<directory>./src</directory>
</whitelist>
</filter>
</phpunit>
7 changes: 6 additions & 1 deletion src/CommandExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ public static function create($command, $cwd)
public function getResult($checkCode = true)
{
if (null === $this->result) {
$process = new Process($this->command, $this->cwd);
// for symfony/process:^4.2
if (method_exists(Process::class, 'fromShellCommandline')) {
$process = Process::fromShellCommandline($this->command, $this->cwd);
} else {
$process = new Process($this->command, $this->cwd);
}
$process->run();

$this->result = new CliResult(
Expand Down
7 changes: 6 additions & 1 deletion src/ScriptExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ public function getResult($checkCode = true)
chmod($this->tmpFilePath, 0777);
$command = './'.$tmpFileName;

$process = new Process($command, $this->cwd);
// for symfony/process:^4.2
if (method_exists(Process::class, 'fromShellCommandline')) {
$process = Process::fromShellCommandline($command, $this->cwd);
} else {
$process = new Process($command, $this->cwd);
}
$process->run();

$this->result = new CliResult(
Expand Down
32 changes: 32 additions & 0 deletions tests/CommandExecutorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of CLI Executor.
*
* (c) Dariusz Rumiński <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Keradus\Tests;

use Keradus\CliExecutor\CommandExecutor;
use PHPUnit\Framework\TestCase;

/**
* @covers \Keradus\CliExecutor\CommandExecutor
*
* @internal
*/
class CommandExecutorTest extends TestCase
{
public function testSimpleExecution()
{
$scriptExecutor = CommandExecutor::create('ls -l', __DIR__);

$cliResult = $scriptExecutor->getResult();

$this->assertContains(basename(__FILE__), $cliResult->getOutput());
}
}
32 changes: 32 additions & 0 deletions tests/ScriptExecutorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of CLI Executor.
*
* (c) Dariusz Rumiński <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Keradus\Tests;

use Keradus\CliExecutor\ScriptExecutor;
use PHPUnit\Framework\TestCase;

/**
* @covers \Keradus\CliExecutor\ScriptExecutor
*
* @internal
*/
class ScriptExecutorTest extends TestCase
{
public function testSimpleExecution()
{
$scriptExecutor = ScriptExecutor::create(array('ls'), __DIR__);

$cliResult = $scriptExecutor->getResult();

$this->assertContains(basename(__FILE__), $cliResult->getOutput());
}
}

0 comments on commit 6c42d7e

Please sign in to comment.