Skip to content

Commit

Permalink
Ref #16332 - Remove more ->at matcher calls
Browse files Browse the repository at this point in the history
Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed Mar 5, 2021
1 parent ad0ef8b commit feb7c8b
Showing 1 changed file with 64 additions and 46 deletions.
110 changes: 64 additions & 46 deletions test/classes/VersionInformationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function dataVersions(): array
}

/**
* Tests getLatestCompatibleVersion() when there is only one server confgiured
* Tests getLatestCompatibleVersion() when there is only one server configured
*/
public function testGetLatestCompatibleVersionWithSingleServer(): void
{
Expand All @@ -178,21 +178,34 @@ public function testGetLatestCompatibleVersionWithSingleServer(): void
->onlyMethods(['evaluateVersionCondition'])
->getMock();

$mockVersionInfo->expects($this->at(0))
$mockVersionInfo->expects($this->exactly(9))
->method('evaluateVersionCondition')
->with('PHP', '>=5.3')
->will($this->returnValue(true));

$mockVersionInfo->expects($this->at(1))
->method('evaluateVersionCondition')
->with('PHP', '<7.1')
->will($this->returnValue(true));

$mockVersionInfo->expects($this->at(2))
->method('evaluateVersionCondition')
->with('MySQL', '>=5.5')
->will($this->returnValue(true));
->withConsecutive(
['PHP', '>=5.3'],
['PHP', '<7.1'],
['MySQL', '>=5.5'],

['PHP', '>=5.3'],
['PHP', '<7.0'],
['MySQL', '>=5.5'],

['PHP', '>=5.2'],
['PHP', '<5.3'],
['MySQL', '>=5.0']
)
->willReturnOnConsecutiveCalls(
true,
true,
true,
true,
true,
true,
true,
true,
true
);

/** @var VersionInformation $mockVersionInfo */
$compatible = $mockVersionInfo->getLatestCompatibleVersion($this->releases);
$this->assertIsArray($compatible);
$this->assertEquals('4.4.14.1', $compatible['version']);
Expand All @@ -212,16 +225,18 @@ public function testGetLatestCompatibleVersionWithMultipleServers(): void
->onlyMethods(['evaluateVersionCondition'])
->getMock();

$mockVersionInfo->expects($this->at(0))
$mockVersionInfo->expects($this->atLeast(4))
->method('evaluateVersionCondition')
->with('PHP', '>=5.3')
->will($this->returnValue(true));

$mockVersionInfo->expects($this->at(1))
->method('evaluateVersionCondition')
->with('PHP', '<7.1')
->will($this->returnValue(true));
->withConsecutive(
['PHP', '>=5.3'],
['PHP', '<7.1']
)
->willReturnOnConsecutiveCalls(
true,
true
);

/** @var VersionInformation $mockVersionInfo */
$compatible = $mockVersionInfo->getLatestCompatibleVersion($this->releases);
$this->assertIsArray($compatible);
$this->assertEquals('4.4.14.1', $compatible['version']);
Expand All @@ -241,26 +256,22 @@ public function testGetLatestCompatibleVersionWithOldPHPVersion(): void
->onlyMethods(['evaluateVersionCondition'])
->getMock();

$mockVersionInfo->expects($this->at(0))
$mockVersionInfo->expects($this->atLeast(2))
->method('evaluateVersionCondition')
->with('PHP', '>=5.3')
->will($this->returnValue(false));

$mockVersionInfo->expects($this->at(1))
->method('evaluateVersionCondition')
->with('PHP', '>=5.3')
->will($this->returnValue(false));

$mockVersionInfo->expects($this->at(2))
->method('evaluateVersionCondition')
->with('PHP', '>=5.2')
->will($this->returnValue(true));

$mockVersionInfo->expects($this->at(3))
->method('evaluateVersionCondition')
->with('PHP', '<5.3')
->will($this->returnValue(true));
->withConsecutive(
['PHP', '>=5.3'],
['PHP', '>=5.3'],
['PHP', '>=5.2'],
['PHP', '<5.3']
)
->willReturnOnConsecutiveCalls(
false,
false,
true,
true
);

/** @var VersionInformation $mockVersionInfo */
$compatible = $mockVersionInfo->getLatestCompatibleVersion($this->releases);
$this->assertIsArray($compatible);
$this->assertEquals('4.0.10.10', $compatible['version']);
Expand All @@ -286,18 +297,24 @@ public function testGetLatestCompatibleVersionWithNewPHPVersion(
->onlyMethods(['evaluateVersionCondition'])
->getMock();

$i = 0;
$conditionsCalls = [];
$returnValues = [];
foreach ($conditions as $conditionArray) {
[
$condition,
$returnValue,
] = $conditionArray;
$mockVersionInfo->expects($this->at($i))
->method('evaluateVersionCondition')
->with('PHP', $condition)
->will($this->returnValue($returnValue));
$i++;
$conditionsCalls[] = ['PHP', $condition];
$returnValues[] = $returnValue;
}
$mockVersionInfo->expects($this->exactly(count($conditionsCalls)))
->method('evaluateVersionCondition')
->withConsecutive(
...$conditionsCalls
)
->willReturnOnConsecutiveCalls(
...$returnValues
);

/** @var VersionInformation $mockVersionInfo */
$compatible = $mockVersionInfo->getLatestCompatibleVersion($versions);
Expand Down Expand Up @@ -558,6 +575,7 @@ public function testEvaluateVersionCondition(): void
->method('getPHPVersion')
->will($this->returnValue('5.2.4'));

/** @var VersionInformation $mockVersionInfo */
$this->assertTrue($mockVersionInfo->evaluateVersionCondition('PHP', '<=5.3'));
$this->assertTrue($mockVersionInfo->evaluateVersionCondition('PHP', '<5.3'));
$this->assertTrue($mockVersionInfo->evaluateVersionCondition('PHP', '>=5.2'));
Expand Down

0 comments on commit feb7c8b

Please sign in to comment.