From 674b59bb03e395dacb9f3c267b4cab010439e21c Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Tue, 6 Dec 2011 12:44:52 +0400 Subject: [PATCH 01/11] Added Redis stub class for autocompletion --- tests/redis/redis.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/redis/redis.php diff --git a/tests/redis/redis.php b/tests/redis/redis.php new file mode 100644 index 0000000..4c21f88 --- /dev/null +++ b/tests/redis/redis.php @@ -0,0 +1,50 @@ + + * @link http://netmonsters.ru + * @package Lib + * @subpackage Helpers + * @since 2011-05-17 + */ + +/** + * Redis stub for https://github.com/nicolasff/phpredis + * @author aterekhov + * @see https://github.com/nicolasff/phpredis + * + * @method bool connect() connect(string $host, int $port = 6379, float $timeout = 0) Connect to redis + * @method bool pconnect() connect(string $host, int $port = 6379, float $timeout = 0, string $persistent_id) Connect to redis with reusing connection + * @method void close() Close connection to redis + * @method bool setOption() setOption(mixed $name, mixed $value) Set client option + * @method mixed getOption() getOption(mixed $name) Get client option + * @method string ping() ping() Check the current connection status + * @method string|bool get() get(string $key) Get the value related to the specified key + * @method bool set() set(string $key, mixed $value, int $timeout = null) Set the string value in argument as value of the key + * @method bool setex() setex(string $key, int $ttl, mixed $value) Set the string value in argument as value of the key, with a time to live + * @method bool setnx() setnx(string $key, int $ttl) Set the string value in argument as value of the key if the key doesn't already exist in the database + * @method float delete() delete(mixed $key) Remove specified keys + * @method Redis multi() multi(mixed $mode = 1) Enter and exit transactional mode + * @method bool exec() exec() Enter and exit transactional mode + * @method void watch() watch(mixed $keys) Watches a key for modifications by another client + * @method void unwatch() unwatch(mixed $keys) Watches a key for modifications by another client + * @method void subscribe() subscribe(array $channels, mixed $callback) Subscribe to channels. Warning: this function will probably change in the future + * @method void publish() publish(string $channel, string $message) Publish messages to channels. Warning: this function will probably change in the future + * @method bool exists() exists(string $key) Verify if the specified key exists + * @method int incr() incr(string $key) Increment the number stored at key by one + * @method int incrBy() incrBy(string $key, int $value) Increment the number stored at key by $value + * + * @method bool expire() expire(string $key, int $ttl) Sets an expiration date (a timeout) on an item + * + * @method float zAdd() zAdd(string $key, float $score, string $value) Adds the specified member with a given score to the sorted set stored at key + * @method array zRange() zRange(string $key, float $start, float $end, bool $with_scores = false) Returns a range of elements from the ordered set stored at the specified key, with values in the range [start, end] + * @method array zRevRange() zRevRange(string $key, float $start, float $end, bool $with_scores = false) Returns a range of elements from the ordered set stored at the specified key, with values in the range [start, end] + * @method float zCard() zCard(string $key) Returns the cardinality of an ordered set + * @method float zUnionStore() zUnionStore(string $destination, array $keys, array $weights = array(), string $aggregate = 'sum') Creates an union of sorted sets given in second argument and store in in first argument + * @method float zInterStore() zInterStore(string $destination, array $keys, array $weights = array(), string $aggregate = 'sum') Creates an intersection of sorted sets given in second argument and store in in first argument + */ +class Redis +{ + +} \ No newline at end of file From 400d2667df5fe77508c17e4924b69e16c97130d8 Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Tue, 6 Dec 2011 14:00:55 +0400 Subject: [PATCH 02/11] Moved redis stub class from tests to actual place --- {tests/redis => redis}/redis.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {tests/redis => redis}/redis.php (100%) diff --git a/tests/redis/redis.php b/redis/redis.php similarity index 100% rename from tests/redis/redis.php rename to redis/redis.php From 34645282ce1e2ae187bce3eb492a127cf8531a6a Mon Sep 17 00:00:00 2001 From: Alexander Letov Date: Tue, 6 Dec 2011 14:41:47 +0400 Subject: [PATCH 03/11] Fixed vfsStream to version 0.11.1 (work with both 0.10.1 and 0.11.1) --- tests/LoadTest.php | 1 + tests/logger/FileLoggerTest.php | 1 + tests/view/PHPViewTest.php | 1 + 3 files changed, 3 insertions(+) diff --git a/tests/LoadTest.php b/tests/LoadTest.php index d3458d3..78e9e43 100644 --- a/tests/LoadTest.php +++ b/tests/LoadTest.php @@ -42,6 +42,7 @@ class LoadTest extends PHPUnit_Framework_TestCase self::$autoload_array = array('Db' => '/lib/core/model/Db.php', 'DbDriver' => '/lib/core/model/DbDriver.php'); vfsStreamWrapper::register(); + vfsStream::setup(); $this->root = vfsStream::create( array( 'lib' => array( diff --git a/tests/logger/FileLoggerTest.php b/tests/logger/FileLoggerTest.php index acea352..889f985 100644 --- a/tests/logger/FileLoggerTest.php +++ b/tests/logger/FileLoggerTest.php @@ -30,6 +30,7 @@ class FileLoggerTest extends PHPUnit_Framework_TestCase public function setUp() { vfsStreamWrapper::register(); + vfsStream::setup(); $root = vfsStream::create(array()); vfsStreamWrapper::setRoot($root); $this->conf = array('logger' => 'FileLogger', 'filepath' => vfsStream::url('root/log.txt')); diff --git a/tests/view/PHPViewTest.php b/tests/view/PHPViewTest.php index c4aa69a..99dcc0e 100644 --- a/tests/view/PHPViewTest.php +++ b/tests/view/PHPViewTest.php @@ -28,6 +28,7 @@ class PHPViewTest extends PHPUnit_Framework_TestCase public function setUp() { vfsStreamWrapper::register(); + vfsStream::setup(); $root = vfsStream::create(array()); vfsStreamWrapper::setRoot($root); $views_dir = vfsStream::newDirectory('views'); From e9ddaa6d92e49dc21d34231e166edc522c06ad63 Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Tue, 6 Dec 2011 18:40:54 +0400 Subject: [PATCH 04/11] phpredis has some methods named in lowercase, e.g. zinterstore. Code changed to reflect this --- redis/RedisDebug.php | 6 ------ tests/redis/RedisDebugTest.php | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/redis/RedisDebug.php b/redis/RedisDebug.php index 5875210..692f0ea 100644 --- a/redis/RedisDebug.php +++ b/redis/RedisDebug.php @@ -25,12 +25,6 @@ class RedisDebug { $command = $this->r_implode(', ', $arguments); $profiler = Profiler::getInstance()->profilerCommand('Redis->' . $name, $command); - - $search = array_search($name, get_class_methods($this->redis)); - - if (empty($search)) { - throw new GeneralException('undefined method:'.$name); - } $data = call_user_func_array(array($this->redis, $name), $arguments); $profiler->end(); return $data; diff --git a/tests/redis/RedisDebugTest.php b/tests/redis/RedisDebugTest.php index 3794b1e..83642f7 100644 --- a/tests/redis/RedisDebugTest.php +++ b/tests/redis/RedisDebugTest.php @@ -103,7 +103,7 @@ class RedisDebugTest extends PHPUnit_Framework_TestCase $mock = $this->getMock('Redis', array('connect')); $redisDebug = new RedisDebug($mock); - $this->setExpectedException('GeneralException'); + $this->setExpectedException('PHPUnit_Framework_Error', 'call_user_func_array() expects parameter 1 to be a valid callback, class \'Mock_Redis_'); $this->assertNull($redisDebug->nothing('localhost', 4322)); } From 6b1e3f6a7099b3b747dc09b8721b4591510cf1e3 Mon Sep 17 00:00:00 2001 From: Anton Grebnev Date: Tue, 13 Dec 2011 13:51:24 +0400 Subject: [PATCH 05/11] reseted a3e0cafb325742eaf39eab0e733a6a5e591b1f31 commit --- logger/CliLogger.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logger/CliLogger.php b/logger/CliLogger.php index cfc8e5e..121cda1 100644 --- a/logger/CliLogger.php +++ b/logger/CliLogger.php @@ -13,7 +13,7 @@ class CliLogger extends Logger protected function concreteLog($message) { // Заменяем окончания строк на их символы - $message = str_replace(array("\r\n"), array(PHP_EOL), $message); + $message = str_replace(array("\r", "\n"), array('\r', '\n'), $message); $out = microtime(true) . " \t: " . $this->pid . trim($message) . PHP_EOL; print($out); } From 40b3e76c74c2f00a7be4ea823daaf833c0e155c2 Mon Sep 17 00:00:00 2001 From: Anton Grebnev Date: Tue, 6 Mar 2012 18:47:40 +0400 Subject: [PATCH 06/11] modified AutoloadBuilder to atomic write operation --- tests/util/AutoloadBuilderTest.php | 15 ++++++-------- util/AutoloadBuilder.php | 42 +++++++++++++++----------------------- 2 files changed, 23 insertions(+), 34 deletions(-) diff --git a/tests/util/AutoloadBuilderTest.php b/tests/util/AutoloadBuilderTest.php index a3aaff9..f9feb7c 100644 --- a/tests/util/AutoloadBuilderTest.php +++ b/tests/util/AutoloadBuilderTest.php @@ -77,6 +77,7 @@ class AutoloadBuilderTest extends PHPUnit_Framework_TestCase $this->setConstants(); $builder = new AutoloadBuilder(self::$file, array(self::$path . '/' . self::$app . '/src', self::$path . '/' . self::$app . '/cache', self::$path . '/lib')); + $this->assertFileNotExists(self::$file); $builder->build(); $this->assertFileExists(self::$file); @@ -84,6 +85,8 @@ class AutoloadBuilderTest extends PHPUnit_Framework_TestCase $array = require self::$file; $this->assertInternalType('array', $array); $this->assertNotEmpty($array); + $this->assertArrayHasKey('AutoloadBuilder', $array); + $this->assertArrayHasKey('Load', $array); } /** @@ -94,7 +97,10 @@ class AutoloadBuilderTest extends PHPUnit_Framework_TestCase $this->setConstants(); $this->setExpectedException('PHPUnit_Framework_Error'); + $this->assertFileNotExists(self::$file); + touch(self::$file); + $this->assertFileExists(self::$file); chmod(self::$file, 0400); $builder = new AutoloadBuilder(self::$file, array(self::$path . '/' . self::$app . '/src', self::$path . '/' . self::$app . '/cache', self::$path . '/lib')); @@ -102,15 +108,6 @@ class AutoloadBuilderTest extends PHPUnit_Framework_TestCase chmod(self::$file, 0777); } - public function tearDown() - { -// if (defined('PATH')) { -// echo PHP_EOL . __CLASS__ . ' ' . PATH . PHP_EOL; -// } else { -// echo PHP_EOL . __CLASS__ . ' ' . 'PATH NOT DEFINED' . PHP_EOL; -// } - } - public static function tearDownAfterClass() { if (file_exists(self::$file)) { diff --git a/util/AutoloadBuilder.php b/util/AutoloadBuilder.php index 3f64ef6..5c969cd 100644 --- a/util/AutoloadBuilder.php +++ b/util/AutoloadBuilder.php @@ -35,7 +35,7 @@ class AutoloadBuilder public function build() { - $this->openAutoload(); + $array_string = "dirs as $dir) { @@ -65,47 +65,39 @@ class AutoloadBuilder if (array_key_exists($match[2], $classes)) { continue; } - $string = "'{$match[2]}'=>'" . $relative_path . "',\n"; - $this->write($string); + $array_string .= "'{$match[2]}'=>'" . $relative_path . "',\n"; $classes[$match[2]] = $file->getRealPath(); } } } } - $this->closeAutoload(); + $array_string .= ');'; + $this->writeAutoload($array_string); + $this->isFileConsistent(); } - protected function isExcluded($file) - { - foreach ($this->exclude as $dir) { - if (stripos($file, PATH . $dir) === 0) { - return true; - } - } - return false; - } - - - protected function openAutoload() + protected function writeAutoload($string) { - $this->write("autoload, $string); } - protected function closeAutoload() + protected function isFileConsistent() { - if ($this->write(');')) { - fclose($this->handler); + $autoload_array = include($this->autoload); + if(!is_array($autoload_array)) { + unlink($this->autoload); + trigger_error("Error while generating autoload file.", E_USER_ERROR); } } - protected function write($string) + protected function isExcluded($file) { - if (!$this->handler) { - if (!$this->handler = fopen($this->autoload, 'w')) { - trigger_error("{$this->autoload} is not writable", E_USER_ERROR); + foreach ($this->exclude as $dir) { + if (stripos($file, PATH . $dir) === 0) { + return true; } } - return (bool) fwrite($this->handler, $string); + return false; } protected function rightSubstr($string, $nchars) From 755f1b46c71e5e2865a1690c9cefc7afbb03adb4 Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Mon, 19 Mar 2012 18:18:25 +0400 Subject: [PATCH 07/11] Fixed packages for some files --- app/AjaxAction.php | 2 +- redis/redis.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/AjaxAction.php b/app/AjaxAction.php index 0316bf1..c91affe 100644 --- a/app/AjaxAction.php +++ b/app/AjaxAction.php @@ -4,7 +4,7 @@ * * @copyright NetMonsters * @link - * @package Kuperauto + * @package Majestic * @subpackage face * @since * @version SVN: $Id$ diff --git a/redis/redis.php b/redis/redis.php index 4c21f88..8cc008f 100644 --- a/redis/redis.php +++ b/redis/redis.php @@ -4,8 +4,8 @@ * * @copyright NetMonsters * @link http://netmonsters.ru - * @package Lib - * @subpackage Helpers + * @package Majestic + * @subpackage Redis * @since 2011-05-17 */ From c7dcd335129e5f09b516fdb18b88987c6eb0974c Mon Sep 17 00:00:00 2001 From: Anton Terekhov Date: Thu, 22 Mar 2012 16:03:55 +0400 Subject: [PATCH 08/11] Code format, PHPDoc --- logger/Logger.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/logger/Logger.php b/logger/Logger.php index 48e64f9..c8637c0 100644 --- a/logger/Logger.php +++ b/logger/Logger.php @@ -12,24 +12,31 @@ abstract class Logger { protected static $_instance = null; - + /** * pid текущего процесса * @var string */ protected $pid = ''; - protected function __construct() {} + protected function __construct() + { + } + /** + * @static + * @return Logger + */ public static function getInstance() { - if(static::$_instance === null) { + if (static::$_instance === null) { //$class = get_called_class(); $class = Config::get('Logger')->logger; static::$_instance = new $class(); } return static::$_instance; } + /** * Вывод лога * @param string $message Сообщение @@ -53,5 +60,4 @@ abstract class Logger } abstract protected function concreteLog($message); - } \ No newline at end of file From a1bfcdd78b069ffbf6330b49f1a507c1d2107084 Mon Sep 17 00:00:00 2001 From: Anton Grebnev Date: Mon, 2 Apr 2012 15:21:37 +0400 Subject: [PATCH 09/11] added count() method to MongoModel --- model/MongoDbCommand.php | 53 ++++++++++++++++++++++++++++++++++++++++++++++-- model/MongoDriver.php | 9 +++++++- model/MongoStatement.php | 4 ++++ 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/model/MongoDbCommand.php b/model/MongoDbCommand.php index 0cc81b5..4eae91e 100644 --- a/model/MongoDbCommand.php +++ b/model/MongoDbCommand.php @@ -12,6 +12,8 @@ class MongoCommandBuilder const FIND = 'Find'; + const COUNT = 'Count'; + const INSERT = 'Insert'; const UPDATE = 'Update'; @@ -68,9 +70,9 @@ abstract class MongoDbCommand class FindMongoCommand extends MongoDbCommand { - protected $condition; + protected $condition = array(); - protected $fields; + protected $fields = array(); protected $multiple = true; @@ -100,6 +102,7 @@ class FindMongoCommand extends MongoDbCommand var_dump($this->condition); $condition = ob_get_clean(); $result .= 'Condition: ' . $condition . PHP_EOL; + $result .= 'Type: FIND' . PHP_EOL; ob_start(); var_dump($this->fields); $fields = ob_get_clean(); @@ -113,6 +116,48 @@ class FindMongoCommand extends MongoDbCommand } } +class CountMongoCommand extends MongoDbCommand +{ + protected $condition = array(); + + protected $limit = 0; + + protected $skip = 0; + + protected $multiple = true; + + protected function concreteExecute() + { + return $this->collection->count($this->condition, $this->limit, $this->skip); + } + + protected function checkParams() + { + if (isset($this->collection) && isset($this->condition) && isset($this->limit) && isset($this->skip)) { + return true; + } else { + return false; + } + } + + public function __toString() + { + if ($this->checkParams()) { + $result = 'Collection: ' . $this->collection . PHP_EOL; + $result .= 'Type: COUNT' . PHP_EOL; + ob_start(); + var_dump($this->condition); + $condition = ob_get_clean(); + $result .= 'Condition: ' . $condition . PHP_EOL; + $result .= 'Limit: ' . $this->limit . PHP_EOL; + $result .= 'Skip: ' . $this->skip . PHP_EOL; + return $result; + } else { + return 'Command properties not set'; + } + } +} + class InsertMongoCommand extends MongoDbCommand { protected $data; @@ -155,6 +200,7 @@ class InsertMongoCommand extends MongoDbCommand { if ($this->checkParams()) { $result = 'Collection: ' . $this->collection . PHP_EOL; + $result .= 'Type: INSERT' . PHP_EOL; ob_start(); var_dump($this->data); $data = ob_get_clean(); @@ -203,6 +249,7 @@ class UpdateMongoCommand extends MongoDbCommand { if ($this->checkParams()) { $result = 'Collection: ' . $this->collection . PHP_EOL; + $result .= 'Type: UPDATE' . PHP_EOL; ob_start(); var_dump($this->condition); $condition = ob_get_clean(); @@ -248,6 +295,7 @@ class RemoveMongoCommand extends MongoDbCommand { if ($this->checkParams()) { $result = 'Collection: ' . $this->collection . PHP_EOL; + $result .= 'Type: REMOVE' . PHP_EOL; ob_start(); var_dump($this->condition); $condition = ob_get_clean(); @@ -288,6 +336,7 @@ class CommandMongoCommand extends MongoDbCommand { if ($this->checkParams()) { $result = 'Collection: ' . $this->collection . PHP_EOL; + $result .= 'Type: COMMAND' . PHP_EOL; ob_start(); var_dump($this->command); $command = ob_get_clean(); diff --git a/model/MongoDriver.php b/model/MongoDriver.php index a6c4ad6..455b0a4 100644 --- a/model/MongoDriver.php +++ b/model/MongoDriver.php @@ -28,7 +28,14 @@ class MongoDriver extends NoSqlDbDriver public function count($collection, $query = array(), $limit = 0, $skip = 0) { - return $this->getCollection($collection)->count($query, $limit, $skip); + $command = MongoCommandBuilder::factory(MongoCommandBuilder::COUNT, $this->getCollection($collection)); + $params = array( + 'condition' => $query, + 'limit' => $limit, + 'skip' => $skip + ); + + return $this->query($command, $params)->affectedRows(); } public function find($collection, $condition = array(), $fields = array()) diff --git a/model/MongoStatement.php b/model/MongoStatement.php index 3e43f0a..02c5254 100644 --- a/model/MongoStatement.php +++ b/model/MongoStatement.php @@ -112,6 +112,8 @@ class MongoStatement extends DbStatement } else { return false; } + } elseif (is_int($this->result)) { + return $this->result; } return false; } @@ -151,6 +153,8 @@ class MongoStatement extends DbStatement if (is_array($result) && isset($result['values'])) { $this->result = $result['values']; } + } elseif (is_int($result)) { + $this->result = $result; } if ($request instanceof InsertMongoCommand) { $this->insertId = $request->getInsertId(); From f728e6d6a20a26613bbaa0af7c22933b11b3240f Mon Sep 17 00:00:00 2001 From: Anton Grebnev Date: Mon, 2 Apr 2012 15:21:58 +0400 Subject: [PATCH 10/11] updated tests for MongoDbCommand with count command --- tests/model/MongoDbCommandTest.php | 40 ++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/tests/model/MongoDbCommandTest.php b/tests/model/MongoDbCommandTest.php index e3bb265..1963318 100644 --- a/tests/model/MongoDbCommandTest.php +++ b/tests/model/MongoDbCommandTest.php @@ -99,12 +99,34 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase /** * @group Mongo */ - public function testFindCommandNotAllParamsBinded() + public function testCountCommand() { - $cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $this->collection); - $cmd->bindParam('condition', array('name' => 'bread')); - $this->setExpectedException('GeneralException', 'FindMongoCommand error. Bind all required params first'); + $count_cmd = MongoCommandBuilder::factory(MongoCommandBuilder::COUNT, $this->collection); + $count_cmd->bindParam('condition', array('name' => 'bread')); + $count_result = $count_cmd->execute(); + $find_cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $this->collection); + $find_cmd->bindParam('condition', array('name' => 'bread'))->bindParam('fields', array()); + $find_result = $find_cmd->execute(); + $this->assertEquals(0, $count_result); + $this->assertEquals($count_result, $find_result->count()); + + + $cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $this->collection); + $cmd + ->bindParam('data', array('name' => 'insert')) + ->bindParam('safe', true); $cmd->execute(); + $cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $this->collection); + $cmd + ->bindParam('data', array('name' => 'insert')) + ->bindParam('safe', true); + $cmd->execute(); + + $count_cmd->bindParam('condition', array('name' => 'insert')); + $this->assertEquals(2, $count_cmd->execute()); + $find_cmd->bindParam('condition', array('name' => 'insert')); + $this->assertEquals($find_cmd->execute()->count(), $count_cmd->execute()); + } /** @@ -305,6 +327,14 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase */ public function testToString() { + $cmd = MongoCommandBuilder::factory(MongoCommandBuilder::COUNT, new CollectionMock()); + $cmd->bindParam('condition', array()); + $this->assertStringStartsWith('Collection: CollectionMock', $cmd->__toString()); + + $cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, new CollectionMock()); + $cmd->bindParam('condition', array()); + $this->assertStringStartsWith('Collection: CollectionMock', $cmd->__toString()); + $cmd = MongoCommandBuilder::factory(MongoCommandBuilder::COMMAND, new CollectionMock()); $this->assertSame('Command properties not set', $cmd->__toString()); $cmd->bindParam('command', array()); @@ -326,8 +356,6 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase ->bindParam('safe', true); $this->assertContains('Bulk insert: TRUE', $cmd->__toString()); - $cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $this->collection); - $this->assertSame('Command properties not set', $cmd->__toString()); $cmd->bindParam('condition', array('name' => 'insert'))->bindParam('fields', array()); $this->assertStringStartsWith('Collection: ', $cmd->__toString()); From 623666fb09392f819e694e102a225c257595ef2d Mon Sep 17 00:00:00 2001 From: Anton Grebnev Date: Mon, 2 Apr 2012 15:27:33 +0400 Subject: [PATCH 11/11] updated MongoDbCommand Profiler output --- model/MongoDbCommand.php | 26 +++++++++++++------------- tests/model/MongoDbCommandTest.php | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/model/MongoDbCommand.php b/model/MongoDbCommand.php index 4eae91e..c82c430 100644 --- a/model/MongoDbCommand.php +++ b/model/MongoDbCommand.php @@ -97,11 +97,11 @@ class FindMongoCommand extends MongoDbCommand public function __toString() { if ($this->checkParams()) { - $result = 'Collection: ' . $this->collection . PHP_EOL; + $result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL; ob_start(); var_dump($this->condition); $condition = ob_get_clean(); - $result .= 'Condition: ' . $condition . PHP_EOL; + $result .= 'Condition: ' . $condition; $result .= 'Type: FIND' . PHP_EOL; ob_start(); var_dump($this->fields); @@ -143,12 +143,12 @@ class CountMongoCommand extends MongoDbCommand public function __toString() { if ($this->checkParams()) { - $result = 'Collection: ' . $this->collection . PHP_EOL; + $result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL; $result .= 'Type: COUNT' . PHP_EOL; ob_start(); var_dump($this->condition); $condition = ob_get_clean(); - $result .= 'Condition: ' . $condition . PHP_EOL; + $result .= 'Condition: ' . $condition; $result .= 'Limit: ' . $this->limit . PHP_EOL; $result .= 'Skip: ' . $this->skip . PHP_EOL; return $result; @@ -199,12 +199,12 @@ class InsertMongoCommand extends MongoDbCommand public function __toString() { if ($this->checkParams()) { - $result = 'Collection: ' . $this->collection . PHP_EOL; + $result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL; $result .= 'Type: INSERT' . PHP_EOL; ob_start(); var_dump($this->data); $data = ob_get_clean(); - $result .= 'Data: ' . $data . PHP_EOL; + $result .= 'Data: ' . $data; $mult = $this->multiple ? 'TRUE' : 'FALSE'; $result .= 'Bulk insert: ' . $mult . PHP_EOL; $safe = $this->safe ? 'TRUE' : 'FALSE'; @@ -248,16 +248,16 @@ class UpdateMongoCommand extends MongoDbCommand public function __toString() { if ($this->checkParams()) { - $result = 'Collection: ' . $this->collection . PHP_EOL; + $result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL; $result .= 'Type: UPDATE' . PHP_EOL; ob_start(); var_dump($this->condition); $condition = ob_get_clean(); - $result .= 'Condition: ' . $condition . PHP_EOL; + $result .= 'Condition: ' . $condition; ob_start(); var_dump($this->data); $data = ob_get_clean(); - $result .= 'Data: ' . $data . PHP_EOL; + $result .= 'Data: ' . $data; $mult = $this->multiple ? 'TRUE' : 'FALSE'; $result .= 'Multiple fields: ' . $mult . PHP_EOL; $upsert = $this->upsert ? 'TRUE' : 'FALSE'; @@ -294,12 +294,12 @@ class RemoveMongoCommand extends MongoDbCommand public function __toString() { if ($this->checkParams()) { - $result = 'Collection: ' . $this->collection . PHP_EOL; + $result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL; $result .= 'Type: REMOVE' . PHP_EOL; ob_start(); var_dump($this->condition); $condition = ob_get_clean(); - $result .= 'Condition: ' . $condition . PHP_EOL; + $result .= 'Condition: ' . $condition; $safe = $this->safe ? 'TRUE' : 'FALSE'; $result .= 'Safe operation: ' . $safe . PHP_EOL; return $result; @@ -335,12 +335,12 @@ class CommandMongoCommand extends MongoDbCommand public function __toString() { if ($this->checkParams()) { - $result = 'Collection: ' . $this->collection . PHP_EOL; + $result = PHP_EOL . 'Collection: ' . $this->collection . PHP_EOL; $result .= 'Type: COMMAND' . PHP_EOL; ob_start(); var_dump($this->command); $command = ob_get_clean(); - $result .= 'Command: ' . $command . PHP_EOL; + $result .= 'Command: ' . $command; return $result; } else { return 'Command properties not set'; diff --git a/tests/model/MongoDbCommandTest.php b/tests/model/MongoDbCommandTest.php index 1963318..69fe5b5 100644 --- a/tests/model/MongoDbCommandTest.php +++ b/tests/model/MongoDbCommandTest.php @@ -330,7 +330,7 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase $cmd = MongoCommandBuilder::factory(MongoCommandBuilder::COUNT, new CollectionMock()); $cmd->bindParam('condition', array()); $this->assertStringStartsWith('Collection: CollectionMock', $cmd->__toString()); - + $cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, new CollectionMock()); $cmd->bindParam('condition', array()); $this->assertStringStartsWith('Collection: CollectionMock', $cmd->__toString());