Skip to content

Conversation

@Naktibalda
Copy link
Member

I used $I->seeInRedis($key, $expectedValue) in my project and it failed with very disappointing message.

Cannot find key "doesnotexist" with the provided value.

I expected to see a diff between expected value and actual value, like the one displayed by seeResponseMatchesJsonType
So I implemented it myself.

Examples of output with diff:


---------
3) RedisTest: See in redis existing string with incorrect value
 Test  tests/unit/Codeception/Module/RedisTest.php:testSeeInRedisExistingStringWithIncorrectValue
Value of key "test:string" does not match expected value
- Expected | + Actual
@@ @@
-'incorrect value'
+'hello'
#1  /.../module-redis/src/Codeception/Module/Redis.php:688
#2  /.../module-redis/src/Codeception/Module/Redis.php:454
#3  /.../module-redis/tests/unit/Codeception/Module/RedisTest.php:1000
#4  /.../module-redis/vendor/bin/codecept(21) : eval()'d code:6
#5  /.../module-redis/vendor/bin/codecept:21

---------
4) RedisTest: See in redis existing list with correct value different order
 Test  tests/unit/Codeception/Module/RedisTest.php:testSeeInRedisExistingListWithCorrectValueDifferentOrder
Value of key "test:list" does not match expected value
- Expected | + Actual
@@ @@
Array (
-    0 => 'loulou'
+    0 => 'riri'
1 => 'fifi'
-    2 => 'riri'
+    2 => 'loulou'
)
#1  /.../module-redis/src/Codeception/Module/Redis.php:688
#2  /.../module-redis/src/Codeception/Module/Redis.php:454
#3  /.../module-redis/tests/unit/Codeception/Module/RedisTest.php:1021
#4  /.../module-redis/vendor/bin/codecept(21) : eval()'d code:6
#5  /.../module-redis/vendor/bin/codecept:21

---------
5) RedisTest: See in redis existing list with incorrect value
 Test  tests/unit/Codeception/Module/RedisTest.php:testSeeInRedisExistingListWithIncorrectValue
Value of key "test:list" does not match expected value
- Expected | + Actual
@@ @@
Array (
-    0 => 'incorrect'
-    1 => 'value'
+    0 => 'riri'
+    1 => 'fifi'
+    2 => 'loulou'
)
#1  /.../module-redis/src/Codeception/Module/Redis.php:688
#2  /.../module-redis/src/Codeception/Module/Redis.php:454
#3  /.../module-redis/tests/unit/Codeception/Module/RedisTest.php:1030
#4  /.../module-redis/vendor/bin/codecept(21) : eval()'d code:6
#5  /.../module-redis/vendor/bin/codecept:21

---------
6) RedisTest: See in redis existing set with incorrect value
 Test  tests/unit/Codeception/Module/RedisTest.php:testSeeInRedisExistingSetWithIncorrectValue
Value of key "test:set" does not match expected value
- Expected | + Actual
@@ @@
Array (
-    0 => 'incorrect'
-    1 => 'value'
+    0 => 'dewey'
+    1 => 'huey'
+    2 => 'louie'
)
#1  /.../module-redis/src/Codeception/Module/Redis.php:688
#2  /.../module-redis/src/Codeception/Module/Redis.php:454
#3  /.../module-redis/tests/unit/Codeception/Module/RedisTest.php:1059
#4  /.../module-redis/vendor/bin/codecept(21) : eval()'d code:6
#5  /.../module-redis/vendor/bin/codecept:21

---------
7) RedisTest: See in redis existing z set with correct value without scores
 Test  tests/unit/Codeception/Module/RedisTest.php:testSeeInRedisExistingZSetWithCorrectValueWithoutScores
