Skip to content

Commit

Permalink
Add tests for TypeConverter
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Feb 10, 2016
1 parent 4b284d9 commit 6d52bc6
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/Alcaeus/MongoDbAdapter/TypeConverterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Alcaeus\MongoDbAdapter\Tests;

use MongoDB\BSON;
use MongoDB\Driver\Exception;
use Alcaeus\MongoDbAdapter\TypeConverter;
use MongoDB\Model\BSONDocument;

class TypeConverterTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider converterData
*/
public function testFromLegacy($legacyValue, $modernValue)
{
$this->assertEquals($modernValue, TypeConverter::fromLegacy($legacyValue));
}

public static function converterData()
{
$id = str_repeat('0123', 6);

return [
'objectId' => [
new \MongoId($id), new BSON\ObjectID($id)
],
'numericArray' => [
['foo', 'bar'], ['foo', 'bar']
],
'hashWithNumericKeys' => [
(object) ['foo', 'bar'], new BSONDocument(['foo', 'bar'])
],
'hash' => [
['foo' => 'bar'], new BSONDocument(['foo' => 'bar'])
],
'nestedArrays' => [
[['foo' => 'bar']], [new BSONDocument(['foo' => 'bar'])]
],
];
}
}

0 comments on commit 6d52bc6

Please sign in to comment.