コード例 #1
0
 public function setup()
 {
     $this->connectionMock = $this->getMockBuilder('MartynBiz\\Mongo\\Connection')->disableOriginalConstructor()->getMock();
     // mock method to return mock collection
     $this->connectionMock->method('getNextSequence')->willReturn(1);
     // reset Connection as it's being used across multiple tests (unit, int)
     Connection::getInstance()->resetInstance();
     // swap the instance as it's a singleton
     Connection::setInstance($this->connectionMock);
 }
コード例 #2
0
ファイル: SoftDeletes.php プロジェクト: martynbiz/php-mongo
 /**
  * Override the delete method to update with deleted_at instead
  */
 public function delete()
 {
     // check _id is set
     if (!isset($this->data['_id'])) {
         return false;
     }
     $query = array('_id' => $this->data['_id']);
     // append deleted_at date
     $values = array('deleted_at' => new \MongoDate(time()));
     $options = array('multi' => false);
     // update
     $result = Connection::getInstance()->update(static::$collection, $query, $values, $options);
     // merge values into data - if insert, will add id and _id
     $this->data = array_merge($this->data, $values);
     return $result;
 }
コード例 #3
0
ファイル: TestCase.php プロジェクト: martynbiz/slim-mvc
 public function setUp()
 {
     // =========================
     // Instantiate the app and container
     $settings = (require APPLICATION_PATH . '/config/global.php');
     $this->app = $app = new \Slim\App($settings);
     $this->container = $app->getContainer();
     // =========================
     // Set up dependencies
     require APPLICATION_PATH . '/dependencies.php';
     // =========================
     // Create test stubs
     // In some cases, where services have become "frozen", we need to define
     // mocks before they are loaded
     //  auth service
     $authMock = $this->getMockBuilder('Wordup\\Auth\\Auth')->disableOriginalConstructor()->getMock();
     $this->container['auth'] = $authMock;
     // =========================
     // Register middleware
     require APPLICATION_PATH . '/middleware.php';
     // =========================
     // Register routes
     require APPLICATION_PATH . '/routes.php';
     $this->app = $app;
     // =========================
     // Init mongo
     Connection::getInstance()->init($settings['mongo_testing']);
     // =========================
     // create fixtures
     $this->adminUser = new User(array('first_name' => 'Martyn', 'last_name' => 'Bissett', 'email' => '*****@*****.**', 'password' => 'mypass'));
     $this->adminUser->role = User::ROLE_ADMIN;
     $this->adminUser->save();
     $this->editorUser = new User(array('first_name' => 'Neil', 'last_name' => 'McInness', 'email' => '*****@*****.**', 'password' => 'mypass'));
     $this->editorUser->role = User::ROLE_EDITOR;
     $this->editorUser->save();
     $this->ownerUser = new User(array('first_name' => 'Louise', 'last_name' => 'McInness', 'email' => '*****@*****.**', 'password' => 'mypass'));
     $this->ownerUser->role = User::ROLE_MEMBER;
     $this->ownerUser->save();
     $this->randomUser = new User(array('first_name' => 'Moses', 'last_name' => 'Cat', 'email' => '*****@*****.**', 'password' => 'mypass'));
     $this->randomUser->role = User::ROLE_MEMBER;
     $this->randomUser->save();
     $this->article = new Article(array('title' => 'A long time ago in a galaxy far far away...', 'description' => '...'));
     $this->article->author = $this->ownerUser;
     $this->article->save();
     $this->tag = new Tag(array('name' => 'Travel', 'slug' => 'travel'));
     $this->tag->save();
 }
コード例 #4
0
ファイル: Mongo.php プロジェクト: martynbiz/php-mongo
 /**
  * Will convert objects to arrays
  * @param int $deep How deep to recursively convert to arrays
  * @param mixed $values Used by the class when recursively converting arrays
  * @return array
  */
 public function toArray($deep = 2, $values = null)
 {
     if (is_null($values)) {
         $values = $this->data;
     }
     // look for
     foreach ($values as $name => &$value) {
         if ($value instanceof \MongoId) {
             $value = $value->__toString();
         } elseif ($value instanceof Mongo) {
             if ($deep > 0) {
                 $value = $value->toArray($deep - 1);
             } else {
                 $value = '...';
             }
         } elseif (\MongoDBRef::isRef($value)) {
             if ($deep > 0) {
                 $value = Connection::getInstance(self::$conn)->findOne($value['$ref'], array('_id' => $value['$id']));
             } else {
                 $value = '...';
             }
         } elseif (is_array($value)) {
             $value = $this->toArray($deep, $value);
         } else {
             // run $value through get() as there may be some custom getter methods
             // as it may be a array or instances, we will skip if $name is not string
             if (is_string($name)) {
                 $value = $this->get($name);
             }
         }
     }
     return $values;
 }
コード例 #5
0
 public function testInsertCreateSequenceNumbers()
 {
     // reset Connection as it's being used across multiple tests (unit, int)
     $connection = Connection::getInstance();
     // don't really know where sequence will be up to, so we'll start from
     // whatever it gives us here
     $baseSequence = $connection->getNextSequence('users');
     $this->assertEquals($baseSequence + 1, $connection->getNextSequence('users'));
     $this->assertEquals($baseSequence + 2, $connection->getNextSequence('users'));
     // upsert
     $this->assertEquals($baseSequence + 3, $connection->getNextSequence('users'));
     // upsert
 }
コード例 #6
0
ファイル: ArticleTest.php プロジェクト: martynbiz/slim-mvc
 public function tearDown()
 {
     // reset Connection as it's being used across multiple tests (unit, int)
     Connection::getInstance()->resetInstance();
 }
コード例 #7
0
 public function testGetSetAppendClassMap()
 {
     $classmap = Connection::getInstance()->getClassmap();
     $this->assertEquals(['users' => 'User'], $classmap);
     Connection::getInstance()->setClassmap(['articles' => 'Articles']);
     $classmap = Connection::getInstance()->getClassmap();
     $this->assertEquals(['articles' => 'Articles'], $classmap);
     Connection::getInstance()->appendClassmap(['photos' => 'Photos']);
     $classmap = Connection::getInstance()->getClassmap();
     $this->assertEquals(['articles' => 'Articles', 'photos' => 'Photos'], $classmap);
 }