From 950d1f4a9ae4d712da512717055553d387ce51fc Mon Sep 17 00:00:00 2001 From: Anton Grebnev Date: Mon, 4 Jun 2012 16:06:03 +0400 Subject: [PATCH] modified MongoDbCommand __toString output --- model/MongoDbCommand.php | 12 ++++++------ tests/model/MongoDbCommandTest.php | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/model/MongoDbCommand.php b/model/MongoDbCommand.php index c82c430..ad08978 100644 --- a/model/MongoDbCommand.php +++ b/model/MongoDbCommand.php @@ -97,7 +97,7 @@ class FindMongoCommand extends MongoDbCommand public function __toString() { if ($this->checkParams()) { - $result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL; + $result = PHP_EOL . 'Collection: ' . trim($this->collection, "\n") . PHP_EOL; ob_start(); var_dump($this->condition); $condition = ob_get_clean(); @@ -143,7 +143,7 @@ class CountMongoCommand extends MongoDbCommand public function __toString() { if ($this->checkParams()) { - $result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL; + $result = PHP_EOL . 'Collection: ' . trim($this->collection, "\n") . PHP_EOL; $result .= 'Type: COUNT' . PHP_EOL; ob_start(); var_dump($this->condition); @@ -199,7 +199,7 @@ class InsertMongoCommand extends MongoDbCommand public function __toString() { if ($this->checkParams()) { - $result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL; + $result = PHP_EOL . 'Collection: ' . trim($this->collection, "\n") . PHP_EOL; $result .= 'Type: INSERT' . PHP_EOL; ob_start(); var_dump($this->data); @@ -248,7 +248,7 @@ class UpdateMongoCommand extends MongoDbCommand public function __toString() { if ($this->checkParams()) { - $result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL; + $result = PHP_EOL . 'Collection: ' . trim($this->collection, "\n") . PHP_EOL; $result .= 'Type: UPDATE' . PHP_EOL; ob_start(); var_dump($this->condition); @@ -294,7 +294,7 @@ class RemoveMongoCommand extends MongoDbCommand public function __toString() { if ($this->checkParams()) { - $result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL; + $result = PHP_EOL . 'Collection: ' . trim($this->collection, "\n") . PHP_EOL; $result .= 'Type: REMOVE' . PHP_EOL; ob_start(); var_dump($this->condition); @@ -335,7 +335,7 @@ class CommandMongoCommand extends MongoDbCommand public function __toString() { if ($this->checkParams()) { - $result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL; + $result = PHP_EOL . 'Collection: ' . trim($this->collection, "\n") . PHP_EOL; $result .= 'Type: COMMAND' . PHP_EOL; ob_start(); var_dump($this->command); diff --git a/tests/model/MongoDbCommandTest.php b/tests/model/MongoDbCommandTest.php index 69fe5b5..12a4119 100644 --- a/tests/model/MongoDbCommandTest.php +++ b/tests/model/MongoDbCommandTest.php @@ -329,23 +329,23 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase { $cmd = MongoCommandBuilder::factory(MongoCommandBuilder::COUNT, new CollectionMock()); $cmd->bindParam('condition', array()); - $this->assertStringStartsWith('Collection: CollectionMock', $cmd->__toString()); + $this->assertStringStartsWith(PHP_EOL . 'Collection: CollectionMock', $cmd->__toString()); $cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, new CollectionMock()); $cmd->bindParam('condition', array()); - $this->assertStringStartsWith('Collection: CollectionMock', $cmd->__toString()); + $this->assertStringStartsWith(PHP_EOL . 'Collection: CollectionMock', $cmd->__toString()); $cmd = MongoCommandBuilder::factory(MongoCommandBuilder::COMMAND, new CollectionMock()); $this->assertSame('Command properties not set', $cmd->__toString()); $cmd->bindParam('command', array()); - $this->assertStringStartsWith('Collection: CollectionMock', $cmd->__toString()); + $this->assertStringStartsWith(PHP_EOL . 'Collection: CollectionMock', $cmd->__toString()); $cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $this->collection); $this->assertSame('Command properties not set', $cmd->__toString()); $cmd ->bindParam('data', array('name' => 'insert')) ->bindParam('safe', true); - $this->assertStringStartsWith('Collection: ', $cmd->__toString()); + $this->assertStringStartsWith(PHP_EOL . 'Collection: ', $cmd->__toString()); $this->assertContains('Bulk insert: FALSE', $cmd->__toString()); $cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $this->collection); @@ -357,14 +357,14 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase $this->assertContains('Bulk insert: TRUE', $cmd->__toString()); $cmd->bindParam('condition', array('name' => 'insert'))->bindParam('fields', array()); - $this->assertStringStartsWith('Collection: ', $cmd->__toString()); + $this->assertStringStartsWith(PHP_EOL . 'Collection: ', $cmd->__toString()); $cmd = MongoCommandBuilder::factory(MongoCommandBuilder::REMOVE, $this->collection); $this->assertSame('Command properties not set', $cmd->__toString()); $cmd ->bindParam('condition', array('name' => 'insert')) ->bindParam('safe', true); - $this->assertStringStartsWith('Collection: ', $cmd->__toString()); + $this->assertStringStartsWith(PHP_EOL . 'Collection: ', $cmd->__toString()); $cmd = MongoCommandBuilder::factory(MongoCommandBuilder::UPDATE, $this->collection); $this->assertSame('Command properties not set', $cmd->__toString()); @@ -373,7 +373,7 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase ->bindParam('data', array('$set' => array('name' => 'update'))) ->bindParam('upsert', false) ->bindParam('safe', true); - $this->assertStringStartsWith('Collection: ', $cmd->__toString()); + $this->assertStringStartsWith(PHP_EOL . 'Collection: ', $cmd->__toString()); } } @@ -383,6 +383,6 @@ class CollectionMock public function __toString() { - return 'CollectionMock'; + return PHP_EOL . 'CollectionMock'; } }