FunctionsTest.php 1.2 KB

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