LogBuilderTest.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace yiiunit\extensions\mongodb;
  3. use MongoDB\BSON\Javascript;
  4. use MongoDB\BSON\ObjectID;
  5. class LogBuilderTest extends TestCase
  6. {
  7. /**
  8. * Data provider for [[testEncodeData]].
  9. * @return array test data
  10. */
  11. public function dataProviderEncodeData()
  12. {
  13. return [
  14. [
  15. 'foo',
  16. '"foo"',
  17. ],
  18. [
  19. new ObjectID('57684eed962078354a21ec11'),
  20. '"MongoDB\\\\BSON\\\\ObjectID(57684eed962078354a21ec11)"',
  21. ],
  22. [
  23. new Javascript('function () {return 0;}'),
  24. '"MongoDB\\\\BSON\\\\Javascript(function () {return 0;})"'
  25. ],
  26. ];
  27. }
  28. /**
  29. * @dataProvider dataProviderEncodeData
  30. *
  31. * @param mixed $data
  32. * @param string $expectedResult
  33. */
  34. public function testEncodeData($data, $expectedResult)
  35. {
  36. $logBuilder = $this->getConnection()->getLogBuilder();
  37. $this->assertTrue(strcasecmp($expectedResult, $logBuilder->encodeData($data)) === 0);
  38. }
  39. }