Skip to content

Commit

Permalink
Whip_Requirement: be explicit about all expected methods
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
jrfnl committed Sep 26, 2023
1 parent 9efacd2 commit ba6e94f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/interfaces/Whip_Requirement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
8 changes: 4 additions & 4 deletions tests/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ba6e94f

Please sign in to comment.