From 156f7c04676ce35479de1e872b7973ea5a4b50c7 Mon Sep 17 00:00:00 2001 From: Paul Klimov Date: Wed, 4 Dec 2013 11:18:09 +0200 Subject: [PATCH] Unit tests for Mongo updated to check nested columns. --- tests/unit/extensions/mongo/ActiveRecordTest.php | 26 ++++++++++++++++++++++++ tests/unit/extensions/mongo/QueryRunTest.php | 12 +++++++++++ 2 files changed, 38 insertions(+) diff --git a/tests/unit/extensions/mongo/ActiveRecordTest.php b/tests/unit/extensions/mongo/ActiveRecordTest.php index 812d6e3..78e1da1 100644 --- a/tests/unit/extensions/mongo/ActiveRecordTest.php +++ b/tests/unit/extensions/mongo/ActiveRecordTest.php @@ -218,4 +218,30 @@ class ActiveRecordTest extends MongoTestCase $refreshedRecord = Customer::find($record->_id); $this->assertEquals($originalCounter + $counterIncrement, $refreshedRecord->status); } + + /** + * @depends testUpdate + */ + public function testUpdateNestedAttribute() + { + $record = new Customer; + $record->name = 'new name'; + $record->email = 'new email'; + $record->address = [ + 'city' => 'SomeCity', + 'street' => 'SomeStreet', + ]; + $record->status = 7; + $record->save(); + + // save + $record = Customer::find($record->_id); + $newAddress = [ + 'city' => 'AnotherCity' + ]; + $record->address = $newAddress; + $record->save(); + $record2 = Customer::find($record->_id); + $this->assertEquals($newAddress, $record2->address); + } } \ No newline at end of file diff --git a/tests/unit/extensions/mongo/QueryRunTest.php b/tests/unit/extensions/mongo/QueryRunTest.php index 078e1c7..7fe4812 100644 --- a/tests/unit/extensions/mongo/QueryRunTest.php +++ b/tests/unit/extensions/mongo/QueryRunTest.php @@ -32,6 +32,11 @@ class QueryRunTest extends MongoTestCase $rows[] = [ 'name' => 'name' . $i, 'address' => 'address' . $i, + 'avatar' => [ + 'width' => 50 + $i, + 'height' => 100 + $i, + 'url' => 'http://some.url/' . $i, + ], ]; } $collection->batchInsert($rows); @@ -99,11 +104,18 @@ class QueryRunTest extends MongoTestCase public function testOrder() { $connection = $this->getConnection(); + $query = new Query; $rows = $query->from('customer') ->orderBy(['name' => SORT_DESC]) ->all($connection); $this->assertEquals('name9', $rows[0]['name']); + + $query = new Query; + $rows = $query->from('customer') + ->orderBy(['avatar.height' => SORT_DESC]) + ->all($connection); + $this->assertEquals('name10', $rows[0]['name']); } public function testMatchPlainId()