Value of key "test:zset" does not match expected value
- Expected | + Actual
@@ @@
Array (
-    0 => 0.0
-    1 => 0.0
-    2 => 0.0
+    'juanito' => 1.0
+    'jorgito' => 2.0
+    'jaimito' => 3.0
)
#1  /.../module-redis/src/Codeception/Module/Redis.php:688
#2  /.../module-redis/src/Codeception/Module/Redis.php:454
#3  /.../module-redis/tests/unit/Codeception/Module/RedisTest.php:1080
#4  /.../module-redis/vendor/bin/codecept(21) : eval()'d code:6
#5  /.../module-redis/vendor/bin/codecept:21

---------
8) RedisTest: See in redis existing z set with correct value different order
 Test  tests/unit/Codeception/Module/RedisTest.php:testSeeInRedisExistingZSetWithCorrectValueDifferentOrder
Cannot find key "test:zset" with the provided value
Failed asserting that false is true.
#1  /.../module-redis/src/Codeception/Module/Redis.php:455
#2  /.../module-redis/tests/unit/Codeception/Module/RedisTest.php:1089
#3  /.../module-redis/vendor/bin/codecept(21) : eval()'d code:6
#4  /.../module-redis/vendor/bin/codecept:21

---------
9) RedisTest: See in redis existing z set with incorrect value
 Test  tests/unit/Codeception/Module/RedisTest.php:testSeeInRedisExistingZSetWithIncorrectValue
Value of key "test:zset" does not match expected value
- Expected | + Actual
@@ @@
Array (
-    'incorrect' => 1.0
-    'value' => 2.0
+    'juanito' => 1.0
+    'jorgito' => 2.0
+    'jaimito' => 3.0
)
#1  /.../module-redis/src/Codeception/Module/Redis.php:688
#2  /.../module-redis/src/Codeception/Module/Redis.php:454
#3  /.../module-redis/tests/unit/Codeception/Module/RedisTest.php:1098
#4  /.../module-redis/vendor/bin/codecept(21) : eval()'d code:6
#5  /.../module-redis/vendor/bin/codecept:21

---------
10) RedisTest: See in redis existing hash with incorrect value
 Test  tests/unit/Codeception/Module/RedisTest.php:testSeeInRedisExistingHashWithIncorrectValue
Value of key "test:hash" does not match expected value
- Expected | + Actual
@@ @@
Array (
-    'incorrect' => 'value'
+    'Tick' => '1'
+    'Trick' => 'dewey'
+    'Track' => '42'
)
#1  /.../module-redis/src/Codeception/Module/Redis.php:688
#2  /.../module-redis/src/Codeception/Module/Redis.php:454
#3  /.../module-redis/tests/unit/Codeception/Module/RedisTest.php:1127
#4  /.../module-redis/vendor/bin/codecept(21) : eval()'d code:6
#5  /.../module-redis/vendor/bin/codecept:21

because ArrayComparator considers out of order arrays as equal
@Naktibalda
Copy link
Member Author

I noticed that ArrayComparator considers associative arrays having the same keys and same values but out of order as equal,
so I will compare arrays as strings, the diff is not as nice, but I think that it is good enough:

1) RedisTest: See in redis existing z set with correct value different order
 Test  tests/unit/Codeception/Module/RedisTest.php:testSeeInRedisExistingZSetWithCorrectValueDifferentOrder
Value of key "test:zset" does not match expected value
- Expected | + Actual
@@ @@
'array (\n
+  'juanito' => 1.0,\n
+  'jorgito' => 2.0,\n
'jaimito' => 3.0,\n
-  'jorgito' => 2.0,\n
-  'juanito' => 1.0,\n
)'
#1  /.../module-redis/src/Codeception/Module/Redis.php:464
#2  /.../module-redis/tests/unit/Codeception/Module/RedisTest.php:1094
#3  /.../module-redis/vendor/bin/codecept(21) : eval()'d code:6
#4  /.../module-redis/vendor/bin/codecept:21

@Naktibalda Naktibalda merged commit a4a185a into master Dec 12, 2021
@Naktibalda Naktibalda deleted the diff-for-seeInRedis branch December 12, 2021 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants