diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..c2dc239 --- /dev/null +++ b/.github/workflows/tests.yml @@ -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 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b95ee4f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,26 +0,0 @@ -language: php -dist: trusty - -sudo: false - -php: - - 7.0 - - 7.1 - - 7.2 - - 7.3 - -matrix: - include: - - php: 7.0 - env: COMPOSER_REQUIRE="symfony/process:^2.0" - - php: 7.0 - env: COMPOSER_REQUIRE="symfony/process:^3.0" - - php: 7.2 - env: COMPOSER_REQUIRE="symfony/process:^5.0" - - php: 7.3 - env: COMPOSER_REQUIRE="symfony/process:^5.0" - -before_script: - - composer self-update - - if [ -n "$COMPOSER_REQUIRE" ]; then composer require --no-update $COMPOSER_REQUIRE; fi - - composer update $COMPOSER_OPTIONS diff --git a/composer.json b/composer.json index a91d6c1..e25a4cc 100644 --- a/composer.json +++ b/composer.json @@ -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": [ { @@ -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" } } -} +} \ No newline at end of file diff --git a/src/Alchemy/BinaryDriver/BinaryDriverTestCase.php b/src/Alchemy/BinaryDriver/BinaryDriverTestCase.php index 3d0463d..c76463d 100644 --- a/src/Alchemy/BinaryDriver/BinaryDriverTestCase.php +++ b/src/Alchemy/BinaryDriver/BinaryDriverTestCase.php @@ -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 @@ -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 @@ -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) diff --git a/src/Alchemy/BinaryDriver/ProcessBuilderFactory.php b/src/Alchemy/BinaryDriver/ProcessBuilderFactory.php index b25ba3c..a1cafc8 100644 --- a/src/Alchemy/BinaryDriver/ProcessBuilderFactory.php +++ b/src/Alchemy/BinaryDriver/ProcessBuilderFactory.php @@ -13,7 +13,6 @@ use Alchemy\BinaryDriver\Exception\InvalidArgumentException; use Symfony\Component\Process\Process; -use Symfony\Component\Process\ProcessBuilder; class ProcessBuilderFactory implements ProcessBuilderFactoryInterface { @@ -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 * @@ -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 */ @@ -110,10 +61,6 @@ public function useBinary($binary) $this->binary = $binary; - if (!static::$emulateSfLTS) { - $this->builder->setPrefix($binary); - } - return $this; } @@ -124,10 +71,6 @@ public function setTimeout($timeout) { $this->timeout = $timeout; - if (!static::$emulateSfLTS) { - $this->builder->setTimeout($this->timeout); - } - return $this; } @@ -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); } } diff --git a/src/Alchemy/BinaryDriver/ProcessRunner.php b/src/Alchemy/BinaryDriver/ProcessRunner.php index 0274887..7384dfa 100644 --- a/src/Alchemy/BinaryDriver/ProcessRunner.php +++ b/src/Alchemy/BinaryDriver/ProcessRunner.php @@ -28,7 +28,7 @@ class ProcessRunner implements ProcessRunnerInterface public function __construct(LoggerInterface $logger, $name) { $this->logger = $logger; - $this->name = $name; + $this->name = $name; } /** @@ -36,11 +36,9 @@ public function __construct(LoggerInterface $logger, $name) * * @return ProcessRunner */ - public function setLogger(LoggerInterface $logger) + public function setLogger(LoggerInterface $logger): void { $this->logger = $logger; - - return $this; } /** @@ -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 { @@ -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()) { @@ -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); } } diff --git a/tests/Alchemy/Tests/BinaryDriver/AbstractBinaryTest.php b/tests/Alchemy/Tests/BinaryDriver/AbstractBinaryTest.php index f51ab6f..befbd8d 100644 --- a/tests/Alchemy/Tests/BinaryDriver/AbstractBinaryTest.php +++ b/tests/Alchemy/Tests/BinaryDriver/AbstractBinaryTest.php @@ -14,11 +14,7 @@ class AbstractBinaryTest extends BinaryDriverTestCase protected function getPhpBinary() { $finder = new ExecutableFinder(); - $php = $finder->find('php'); - - if (null === $php) { - $this->markTestSkipped('Unable to find a php binary'); - } + $php = $finder->find('php'); return $php; } @@ -35,7 +31,7 @@ public function testSimpleLoadWithBinaryPath() public function testMultipleLoadWithBinaryPath() { $php = $this->getPhpBinary(); - $imp = Implementation::load(array('/zz/path/to/unexisting/command', $php)); + $imp = Implementation::load(['/zz/path/to/unexisting/command', $php]); $this->assertInstanceOf('Alchemy\Tests\BinaryDriver\Implementation', $imp); $this->assertEquals($php, $imp->getProcessBuilderFactory()->getBinary()); @@ -53,7 +49,7 @@ public function testSimpleLoadWithBinaryName() public function testMultipleLoadWithBinaryName() { $php = $this->getPhpBinary(); - $imp = Implementation::load(array('bachibouzouk', 'php')); + $imp = Implementation::load(['bachibouzouk', 'php']); $this->assertInstanceOf('Alchemy\Tests\BinaryDriver\Implementation', $imp); $this->assertEquals($php, $imp->getProcessBuilderFactory()->getBinary()); @@ -61,14 +57,14 @@ public function testMultipleLoadWithBinaryName() public function testLoadWithMultiplePathExpectingAFailure() { - $this->setExpectedException(ExecutableNotFoundException::class); + $this->expectException(ExecutableNotFoundException::class); - Implementation::load(array('bachibouzouk', 'moribon')); + Implementation::load(['bachibouzouk', 'moribon']); } public function testLoadWithUniquePathExpectingAFailure() { - $this->setExpectedException(ExecutableNotFoundException::class); + $this->expectException(ExecutableNotFoundException::class); Implementation::load('bachibouzouk'); } @@ -76,15 +72,15 @@ public function testLoadWithUniquePathExpectingAFailure() public function testLoadWithCustomLogger() { $logger = $this->getMock('Psr\Log\LoggerInterface'); - $imp = Implementation::load('php', $logger); + $imp = Implementation::load('php', $logger); $this->assertEquals($logger, $imp->getProcessRunner()->getLogger()); } public function testLoadWithCustomConfigurationAsArray() { - $conf = array('timeout' => 200); - $imp = Implementation::load('php', null, $conf); + $conf = ['timeout' => 200]; + $imp = Implementation::load('php', null, $conf); $this->assertEquals($conf, $imp->getConfiguration()->all()); } @@ -92,14 +88,14 @@ public function testLoadWithCustomConfigurationAsArray() public function testLoadWithCustomConfigurationAsObject() { $conf = $this->getMock('Alchemy\BinaryDriver\ConfigurationInterface'); - $imp = Implementation::load('php', null, $conf); + $imp = Implementation::load('php', null, $conf); $this->assertEquals($conf, $imp->getConfiguration()); } public function testProcessBuilderFactoryGetterAndSetters() { - $imp = Implementation::load('php'); + $imp = Implementation::load('php'); $factory = $this->getMock('Alchemy\BinaryDriver\ProcessBuilderFactoryInterface'); $imp->setProcessBuilderFactory($factory); @@ -108,7 +104,7 @@ public function testProcessBuilderFactoryGetterAndSetters() public function testConfigurationGetterAndSetters() { - $imp = Implementation::load('php'); + $imp = Implementation::load('php'); $conf = $this->getMock('Alchemy\BinaryDriver\ConfigurationInterface'); $imp->setConfiguration($conf); @@ -117,20 +113,20 @@ public function testConfigurationGetterAndSetters() public function testTimeoutIsSetOnConstruction() { - $imp = Implementation::load('php', null, array('timeout' => 42)); + $imp = Implementation::load('php', null, ['timeout' => 42]); $this->assertEquals(42, $imp->getProcessBuilderFactory()->getTimeout()); } public function testTimeoutIsSetOnConfigurationSetting() { $imp = Implementation::load('php', null); - $imp->setConfiguration(new Configuration(array('timeout' => 42))); + $imp->setConfiguration(new Configuration(['timeout' => 42])); $this->assertEquals(42, $imp->getProcessBuilderFactory()->getTimeout()); } public function testTimeoutIsSetOnProcessBuilderSetting() { - $imp = Implementation::load('php', null, array('timeout' => 42)); + $imp = Implementation::load('php', null, ['timeout' => 42]); $factory = $this->getMock('Alchemy\BinaryDriver\ProcessBuilderFactoryInterface'); $factory->expects($this->once()) @@ -155,7 +151,7 @@ public function testListenRegistersAListener() ->with($this->equalTo($listener), $this->equalTo($imp)); $reflexion = new \ReflectionClass('Alchemy\BinaryDriver\AbstractBinary'); - $prop = $reflexion->getProperty('listenersManager'); + $prop = $reflexion->getProperty('listenersManager'); $prop->setAccessible(true); $prop->setValue($imp, $listeners); @@ -167,8 +163,8 @@ public function testListenRegistersAListener() */ public function testCommandRunsAProcess($parameters, $bypassErrors, $expectedParameters, $output) { - $imp = Implementation::load('php'); - $factory = $this->getMock('Alchemy\BinaryDriver\ProcessBuilderFactoryInterface'); + $imp = Implementation::load('php'); + $factory = $this->getMock('Alchemy\BinaryDriver\ProcessBuilderFactoryInterface'); $processRunner = $this->getMock('Alchemy\BinaryDriver\ProcessRunnerInterface'); $process = $this->getMockBuilder('Symfony\Component\Process\Process') @@ -196,8 +192,8 @@ public function testCommandRunsAProcess($parameters, $bypassErrors, $expectedPar */ public function testCommandWithTemporaryListeners($parameters, $bypassErrors, $expectedParameters, $output, $count, $listeners) { - $imp = Implementation::load('php'); - $factory = $this->getMock('Alchemy\BinaryDriver\ProcessBuilderFactoryInterface'); + $imp = Implementation::load('php'); + $factory = $this->getMock('Alchemy\BinaryDriver\ProcessBuilderFactoryInterface'); $processRunner = $this->getMock('Alchemy\BinaryDriver\ProcessRunnerInterface'); $process = $this->getMockBuilder('Symfony\Component\Process\Process') @@ -235,24 +231,24 @@ public function testCommandWithTemporaryListeners($parameters, $bypassErrors, $e public function provideCommandWithListenersParameters() { - return array( - array('-a', false, array('-a'), 'loubda', 2, array($this->getMockListener(), $this->getMockListener())), - array('-a', false, array('-a'), 'loubda', 1, array($this->getMockListener())), - array('-a', false, array('-a'), 'loubda', 1, $this->getMockListener()), - array('-a', false, array('-a'), 'loubda', 0, array()), - ); + return [ + ['-a', false, ['-a'], 'loubda', 2, [$this->getMockListener(), $this->getMockListener()]], + ['-a', false, ['-a'], 'loubda', 1, [$this->getMockListener()]], + ['-a', false, ['-a'], 'loubda', 1, $this->getMockListener()], + ['-a', false, ['-a'], 'loubda', 0, []], + ]; } public function provideCommandParameters() { - return array( - array('-a', false, array('-a'), 'loubda'), - array('-a', true, array('-a'), 'loubda'), - array('-a -b', false, array('-a -b'), 'loubda'), - array(array('-a'), false, array('-a'), 'loubda'), - array(array('-a'), true, array('-a'), 'loubda'), - array(array('-a', '-b'), false, array('-a', '-b'), 'loubda'), - ); + return [ + ['-a', false, ['-a'], 'loubda'], + ['-a', true, ['-a'], 'loubda'], + ['-a -b', false, ['-a -b'], 'loubda'], + [['-a'], false, ['-a'], 'loubda'], + [['-a'], true, ['-a'], 'loubda'], + [['-a', '-b'], false, ['-a', '-b'], 'loubda'], + ]; } public function testUnlistenUnregistersAListener() @@ -270,7 +266,7 @@ public function testUnlistenUnregistersAListener() ->with($this->equalTo($listener), $this->equalTo($imp)); $reflexion = new \ReflectionClass('Alchemy\BinaryDriver\AbstractBinary'); - $prop = $reflexion->getProperty('listenersManager'); + $prop = $reflexion->getProperty('listenersManager'); $prop->setAccessible(true); $prop->setValue($imp, $listeners); @@ -285,7 +281,7 @@ private function getMockListener() $listener = $this->getMock(ListenerInterface::class); $listener->expects($this->any()) ->method('forwardedEvents') - ->willReturn(array()); + ->willReturn([]); return $listener; } diff --git a/tests/Alchemy/Tests/BinaryDriver/AbstractProcessBuilderFactoryTest.php b/tests/Alchemy/Tests/BinaryDriver/AbstractProcessBuilderFactoryTest.php index de0b61c..a466a9e 100644 --- a/tests/Alchemy/Tests/BinaryDriver/AbstractProcessBuilderFactoryTest.php +++ b/tests/Alchemy/Tests/BinaryDriver/AbstractProcessBuilderFactoryTest.php @@ -2,10 +2,12 @@ namespace Alchemy\Tests\BinaryDriver; -use Symfony\Component\Process\ExecutableFinder; +use Alchemy\BinaryDriver\Exception\InvalidArgumentException; use Alchemy\BinaryDriver\ProcessBuilderFactory; +use PHPUnit\Framework\TestCase; +use Symfony\Component\Process\ExecutableFinder; -abstract class AbstractProcessBuilderFactoryTest extends \PHPUnit_Framework_TestCase +abstract class AbstractProcessBuilderFactoryTest extends TestCase { public static $phpBinary; @@ -15,17 +17,11 @@ abstract class AbstractProcessBuilderFactoryTest extends \PHPUnit_Framework_Test */ abstract protected function getProcessBuilderFactory($binary); - public function setUp() + public static function setUpBeforeClass(): void { - ProcessBuilderFactory::$emulateSfLTS = null; - if (null === static::$phpBinary) { - $this->markTestSkipped('Unable to detect php binary, skipping'); - } - } + parent::setUpBeforeClass(); - public static function setUpBeforeClass() - { - $finder = new ExecutableFinder(); + $finder = new ExecutableFinder(); static::$phpBinary = $finder->find('php'); } @@ -38,22 +34,16 @@ public function testThatBinaryIsSetOnConstruction() public function testGetSetBinary() { $finder = new ExecutableFinder(); - $phpUnit = $finder->find('phpunit'); - - if (null === $phpUnit) { - $this->markTestSkipped('Unable to detect phpunit binary, skipping'); - } + $php = $finder->find('php'); $factory = $this->getProcessBuilderFactory(static::$phpBinary); - $factory->useBinary($phpUnit); - $this->assertEquals($phpUnit, $factory->getBinary()); + $factory->useBinary($php); + $this->assertEquals($php, $factory->getBinary()); } - /** - * @expectedException Alchemy\BinaryDriver\Exception\InvalidArgumentException - */ public function testUseNonExistantBinary() { + $this->expectException(InvalidArgumentException::class); $factory = $this->getProcessBuilderFactory(static::$phpBinary); $factory->useBinary('itissureitdoesnotexist'); } @@ -64,7 +54,7 @@ public function testCreateShouldReturnAProcess() $process = $factory->create(); $this->assertInstanceOf('Symfony\Component\Process\Process', $process); - $this->assertEquals("'".static::$phpBinary."'", $process->getCommandLine()); + $this->assertEquals("'" . static::$phpBinary . "'", $process->getCommandLine()); } public function testCreateWithStringArgument() @@ -73,23 +63,23 @@ public function testCreateWithStringArgument() $process = $factory->create('-v'); $this->assertInstanceOf('Symfony\Component\Process\Process', $process); - $this->assertEquals("'".static::$phpBinary."' '-v'", $process->getCommandLine()); + $this->assertEquals("'" . static::$phpBinary . "' '-v'", $process->getCommandLine()); } public function testCreateWithArrayArgument() { $factory = $this->getProcessBuilderFactory(static::$phpBinary); - $process = $factory->create(array('-r', 'echo "Hello !";')); + $process = $factory->create(['-r', 'echo "Hello !";']); $this->assertInstanceOf('Symfony\Component\Process\Process', $process); - $this->assertEquals("'".static::$phpBinary."' '-r' 'echo \"Hello !\";'", $process->getCommandLine()); + $this->assertEquals("'" . static::$phpBinary . "' '-r' 'echo \"Hello !\";'", $process->getCommandLine()); } public function testCreateWithTimeout() { $factory = $this->getProcessBuilderFactory(static::$phpBinary); $factory->setTimeout(200); - $process = $factory->create(array('-i')); + $process = $factory->create(['-i']); $this->assertInstanceOf('Symfony\Component\Process\Process', $process); $this->assertEquals(200, $process->getTimeout()); diff --git a/tests/Alchemy/Tests/BinaryDriver/ConfigurationTest.php b/tests/Alchemy/Tests/BinaryDriver/ConfigurationTest.php index b2cd2dd..71e1891 100644 --- a/tests/Alchemy/Tests/BinaryDriver/ConfigurationTest.php +++ b/tests/Alchemy/Tests/BinaryDriver/ConfigurationTest.php @@ -3,12 +3,13 @@ namespace Alchemy\Tests\BinaryDriver; use Alchemy\BinaryDriver\Configuration; +use PHPUnit\Framework\TestCase; -class ConfigurationTest extends \PHPUnit_Framework_TestCase +class ConfigurationTest extends TestCase { public function testArrayAccessImplementation() { - $configuration = new Configuration(array('key' => 'value')); + $configuration = new Configuration(['key' => 'value']); $this->assertTrue(isset($configuration['key'])); $this->assertEquals('value', $configuration['key']); @@ -31,7 +32,7 @@ public function testGetOnNonExistentKeyShouldReturnDefaultValue() public function testSetHasGetRemove() { - $configuration = new Configuration(array('key' => 'value')); + $configuration = new Configuration(['key' => 'value']); $this->assertTrue($configuration->has('key')); $this->assertEquals('value', $configuration->get('key')); @@ -47,14 +48,14 @@ public function testSetHasGetRemove() public function testIterator() { - $data = array( + $data = [ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', - ); + ]; - $captured = array(); - $conf = new Configuration($data); + $captured = []; + $conf = new Configuration($data); foreach ($conf as $key => $value) { $captured[$key] = $value; @@ -65,14 +66,13 @@ public function testIterator() public function testAll() { - $data = array( + $data = [ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', - ); + ]; $conf = new Configuration($data); $this->assertEquals($data, $conf->all()); } - } diff --git a/tests/Alchemy/Tests/BinaryDriver/LTSProcessBuilderFactoryTest.php b/tests/Alchemy/Tests/BinaryDriver/LTSProcessBuilderFactoryTest.php deleted file mode 100644 index 3c4c581..0000000 --- a/tests/Alchemy/Tests/BinaryDriver/LTSProcessBuilderFactoryTest.php +++ /dev/null @@ -1,28 +0,0 @@ -markTestSkipped('ProcessBuilder is not available.'); - return; - } - - parent::setUp(); - } - - protected function getProcessBuilderFactory($binary) - { - $factory = new ProcessBuilderFactory($binary); - $factory->setBuilder(new LTSProcessBuilder()); - ProcessBuilderFactory::$emulateSfLTS = false; - $factory->useBinary($binary); - - return $factory; - } -} diff --git a/tests/Alchemy/Tests/BinaryDriver/Listeners/DebugListenerTest.php b/tests/Alchemy/Tests/BinaryDriver/Listeners/DebugListenerTest.php index 6995867..29bf5f5 100644 --- a/tests/Alchemy/Tests/BinaryDriver/Listeners/DebugListenerTest.php +++ b/tests/Alchemy/Tests/BinaryDriver/Listeners/DebugListenerTest.php @@ -3,15 +3,16 @@ namespace Alchemy\Tests\BinaryDriver\Listeners; use Alchemy\BinaryDriver\Listeners\DebugListener; +use PHPUnit\Framework\TestCase; use Symfony\Component\Process\Process; -class DebugListenerTest extends \PHPUnit_Framework_TestCase +class DebugListenerTest extends TestCase { public function testHandle() { $listener = new DebugListener(); - $lines = array(); + $lines = []; $listener->on('debug', function ($line) use (&$lines) { $lines[] = $line; }); @@ -20,13 +21,13 @@ public function testHandle() $listener->handle('unknown', "lalala"); $listener->handle(Process::OUT, "another output\n"); - $expected = array( + $expected = [ '[ERROR] first line', '[ERROR] second line', '[OUT] cool output', '[OUT] another output', '[OUT] ', - ); + ]; $this->assertEquals($expected, $lines); } diff --git a/tests/Alchemy/Tests/BinaryDriver/Listeners/ListenersTest.php b/tests/Alchemy/Tests/BinaryDriver/Listeners/ListenersTest.php index fe96d73..67f9934 100644 --- a/tests/Alchemy/Tests/BinaryDriver/Listeners/ListenersTest.php +++ b/tests/Alchemy/Tests/BinaryDriver/Listeners/ListenersTest.php @@ -2,11 +2,12 @@ namespace Alchemy\Tests\BinaryDriver\Listeners; +use Alchemy\BinaryDriver\Listeners\ListenerInterface; use Alchemy\BinaryDriver\Listeners\Listeners; use Evenement\EventEmitter; -use Alchemy\BinaryDriver\Listeners\ListenerInterface; +use PHPUnit\Framework\TestCase; -class ListenersTest extends \PHPUnit_Framework_TestCase +class ListenersTest extends TestCase { public function testRegister() { @@ -40,7 +41,7 @@ public function testRegister() public function testRegisterAndForwardThenUnregister() { $listener = new MockListener(); - $target = new EventEmitter(); + $target = new EventEmitter(); $n = 0; $target->on('received', function ($type, $data) use (&$n, &$capturedType, &$capturedData) { @@ -82,11 +83,11 @@ class MockListener extends EventEmitter implements ListenerInterface { public function handle($type, $data) { - $this->emit('received', array($type, $data)); + $this->emit('received', [$type, $data]); } public function forwardedEvents() { - return array('received'); + return ['received']; } } diff --git a/tests/Alchemy/Tests/BinaryDriver/NONLTSProcessBuilderFactoryTest.php b/tests/Alchemy/Tests/BinaryDriver/NONLTSProcessBuilderFactoryTest.php index fe5f343..fb25cd5 100644 --- a/tests/Alchemy/Tests/BinaryDriver/NONLTSProcessBuilderFactoryTest.php +++ b/tests/Alchemy/Tests/BinaryDriver/NONLTSProcessBuilderFactoryTest.php @@ -8,8 +8,6 @@ class NONLTSProcessBuilderFactoryTest extends AbstractProcessBuilderFactoryTest { protected function getProcessBuilderFactory($binary) { - ProcessBuilderFactory::$emulateSfLTS = true; - return new ProcessBuilderFactory($binary); } }