From ce4113fd9c1d611cbfcbaadb3353de3ffe34f5a7 Mon Sep 17 00:00:00 2001 From: boite Date: Sat, 12 Nov 2016 16:28:11 +0000 Subject: [PATCH] Detect modules by the .load config extension. --- src/Command/AbstractApacheCommand.php | 8 +++--- src/Command/ApacheModuleDisableCommand.php | 4 +-- src/Command/ApacheModuleEnableCommand.php | 4 +-- src/Util/Normaliser.php | 14 +++++----- .../ApacheModuleDisableCommandTest.php | 22 ++++++++-------- .../Command/ApacheModuleEnableCommandTest.php | 26 +++++++++---------- test/Util/NormaliserTest.php | 12 +++++++++ 7 files changed, 52 insertions(+), 38 deletions(-) diff --git a/src/Command/AbstractApacheCommand.php b/src/Command/AbstractApacheCommand.php index 0a1e85d..76c2e56 100644 --- a/src/Command/AbstractApacheCommand.php +++ b/src/Command/AbstractApacheCommand.php @@ -28,14 +28,14 @@ public function __construct( abstract protected function getEnabledDir(); abstract protected function getAvailableDir(); - protected function getConfName($argument) + protected function getConfName($argument, $extension = '.conf') { - return $this->normaliser->normaliseConfName($argument); + return $this->normaliser->normaliseConfName($argument, $extension); } - protected function getConfFilename($argument) + protected function getConfFilename($argument, $extension = '.conf') { - return $this->normaliser->normaliseConfFilename($argument); + return $this->normaliser->normaliseConfFilename($argument, $extension); } protected function available($confFilename) diff --git a/src/Command/ApacheModuleDisableCommand.php b/src/Command/ApacheModuleDisableCommand.php index 90ca0ea..57ffb6d 100644 --- a/src/Command/ApacheModuleDisableCommand.php +++ b/src/Command/ApacheModuleDisableCommand.php @@ -35,8 +35,8 @@ public function execute(InputInterface $input, OutputInterface $output) { $this->activateCheckMode($input); - $confname = $this->getConfName($input->getArgument('module-name')); - $confFilename = $this->getConfFilename($input->getArgument('module-name')); + $confname = $this->getConfName($input->getArgument('module-name'), '.load'); + $confFilename = $this->getConfFilename($input->getArgument('module-name'), '.load'); if (! $this->available($confFilename)) { throw new RuntimeException( diff --git a/src/Command/ApacheModuleEnableCommand.php b/src/Command/ApacheModuleEnableCommand.php index e60d1ad..28f110a 100644 --- a/src/Command/ApacheModuleEnableCommand.php +++ b/src/Command/ApacheModuleEnableCommand.php @@ -35,8 +35,8 @@ public function execute(InputInterface $input, OutputInterface $output) { $this->activateCheckMode($input); - $confname = $this->getConfName($input->getArgument('module-name')); - $confFilename = $this->getConfFilename($input->getArgument('module-name')); + $confname = $this->getConfName($input->getArgument('module-name'), '.load'); + $confFilename = $this->getConfFilename($input->getArgument('module-name'), '.load'); if (! $this->available($confFilename)) { throw new RuntimeException( diff --git a/src/Util/Normaliser.php b/src/Util/Normaliser.php index 27e6c40..3779dc2 100644 --- a/src/Util/Normaliser.php +++ b/src/Util/Normaliser.php @@ -4,18 +4,20 @@ class Normaliser { - public function normaliseConfName($confName) + public function normaliseConfName($confName, $extension = '.conf') { - if (substr($confName, -5, 5) === '.conf') { - return substr($confName, 0, -5); + $ext_len = strlen($extension); + if (substr($confName, 0-$ext_len, $ext_len) === $extension) { + return substr($confName, 0, 0-$ext_len); } return $confName; } - public function normaliseConfFilename($confName) + public function normaliseConfFilename($confName, $extension = '.conf') { - if (substr($confName, -5, 5) != '.conf') { - return $confName . '.conf'; + $ext_len = strlen($extension); + if (substr($confName, 0-$ext_len, $ext_len) != $extension) { + return $confName . $extension; } return $confName; } diff --git a/test/Command/ApacheModuleDisableCommandTest.php b/test/Command/ApacheModuleDisableCommandTest.php index ce03b9a..75f31d2 100644 --- a/test/Command/ApacheModuleDisableCommandTest.php +++ b/test/Command/ApacheModuleDisableCommandTest.php @@ -74,7 +74,7 @@ public function testApacheModDisableThrowsRuntimeExceptionWithUnknownModule() 'stat', '-c', '%F', - '/etc/apache2/mods-available/not_a_module.conf', + '/etc/apache2/mods-available/not_a_module.load', ) ) ; @@ -108,13 +108,13 @@ public function testApacheModDisableExitsWhenModuleIsAlreadyDisabled() 'stat', '-c', '%F', - '/etc/apache2/mods-available/a_module.conf', + '/etc/apache2/mods-available/a_module.load', )), array(array( 'stat', '-c', '%F', - '/etc/apache2/mods-enabled/a_module.conf', + '/etc/apache2/mods-enabled/a_module.load', )) ) ; @@ -164,17 +164,17 @@ public function testApacheModDisableThrowsRuntimeExceptionWhenFailsToDisable() 'stat', '-c', '%F', - '/etc/apache2/mods-available/a_module.conf', + '/etc/apache2/mods-available/a_module.load', )), array(array( 'stat', '-c', '%F', - '/etc/apache2/mods-enabled/a_module.conf', + '/etc/apache2/mods-enabled/a_module.load', )), array(array( 'unlink', - '/etc/apache2/mods-enabled/a_module.conf', + '/etc/apache2/mods-enabled/a_module.load', )) ) ; @@ -214,17 +214,17 @@ public function testApacheModDisableWillDisableEnabledModule() 'stat', '-c', '%F', - '/etc/apache2/mods-available/a_module.conf', + '/etc/apache2/mods-available/a_module.load', )), array(array( 'stat', '-c', '%F', - '/etc/apache2/mods-enabled/a_module.conf', + '/etc/apache2/mods-enabled/a_module.load', )), array(array( 'unlink', - '/etc/apache2/mods-enabled/a_module.conf', + '/etc/apache2/mods-enabled/a_module.load', )) ) ; @@ -270,13 +270,13 @@ public function testApacheModDisableWillReportOnlyInCheckMode() 'stat', '-c', '%F', - '/etc/apache2/mods-available/a_module.conf' + '/etc/apache2/mods-available/a_module.load' )), array(array( 'stat', '-c', '%F', - '/etc/apache2/mods-enabled/a_module.conf' + '/etc/apache2/mods-enabled/a_module.load' )) ) ; diff --git a/test/Command/ApacheModuleEnableCommandTest.php b/test/Command/ApacheModuleEnableCommandTest.php index 48ea02f..d288e6f 100644 --- a/test/Command/ApacheModuleEnableCommandTest.php +++ b/test/Command/ApacheModuleEnableCommandTest.php @@ -74,7 +74,7 @@ public function testApacheModEnableThrowsRuntimeExceptionWithUnknownModule() 'stat', '-c', '%F', - '/etc/apache2/mods-available/not_a_module.conf' + '/etc/apache2/mods-available/not_a_module.load' ) ) ; @@ -108,13 +108,13 @@ public function testApacheModEnableExitsWhenModuleIsAlreadyEnabled() 'stat', '-c', '%F', - '/etc/apache2/mods-available/a_module.conf', + '/etc/apache2/mods-available/a_module.load', )), array(array( 'stat', '-c', '%F', - '/etc/apache2/mods-enabled/a_module.conf', + '/etc/apache2/mods-enabled/a_module.load', )) ) ; @@ -164,19 +164,19 @@ public function testApacheModEnableThrowsRuntimeExceptionWhenFailsToEnable() 'stat', '-c', '%F', - '/etc/apache2/mods-available/a_module.conf', + '/etc/apache2/mods-available/a_module.load', )), array(array( 'stat', '-c', '%F', - '/etc/apache2/mods-enabled/a_module.conf', + '/etc/apache2/mods-enabled/a_module.load', )), array(array( 'ln', '-s', - '/etc/apache2/mods-available/a_module.conf', - '/etc/apache2/mods-enabled/a_module.conf', + '/etc/apache2/mods-available/a_module.load', + '/etc/apache2/mods-enabled/a_module.load', )) ) ; @@ -216,19 +216,19 @@ public function testApacheModEnableWillEnableDisabledModule() 'stat', '-c', '%F', - '/etc/apache2/mods-available/a_module.conf', + '/etc/apache2/mods-available/a_module.load', )), array(array( 'stat', '-c', '%F', - '/etc/apache2/mods-enabled/a_module.conf', + '/etc/apache2/mods-enabled/a_module.load', )), array(array( 'ln', '-s', - '/etc/apache2/mods-available/a_module.conf', - '/etc/apache2/mods-enabled/a_module.conf', + '/etc/apache2/mods-available/a_module.load', + '/etc/apache2/mods-enabled/a_module.load', )) ) ; @@ -274,13 +274,13 @@ public function testApacheModEnableWillReportOnlyInCheckMode() 'stat', '-c', '%F', - '/etc/apache2/mods-available/a_module.conf', + '/etc/apache2/mods-available/a_module.load', )), array(array( 'stat', '-c', '%F', - '/etc/apache2/mods-enabled/a_module.conf', + '/etc/apache2/mods-enabled/a_module.load', )) ) ; diff --git a/test/Util/NormaliserTest.php b/test/Util/NormaliserTest.php index b7283a1..1cc34be 100644 --- a/test/Util/NormaliserTest.php +++ b/test/Util/NormaliserTest.php @@ -19,6 +19,10 @@ public function testNormaliseConfNameStripsExtension() 'foo_module', $this->norm->normaliseConfName('foo_module.conf') ); + $this->assertSame( + 'foo_module', + $this->norm->normaliseConfName('foo_module.extension', '.extension') + ); $this->assertSame( 'foo_module', $this->norm->normaliseConfName('foo_module') @@ -31,9 +35,17 @@ public function testNormaliseConfFilenameAddsExtension() 'foo_module.conf', $this->norm->normaliseConfFilename('foo_module') ); + $this->assertSame( + 'foo_module.extension', + $this->norm->normaliseConfFilename('foo_module', '.extension') + ); $this->assertSame( 'foo_module.conf', $this->norm->normaliseConfFilename('foo_module.conf') ); + $this->assertSame( + 'foo_module.extension', + $this->norm->normaliseConfFilename('foo_module.extension', '.extension') + ); } }