From ba6e94f6a9dea37174d3d10b3275585d5959234c Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 22 Sep 2023 06:10:04 +0200 Subject: [PATCH] Whip_Requirement: be explicit about all expected methods The `Whip_RequirementsChecker::requirementIsFulfilled()` method makes unconditional calls to the `version()` and `operator()` methods on an object implementing `Whip_Requirement`, so these methods ought to be made explicitly required for classes implementing the `Whip_Requirement` interface. Fixed now. Includes updating some tests to match. Note: this change may warrant a new major release! --- src/interfaces/Whip_Requirement.php | 14 ++++++++++++++ tests/ConfigurationTest.php | 8 ++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/interfaces/Whip_Requirement.php b/src/interfaces/Whip_Requirement.php index f03f42f..e653956 100644 --- a/src/interfaces/Whip_Requirement.php +++ b/src/interfaces/Whip_Requirement.php @@ -16,4 +16,18 @@ interface Whip_Requirement { * @return string The component name. */ public function component(); + + /** + * Gets the components version defined for the requirement. + * + * @return string + */ + public function version(); + + /** + * Gets the operator to use when comparing version numbers. + * + * @return string The comparison operator. + */ + public function operator(); } diff --git a/tests/ConfigurationTest.php b/tests/ConfigurationTest.php index 95eff57..32d21f8 100644 --- a/tests/ConfigurationTest.php +++ b/tests/ConfigurationTest.php @@ -33,7 +33,7 @@ public function testItThrowsAnErrorIfAFaultyConfigurationIsPassed() { public function testItReturnsANegativeNumberIfRequirementCannotBeFound() { $configuration = new Whip_Configuration( array( 'php' => '5.6' ) ); $requirement = $this->getMockBuilder( 'Whip_Requirement' ) - ->setMethods( array( 'component' ) ) + ->setMethods( array( 'component', 'version', 'operator' ) ) ->getMock(); $requirement @@ -54,7 +54,7 @@ public function testItReturnsANegativeNumberIfRequirementCannotBeFound() { public function testItReturnsAnEntryIfRequirementIsFound() { $configuration = new Whip_Configuration( array( 'php' => '5.6' ) ); $requirement = $this->getMockBuilder( 'Whip_Requirement' ) - ->setMethods( array( 'component' ) ) + ->setMethods( array( 'component', 'version', 'operator' ) ) ->getMock(); $requirement @@ -75,7 +75,7 @@ public function testItReturnsAnEntryIfRequirementIsFound() { public function testIfRequirementIsConfigured() { $configuration = new Whip_Configuration( array( 'php' => '5.6' ) ); $requirement = $this->getMockBuilder( 'Whip_Requirement' ) - ->setMethods( array( 'component' ) ) + ->setMethods( array( 'component', 'version', 'operator' ) ) ->getMock(); $requirement @@ -84,7 +84,7 @@ public function testIfRequirementIsConfigured() { ->will( $this->returnValue( 'php' ) ); $falseRequirement = $this->getMockBuilder( 'Whip_Requirement' ) - ->setMethods( array( 'component' ) ) + ->setMethods( array( 'component', 'version', 'operator' ) ) ->getMock(); $falseRequirement