Skip to content

Commit

Permalink
loosen tests
Browse files Browse the repository at this point in the history
`assertSame()` is a strict comparison, while `assertEquals()` allows for these two to be pass:

```
['test-bzmpop' => ['member3' => '3', 'member2' => '2']],
['test-bzmpop' => ['member3' => 3.0, 'member2' => 2.0]]
```
  • Loading branch information
tillkruss committed Feb 24, 2023
1 parent 7c92c6a commit 1fbbe1f
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 28 deletions.
3 changes: 1 addition & 2 deletions tests/Predis/Command/Redis/BZMPOP_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public function testParseResponse(array $actualResponse, array $expectedResponse

/**
* @group connected
* @group relay-float
* @dataProvider sortedSetsProvider
* @param int $timeout
* @param array $sortedSetDictionary
Expand All @@ -82,7 +81,7 @@ public function testReturnsPoppedElementsFromGivenSortedSet(
$redis->zadd($key, ...$sortedSetDictionary);
$actualResponse = $redis->bzmpop($timeout, [$key], $modifier, $count);

$this->assertSame($expectedResponse, $actualResponse);
$this->assertEquals($expectedResponse, $actualResponse);
$this->assertSame($expectedModifiedSortedSet, $redis->zrange($key, 0, -1));
}

Expand Down
3 changes: 1 addition & 2 deletions tests/Predis/Command/Redis/BZPOPMAX_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ protected function getExpectedId(): string

/**
* @group connected
* @group relay-float
* @return void
* @requiresRedisVersion >= 5.0.0
*/
Expand All @@ -48,7 +47,7 @@ public function testReturnsPoppedMaxElementFromGivenNonEmptySortedSet(): void

$redis->zadd('test-bzpopmax', ...$sortedSetDictionary);

$this->assertSame($expectedResponse, $redis->bzpopmax(['empty sorted set', 'test-bzpopmax'], 0));
$this->assertEquals($expectedResponse, $redis->bzpopmax(['empty sorted set', 'test-bzpopmax'], 0));
$this->assertSame($expectedModifiedSortedSet, $redis->zrange('test-bzpopmax', 0, -1));
}

Expand Down
3 changes: 1 addition & 2 deletions tests/Predis/Command/Redis/BZPOPMIN_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ protected function getExpectedId(): string

/**
* @group connected
* @group relay-float
* @return void
* @requiresRedisVersion >= 5.0.0
*/
Expand All @@ -48,7 +47,7 @@ public function testReturnsPoppedMinElementFromGivenNonEmptySortedSet(): void

$redis->zadd('test-bzpopmin', ...$sortedSetDictionary);

$this->assertSame($expectedResponse, $redis->bzpopmin(['empty sorted set', 'test-bzpopmin'], 0));
$this->assertEquals($expectedResponse, $redis->bzpopmin(['empty sorted set', 'test-bzpopmin'], 0));
$this->assertSame($expectedModifiedSortedSet, $redis->zrange('test-bzpopmin', 0, -1));
}

Expand Down
9 changes: 4 additions & 5 deletions tests/Predis/Command/Redis/ZADD_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,16 @@ public function testReturnsNumberOfAddedAndUpdatedElementsWithModifierCH(): void

/**
* @group connected
* @group relay-float
* @requiresRedisVersion >= 3.0.2
*/
public function testActsLikeZINCRBYWithModifierINCR(): void
{
$redis = $this->getClient();

$this->assertSame('1', $redis->zadd('letters', 'INCR', 1, 'a'));
$this->assertSame('0', $redis->zadd('letters', 'INCR', -1, 'a'));
$this->assertSame('0.5', $redis->zadd('letters', 'INCR', 0.5, 'a'));
$this->assertSame('-10', $redis->zadd('letters', 'INCR', -10.5, 'a'));
$this->assertEquals('1', $redis->zadd('letters', 'INCR', 1, 'a'));
$this->assertEquals('0', $redis->zadd('letters', 'INCR', -1, 'a'));
$this->assertEquals('0.5', $redis->zadd('letters', 'INCR', 0.5, 'a'));
$this->assertEquals('-10', $redis->zadd('letters', 'INCR', -10.5, 'a'));
}

