From c4e698dc27d35d4105fb1c3821fd988595d70b68 Mon Sep 17 00:00:00 2001 From: Matthew Flaschen Date: Thu, 12 May 2016 18:01:03 -0400 Subject: [PATCH] Follow-up cdc93a62bf: add serialize/unserialize tests for RedisBagOStuff Bug: T134923 Change-Id: I0a7bec40c3fbf301720a248fbe21d46f5e64154c --- .../objectcache/RedisBagOStuffTest.php | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 tests/phpunit/includes/objectcache/RedisBagOStuffTest.php diff --git a/tests/phpunit/includes/objectcache/RedisBagOStuffTest.php b/tests/phpunit/includes/objectcache/RedisBagOStuffTest.php new file mode 100644 index 0000000000..cf87a98098 --- /dev/null +++ b/tests/phpunit/includes/objectcache/RedisBagOStuffTest.php @@ -0,0 +1,101 @@ +cache = TestingAccessWrapper::newFromObject( new RedisBagOStuff( [ 'servers' => [] ] ) ); + } + + /** + * @covers RedisBagOStuff::unserialize + * @dataProvider unserializeProvider + */ + public function testUnserialize( $expected, $input, $message ) { + $actual = $this->cache->unserialize( $input ); + $this->assertSame( $expected, $actual, $message ); + } + + public function unserializeProvider() { + return [ + [ + -1, + '-1', + 'String representation of \'-1\'', + ], + [ + 0, + '0', + 'String representation of \'0\'', + ], + [ + 1, + '1', + 'String representation of \'1\'', + ], + [ + -1.0, + 'd:-1;', + 'Serialized negative double', + ], + [ + 'foo', + 's:3:"foo";', + 'Serialized string', + ] + ]; + } + + /** + * @covers RedisBagOStuff::serialize + * @dataProvider serializeProvider + */ + public function testSerialize( $expected, $input, $message ) { + $actual = $this->cache->serialize( $input ); + $this->assertSame( $expected, $actual, $message ); + } + + public function serializeProvider() { + return [ + [ + -1, + -1, + '-1 as integer', + ], + [ + 0, + 0, + '0 as integer', + ], + [ + 1, + 1, + '1 as integer', + ], + [ + 'd:-1;', + -1.0, + 'Negative double', + ], + [ + 's:3:"2.1";', + '2.1', + 'Decimal string', + ], + [ + 's:1:"1";', + '1', + 'String representation of 1', + ], + [ + 's:3:"foo";', + 'foo', + 'String', + ], + ]; + } +} -- 2.20.1