From d8fde887180787735735857ea9c74dac214e9fbb Mon Sep 17 00:00:00 2001 From: Jerome Bourgeais Date: Tue, 7 Mar 2017 16:49:17 +0100 Subject: [PATCH 1/3] Making cachetool compatible w/ php7 * Add support of php7.0-fpm socket * Fix some php7 warn * Skip unit tests related to APC (not supported by php7) --- src/CacheTool/Adapter/FastCGI.php | 15 ++++++++++++--- src/CacheTool/Command/ApcCacheInfoCommand.php | 4 ++-- src/CacheTool/Command/ApcCacheInfoFileCommand.php | 2 +- tests/CacheTool/Command/ApcBinDumpCommandTest.php | 6 ++++++ tests/CacheTool/Command/ApcBinLoadCommandTest.php | 3 +++ .../Command/ApcCacheClearCommandTest.php | 9 +++++++++ .../CacheTool/Command/ApcCacheInfoCommandTest.php | 3 +++ .../Command/ApcCacheInfoFileCommandTest.php | 3 +++ .../CacheTool/Command/ApcKeyDeleteCommandTest.php | 3 +++ .../CacheTool/Command/ApcKeyExistsCommandTest.php | 3 +++ .../CacheTool/Command/ApcKeyFetchCommandTest.php | 3 +++ .../CacheTool/Command/ApcKeyStoreCommandTest.php | 3 +++ tests/CacheTool/Command/ApcSmaInfoCommandTest.php | 3 +++ 13 files changed, 54 insertions(+), 6 deletions(-) diff --git a/src/CacheTool/Adapter/FastCGI.php b/src/CacheTool/Adapter/FastCGI.php index 1e90e9d..d255a3c 100644 --- a/src/CacheTool/Adapter/FastCGI.php +++ b/src/CacheTool/Adapter/FastCGI.php @@ -21,6 +21,11 @@ class FastCGI extends AbstractAdapter */ protected $client; + protected $possibleSocketFiles = [ + '/var/run/php5-fpm.sock', + '/var/run/php/php7.0-fpm.sock' + ]; + /** * @var string */ @@ -34,9 +39,13 @@ public function __construct($host = null, $tempDir = null) { // try to guess where it is if ($host === null) { - if (file_exists('/var/run/php5-fpm.sock')) { - $host = '/var/run/php5-fpm.sock'; - } else { + foreach ($this->possibleSocketFiles as $possibleSocketFile) { + if (file_exists($possibleSocketFile)) { + $host = $possibleSocketFile; + break; + } + } + if ($host === null) { $host = '127.0.0.1:9000'; } } diff --git a/src/CacheTool/Command/ApcCacheInfoCommand.php b/src/CacheTool/Command/ApcCacheInfoCommand.php index 87a5192..0572103 100644 --- a/src/CacheTool/Command/ApcCacheInfoCommand.php +++ b/src/CacheTool/Command/ApcCacheInfoCommand.php @@ -54,8 +54,8 @@ protected function execute(InputInterface $input, OutputInterface $output) { $this->ensureExtensionLoaded('apc'); - $user = $this->getCacheTool()->apc_cache_info('user'); - $system = $this->getCacheTool()->apc_cache_info('system'); + $user = $this->getCacheTool()->apc_cache_info('user') ?: []; + $system = $this->getCacheTool()->apc_cache_info('system') ?: []; $this->normalize($user); $this->normalize($system); diff --git a/src/CacheTool/Command/ApcCacheInfoFileCommand.php b/src/CacheTool/Command/ApcCacheInfoFileCommand.php index a33a939..6bd6800 100644 --- a/src/CacheTool/Command/ApcCacheInfoFileCommand.php +++ b/src/CacheTool/Command/ApcCacheInfoFileCommand.php @@ -36,7 +36,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $this->ensureExtensionLoaded('apc'); - $info = $this->getCacheTool()->apc_cache_info('system'); + $info = $this->getCacheTool()->apc_cache_info('system') ?: []; $this->normalize($info); if (!$info) { diff --git a/tests/CacheTool/Command/ApcBinDumpCommandTest.php b/tests/CacheTool/Command/ApcBinDumpCommandTest.php index 84619dd..083cb99 100644 --- a/tests/CacheTool/Command/ApcBinDumpCommandTest.php +++ b/tests/CacheTool/Command/ApcBinDumpCommandTest.php @@ -6,6 +6,9 @@ class ApcBinDumpCommandTest extends CommandTest { public function testCommand() { + if (explode('.', PHP_VERSION_ID)[0] >= 7) { + $this->markTestSkipped('Skip APC test w/ php7'); + } $this->assertHasApc(); $this->assertNoHHVM(); @@ -18,6 +21,9 @@ public function testCommand() public function testCommandWithFile() { + if (explode('.', PHP_VERSION_ID)[0] >= 7) { + $this->markTestSkipped('Skip APC test w/ php7'); + } $this->assertHasApc(); $this->assertNoHHVM(); diff --git a/tests/CacheTool/Command/ApcBinLoadCommandTest.php b/tests/CacheTool/Command/ApcBinLoadCommandTest.php index 2584f71..64122ea 100644 --- a/tests/CacheTool/Command/ApcBinLoadCommandTest.php +++ b/tests/CacheTool/Command/ApcBinLoadCommandTest.php @@ -6,6 +6,9 @@ class ApcBinLoadCommandTest extends CommandTest { public function testCommand() { + if (explode('.', PHP_VERSION_ID)[0] >= 7) { + $this->markTestSkipped('Skip APC test w/ php7'); + } $this->assertHasApc(); $this->assertNoHHVM(); diff --git a/tests/CacheTool/Command/ApcCacheClearCommandTest.php b/tests/CacheTool/Command/ApcCacheClearCommandTest.php index e516806..0e47ed9 100644 --- a/tests/CacheTool/Command/ApcCacheClearCommandTest.php +++ b/tests/CacheTool/Command/ApcCacheClearCommandTest.php @@ -6,6 +6,9 @@ class ApcCacheClearCommandTest extends CommandTest { public function testCommand() { + if (explode('.', PHP_VERSION_ID)[0] >= 7) { + $this->markTestSkipped('Skip APC test w/ php7'); + } $this->assertHasApc(); $result = $this->runCommand('apc:cache:clear all -v'); @@ -16,6 +19,9 @@ public function testCommand() public function testCommandUser() { + if (explode('.', PHP_VERSION_ID)[0] >= 7) { + $this->markTestSkipped('Skip APC test w/ php7'); + } $this->assertHasApc(); $result = $this->runCommand('apc:cache:clear user -v'); @@ -25,6 +31,9 @@ public function testCommandUser() public function testException() { + if (explode('.', PHP_VERSION_ID)[0] >= 7) { + $this->markTestSkipped('Skip APC test w/ php7'); + } $this->assertHasApc(); $result = $this->runCommand('apc:cache:clear err -v'); diff --git a/tests/CacheTool/Command/ApcCacheInfoCommandTest.php b/tests/CacheTool/Command/ApcCacheInfoCommandTest.php index d3f9fbf..5f9ab64 100644 --- a/tests/CacheTool/Command/ApcCacheInfoCommandTest.php +++ b/tests/CacheTool/Command/ApcCacheInfoCommandTest.php @@ -6,6 +6,9 @@ class ApcCacheInfoCommandTest extends CommandTest { public function testCommand() { + if (explode('.', PHP_VERSION_ID)[0] >= 7) { + $this->markTestSkipped('Skip APC test w/ php7'); + } $this->assertHasApc(); $result = $this->runCommand('apc:cache:info'); diff --git a/tests/CacheTool/Command/ApcCacheInfoFileCommandTest.php b/tests/CacheTool/Command/ApcCacheInfoFileCommandTest.php index 7e130b1..8e70d3a 100644 --- a/tests/CacheTool/Command/ApcCacheInfoFileCommandTest.php +++ b/tests/CacheTool/Command/ApcCacheInfoFileCommandTest.php @@ -6,6 +6,9 @@ class ApcCacheInfoFileCommandTest extends CommandTest { public function testCommand() { + if (explode('.', PHP_VERSION_ID)[0] >= 7) { + $this->markTestSkipped('Skip APC test w/ php7'); + } $this->assertHasApc(); $result = $this->runCommand('apc:cache:info:file -v'); diff --git a/tests/CacheTool/Command/ApcKeyDeleteCommandTest.php b/tests/CacheTool/Command/ApcKeyDeleteCommandTest.php index 594c1e8..1b79e16 100644 --- a/tests/CacheTool/Command/ApcKeyDeleteCommandTest.php +++ b/tests/CacheTool/Command/ApcKeyDeleteCommandTest.php @@ -6,6 +6,9 @@ class ApcKeyDeleteCommandTest extends CommandTest { public function testCommand() { + if (explode('.', PHP_VERSION_ID)[0] >= 7) { + $this->markTestSkipped('Skip APC test w/ php7'); + } $this->assertHasApc(); $result = $this->runCommand('apc:key:delete key -v'); diff --git a/tests/CacheTool/Command/ApcKeyExistsCommandTest.php b/tests/CacheTool/Command/ApcKeyExistsCommandTest.php index 82d3295..b8ba45a 100644 --- a/tests/CacheTool/Command/ApcKeyExistsCommandTest.php +++ b/tests/CacheTool/Command/ApcKeyExistsCommandTest.php @@ -6,6 +6,9 @@ class ApcKeyExistsCommandTest extends CommandTest { public function testCommand() { + if (explode('.', PHP_VERSION_ID)[0] >= 7) { + $this->markTestSkipped('Skip APC test w/ php7'); + } $this->assertHasApc(); $result = $this->runCommand('apc:key:exists key -v'); diff --git a/tests/CacheTool/Command/ApcKeyFetchCommandTest.php b/tests/CacheTool/Command/ApcKeyFetchCommandTest.php index 64bbc90..53a1931 100644 --- a/tests/CacheTool/Command/ApcKeyFetchCommandTest.php +++ b/tests/CacheTool/Command/ApcKeyFetchCommandTest.php @@ -6,6 +6,9 @@ class ApcKeyFetchCommandTest extends CommandTest { public function testCommand() { + if (explode('.', PHP_VERSION_ID)[0] >= 7) { + $this->markTestSkipped('Skip APC test w/ php7'); + } $this->assertHasApc(); $result = $this->runCommand('apc:key:fetch key -v'); diff --git a/tests/CacheTool/Command/ApcKeyStoreCommandTest.php b/tests/CacheTool/Command/ApcKeyStoreCommandTest.php index b920c98..7b1496f 100644 --- a/tests/CacheTool/Command/ApcKeyStoreCommandTest.php +++ b/tests/CacheTool/Command/ApcKeyStoreCommandTest.php @@ -6,6 +6,9 @@ class ApcKeyStoreCommandTest extends CommandTest { public function testCommand() { + if (explode('.', PHP_VERSION_ID)[0] >= 7) { + $this->markTestSkipped('Skip APC test w/ php7'); + } $this->assertHasApc(); $result = $this->runCommand('apc:key:store key value 3600 -v'); diff --git a/tests/CacheTool/Command/ApcSmaInfoCommandTest.php b/tests/CacheTool/Command/ApcSmaInfoCommandTest.php index 8fa0a59..ca9d482 100644 --- a/tests/CacheTool/Command/ApcSmaInfoCommandTest.php +++ b/tests/CacheTool/Command/ApcSmaInfoCommandTest.php @@ -6,6 +6,9 @@ class ApcSmaInfoCommandTest extends CommandTest { public function testCommand() { + if (explode('.', PHP_VERSION_ID)[0] >= 7) { + $this->markTestSkipped('Skip APC test w/ php7'); + } $this->assertHasApc(); $result = $this->runCommand('apc:sma:info -v'); From eee64b8752bd001b99b329a6685450a75f07300a Mon Sep 17 00:00:00 2001 From: Jerome Bourgeais Date: Tue, 7 Mar 2017 17:06:42 +0100 Subject: [PATCH 2/3] Changes following @Seldaek's CR --- src/CacheTool/Adapter/FastCGI.php | 7 +++++-- tests/CacheTool/Command/ApcBinDumpCommandTest.php | 4 ++-- tests/CacheTool/Command/ApcBinLoadCommandTest.php | 2 +- tests/CacheTool/Command/ApcCacheClearCommandTest.php | 6 +++--- tests/CacheTool/Command/ApcCacheInfoCommandTest.php | 2 +- tests/CacheTool/Command/ApcCacheInfoFileCommandTest.php | 2 +- tests/CacheTool/Command/ApcKeyDeleteCommandTest.php | 2 +- tests/CacheTool/Command/ApcKeyExistsCommandTest.php | 2 +- tests/CacheTool/Command/ApcKeyFetchCommandTest.php | 2 +- tests/CacheTool/Command/ApcKeyStoreCommandTest.php | 2 +- tests/CacheTool/Command/ApcSmaInfoCommandTest.php | 2 +- 11 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/CacheTool/Adapter/FastCGI.php b/src/CacheTool/Adapter/FastCGI.php index d255a3c..70546c5 100644 --- a/src/CacheTool/Adapter/FastCGI.php +++ b/src/CacheTool/Adapter/FastCGI.php @@ -21,9 +21,12 @@ class FastCGI extends AbstractAdapter */ protected $client; + /** + * @var Array of patterns matching php socket files + */ protected $possibleSocketFiles = [ - '/var/run/php5-fpm.sock', - '/var/run/php/php7.0-fpm.sock' + '/var/run/php*.sock', + '/var/run/php/*.sock' ]; /** diff --git a/tests/CacheTool/Command/ApcBinDumpCommandTest.php b/tests/CacheTool/Command/ApcBinDumpCommandTest.php index 083cb99..f9ff39b 100644 --- a/tests/CacheTool/Command/ApcBinDumpCommandTest.php +++ b/tests/CacheTool/Command/ApcBinDumpCommandTest.php @@ -6,7 +6,7 @@ class ApcBinDumpCommandTest extends CommandTest { public function testCommand() { - if (explode('.', PHP_VERSION_ID)[0] >= 7) { + if (PHP_VERSION_ID >= 70000) { $this->markTestSkipped('Skip APC test w/ php7'); } $this->assertHasApc(); @@ -21,7 +21,7 @@ public function testCommand() public function testCommandWithFile() { - if (explode('.', PHP_VERSION_ID)[0] >= 7) { + if (PHP_VERSION_ID >= 70000) { $this->markTestSkipped('Skip APC test w/ php7'); } $this->assertHasApc(); diff --git a/tests/CacheTool/Command/ApcBinLoadCommandTest.php b/tests/CacheTool/Command/ApcBinLoadCommandTest.php index 64122ea..502b007 100644 --- a/tests/CacheTool/Command/ApcBinLoadCommandTest.php +++ b/tests/CacheTool/Command/ApcBinLoadCommandTest.php @@ -6,7 +6,7 @@ class ApcBinLoadCommandTest extends CommandTest { public function testCommand() { - if (explode('.', PHP_VERSION_ID)[0] >= 7) { + if (PHP_VERSION_ID >= 70000) { $this->markTestSkipped('Skip APC test w/ php7'); } $this->assertHasApc(); diff --git a/tests/CacheTool/Command/ApcCacheClearCommandTest.php b/tests/CacheTool/Command/ApcCacheClearCommandTest.php index 0e47ed9..a796267 100644 --- a/tests/CacheTool/Command/ApcCacheClearCommandTest.php +++ b/tests/CacheTool/Command/ApcCacheClearCommandTest.php @@ -6,7 +6,7 @@ class ApcCacheClearCommandTest extends CommandTest { public function testCommand() { - if (explode('.', PHP_VERSION_ID)[0] >= 7) { + if (PHP_VERSION_ID >= 70000) { $this->markTestSkipped('Skip APC test w/ php7'); } $this->assertHasApc(); @@ -19,7 +19,7 @@ public function testCommand() public function testCommandUser() { - if (explode('.', PHP_VERSION_ID)[0] >= 7) { + if (PHP_VERSION_ID >= 70000) { $this->markTestSkipped('Skip APC test w/ php7'); } $this->assertHasApc(); @@ -31,7 +31,7 @@ public function testCommandUser() public function testException() { - if (explode('.', PHP_VERSION_ID)[0] >= 7) { + if (PHP_VERSION_ID >= 70000) { $this->markTestSkipped('Skip APC test w/ php7'); } $this->assertHasApc(); diff --git a/tests/CacheTool/Command/ApcCacheInfoCommandTest.php b/tests/CacheTool/Command/ApcCacheInfoCommandTest.php index 5f9ab64..7001507 100644 --- a/tests/CacheTool/Command/ApcCacheInfoCommandTest.php +++ b/tests/CacheTool/Command/ApcCacheInfoCommandTest.php @@ -6,7 +6,7 @@ class ApcCacheInfoCommandTest extends CommandTest { public function testCommand() { - if (explode('.', PHP_VERSION_ID)[0] >= 7) { + if (PHP_VERSION_ID >= 70000) { $this->markTestSkipped('Skip APC test w/ php7'); } $this->assertHasApc(); diff --git a/tests/CacheTool/Command/ApcCacheInfoFileCommandTest.php b/tests/CacheTool/Command/ApcCacheInfoFileCommandTest.php index 8e70d3a..53a9c32 100644 --- a/tests/CacheTool/Command/ApcCacheInfoFileCommandTest.php +++ b/tests/CacheTool/Command/ApcCacheInfoFileCommandTest.php @@ -6,7 +6,7 @@ class ApcCacheInfoFileCommandTest extends CommandTest { public function testCommand() { - if (explode('.', PHP_VERSION_ID)[0] >= 7) { + if (PHP_VERSION_ID >= 70000) { $this->markTestSkipped('Skip APC test w/ php7'); } $this->assertHasApc(); diff --git a/tests/CacheTool/Command/ApcKeyDeleteCommandTest.php b/tests/CacheTool/Command/ApcKeyDeleteCommandTest.php index 1b79e16..59e5e1c 100644 --- a/tests/CacheTool/Command/ApcKeyDeleteCommandTest.php +++ b/tests/CacheTool/Command/ApcKeyDeleteCommandTest.php @@ -6,7 +6,7 @@ class ApcKeyDeleteCommandTest extends CommandTest { public function testCommand() { - if (explode('.', PHP_VERSION_ID)[0] >= 7) { + if (PHP_VERSION_ID >= 70000) { $this->markTestSkipped('Skip APC test w/ php7'); } $this->assertHasApc(); diff --git a/tests/CacheTool/Command/ApcKeyExistsCommandTest.php b/tests/CacheTool/Command/ApcKeyExistsCommandTest.php index b8ba45a..7b77c12 100644 --- a/tests/CacheTool/Command/ApcKeyExistsCommandTest.php +++ b/tests/CacheTool/Command/ApcKeyExistsCommandTest.php @@ -6,7 +6,7 @@ class ApcKeyExistsCommandTest extends CommandTest { public function testCommand() { - if (explode('.', PHP_VERSION_ID)[0] >= 7) { + if (PHP_VERSION_ID >= 70000) { $this->markTestSkipped('Skip APC test w/ php7'); } $this->assertHasApc(); diff --git a/tests/CacheTool/Command/ApcKeyFetchCommandTest.php b/tests/CacheTool/Command/ApcKeyFetchCommandTest.php index 53a1931..fe3cd23 100644 --- a/tests/CacheTool/Command/ApcKeyFetchCommandTest.php +++ b/tests/CacheTool/Command/ApcKeyFetchCommandTest.php @@ -6,7 +6,7 @@ class ApcKeyFetchCommandTest extends CommandTest { public function testCommand() { - if (explode('.', PHP_VERSION_ID)[0] >= 7) { + if (PHP_VERSION_ID >= 70000) { $this->markTestSkipped('Skip APC test w/ php7'); } $this->assertHasApc(); diff --git a/tests/CacheTool/Command/ApcKeyStoreCommandTest.php b/tests/CacheTool/Command/ApcKeyStoreCommandTest.php index 7b1496f..42eafb5 100644 --- a/tests/CacheTool/Command/ApcKeyStoreCommandTest.php +++ b/tests/CacheTool/Command/ApcKeyStoreCommandTest.php @@ -6,7 +6,7 @@ class ApcKeyStoreCommandTest extends CommandTest { public function testCommand() { - if (explode('.', PHP_VERSION_ID)[0] >= 7) { + if (PHP_VERSION_ID >= 70000) { $this->markTestSkipped('Skip APC test w/ php7'); } $this->assertHasApc(); diff --git a/tests/CacheTool/Command/ApcSmaInfoCommandTest.php b/tests/CacheTool/Command/ApcSmaInfoCommandTest.php index ca9d482..b4a126c 100644 --- a/tests/CacheTool/Command/ApcSmaInfoCommandTest.php +++ b/tests/CacheTool/Command/ApcSmaInfoCommandTest.php @@ -6,7 +6,7 @@ class ApcSmaInfoCommandTest extends CommandTest { public function testCommand() { - if (explode('.', PHP_VERSION_ID)[0] >= 7) { + if (PHP_VERSION_ID >= 70000) { $this->markTestSkipped('Skip APC test w/ php7'); } $this->assertHasApc(); From c405f12931b71dc95fbbab253a5b61476af7c30a Mon Sep 17 00:00:00 2001 From: Jerome Bourgeais Date: Tue, 7 Mar 2017 17:16:51 +0100 Subject: [PATCH 3/3] glob pattern to get the 1st matching socket file --- src/CacheTool/Adapter/FastCGI.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/CacheTool/Adapter/FastCGI.php b/src/CacheTool/Adapter/FastCGI.php index 70546c5..28c3b4c 100644 --- a/src/CacheTool/Adapter/FastCGI.php +++ b/src/CacheTool/Adapter/FastCGI.php @@ -24,7 +24,7 @@ class FastCGI extends AbstractAdapter /** * @var Array of patterns matching php socket files */ - protected $possibleSocketFiles = [ + protected $possibleSocketFilePatterns = [ '/var/run/php*.sock', '/var/run/php/*.sock' ]; @@ -42,7 +42,8 @@ public function __construct($host = null, $tempDir = null) { // try to guess where it is if ($host === null) { - foreach ($this->possibleSocketFiles as $possibleSocketFile) { + foreach ($this->possibleSocketFilePatterns as $possibleSocketFilePattern) { + $possibleSocketFile = current(glob($possibleSocketFilePattern)); if (file_exists($possibleSocketFile)) { $host = $possibleSocketFile; break;