/**
Expand Down
9 changes: 4 additions & 5 deletions tests/Predis/Command/Redis/ZINCRBY_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,15 @@ public function testParseResponse(): void

/**
* @group connected
* @group relay-float
*/
public function testIncrementsScoreOfMemberByFloat(): void
{
$redis = $this->getClient();

$this->assertSame('1', $redis->zincrby('letters', 1, 'member'));
$this->assertSame('0', $redis->zincrby('letters', -1, 'member'));
$this->assertSame('0.5', $redis->zincrby('letters', 0.5, 'member'));
$this->assertSame('-10', $redis->zincrby('letters', -10.5, 'member'));
$this->assertEquals('1', $redis->zincrby('letters', 1, 'member'));
$this->assertEquals('0', $redis->zincrby('letters', -1, 'member'));
$this->assertEquals('0.5', $redis->zincrby('letters', 0.5, 'member'));
$this->assertEquals('-10', $redis->zincrby('letters', -10.5, 'member'));
}

/**
Expand Down
3 changes: 1 addition & 2 deletions tests/Predis/Command/Redis/ZMPOP_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public function testParseResponse(array $actualResponse, array $expectedResponse

/**
* @group connected
* @group relay-float
* @dataProvider sortedSetsProvider
* @param array $sortedSetDictionary
* @param string $key
Expand All @@ -80,7 +79,7 @@ public function testReturnsPoppedElementsFromGivenSortedSet(
$redis->zadd($key, ...$sortedSetDictionary);
$actualResponse = $redis->zmpop([$key], $modifier, $count);

$this->assertSame($expectedResponse, $actualResponse);
$this->assertEquals($expectedResponse, $actualResponse);
$this->assertSame($expectedModifiedSortedSet, $redis->zrange($key, 0, -1));
}

Expand Down
3 changes: 1 addition & 2 deletions tests/Predis/Command/Redis/ZMSCORE_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public function testParseResponse(): void

/**
* @group connected
* @group relay-float
* @dataProvider membersProvider
* @requiresRedisVersion >= 6.2.0
*/
Expand All @@ -79,7 +78,7 @@ public function testReturnsScoresAssociatedWithMembers(

$redis->zadd($key, ...$membersDictionary);

$this->assertSame($expectedResponse, $redis->zmscore($key, ...$members));
$this->assertEquals($expectedResponse, $redis->zmscore($key, ...$members));
$this->assertNull($redis->zmscore($key, $notExpectedMember)[0]);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Predis/Command/Redis/ZPOPMAX_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testParseResponse(): void

/**
* @group connected
* @group relay-float
* @group relay-todo
* @requiresRedisVersion >= 5.0.0
*/
public function testReturnsElements(): void
Expand All @@ -79,7 +79,7 @@ public function testReturnsElements(): void

$redis->zadd('letters', -10, 'a', 0, 'b', 10, 'c', 20, 'd', 20, 'e', 30, 'f');

$this->assertSame(['f' => '30'], $redis->zpopmax('letters'));
$this->assertEquals(['f' => '30'], $redis->zpopmax('letters'));
$this->assertSame(['e' => '20', 'd' => '20', 'c' => '10'], $redis->zpopmax('letters', 3));
$this->assertSame(['b' => '0', 'a' => '-10'], $redis->zpopmax('letters', 3));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Predis/Command/Redis/ZPOPMIN_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testParseResponse(): void

/**
* @group connected
* @group relay-float
* @group relay-todo
* @requiresRedisVersion >= 5.0.0
*/
public function testReturnsElements(): void
Expand All @@ -79,7 +79,7 @@ public function testReturnsElements(): void

$redis->zadd('letters', -10, 'a', 0, 'b', 10, 'c', 20, 'd', 20, 'e', 30, 'f');

$this->assertSame(['a' => '-10'], $redis->zpopmin('letters'));
$this->assertEquals(['a' => '-10'], $redis->zpopmin('letters'));
$this->assertSame(['b' => '0', 'c' => '10', 'd' => '20'], $redis->zpopmin('letters', 3));
$this->assertSame(['e' => '20', 'f' => '30'], $redis->zpopmin('letters', 3));
}
Expand Down
7 changes: 3 additions & 4 deletions tests/Predis/Command/Redis/ZSCORE_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,16 @@ public function testParseResponse(): void

/**
* @group connected
* @group relay-float
*/
public function testReturnsRank(): void
{
$redis = $this->getClient();

$redis->zadd('letters', -10, 'a', 0, 'b', 10, 'c', 20, 'd', 20, 'e', 30, 'f');

$this->assertSame('-10', $redis->zscore('letters', 'a'));
$this->assertSame('0', $redis->zscore('letters', 'b'));
$this->assertSame('20', $redis->zscore('letters', 'e'));
$this->assertEquals('-10', $redis->zscore('letters', 'a'));
$this->assertEquals('0', $redis->zscore('letters', 'b'));
$this->assertEquals('20', $redis->zscore('letters', 'e'));

$this->assertNull($redis->zscore('unknown', 'a'));
}
Expand Down

0 comments on commit 1fbbe1f

Please sign in to comment.