FunctionsTest.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace Alcaeus\MongoDbAdapter\Tests;
  3. /**
  4. * @author alcaeus <alcaeus@alcaeus.org>
  5. */
  6. class FunctionsTest extends TestCase
  7. {
  8. /**
  9. * @return array Returns tupels: [$encoded, $decoded]
  10. */
  11. public static function data()
  12. {
  13. // The encoded values were retrieved by encoding data with the legacy driver and encoding them base64
  14. $simpleArray = ['foo' => 'bar'];
  15. $simpleArrayEncoded = "EgAAAAJmb28ABAAAAGJhcgAA";
  16. $arrayWithObjectId = ['_id' => new \MongoId('1234567890abcdef12345678')];
  17. $arrayWithObjectIdEncoded = "FgAAAAdfaWQAEjRWeJCrze8SNFZ4AA==";
  18. return [
  19. 'simpleArray' => [base64_decode($simpleArrayEncoded), $simpleArray],
  20. 'arrayWithObjectId' => [base64_decode($arrayWithObjectIdEncoded), $arrayWithObjectId],
  21. ];
  22. }
  23. /**
  24. * @dataProvider data
  25. */
  26. public function testEncode($encoded, $decoded)
  27. {
  28. $this->assertEquals($encoded, bson_encode($decoded));
  29. }
  30. /**
  31. * @dataProvider data
  32. */
  33. public function testDecode($encoded, $decoded)
  34. {
  35. $this->assertEquals($decoded, bson_decode($encoded));
  36. }
  37. }