Exemplo n.º 1
0
 public function setUp()
 {
     TestSchema::deleteAll([]);
     for ($i = 0; $i < 100; $i++) {
         $model = new TestSchema(['title' => 'Title' . $i, 'object' => ['id' => $i, 'name' => 'Obj' . $i]]);
         $model->save();
         $this->_ids[] = $model->id;
     }
 }
Exemplo n.º 2
0
 /**
  * @iterations 500
  */
 public function inserting()
 {
     $length = 100;
     $rnd = rand(0, 999999999);
     $randomString = substr(str_shuffle('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, $length);
     $model = new TestSchema();
     $model->title = $randomString;
     $model->object = ['rnd' => $rnd, 'type' => $rnd > 999999999 / 2 ? 1 : 2];
     $model->save();
     $this->_ids[] = $model->_id;
 }
Exemplo n.º 3
0
 public function testStats()
 {
     //$stats = TestSchema::getCollection()->stats();
     //$this->assertTrue(is_array($stats));
     //$this->assertEquals(['ok' => 0, 'errmsg' => 'Collection [reach_testing.test_model_mongo_document] not found.'], $stats);
     $model = new TestSchema(['title' => 'CollectionStatsTitle']);
     $model->save();
     $stats = TestSchema::getCollection()->stats();
     $this->assertTrue(is_array($stats));
     $this->assertEquals(1, $stats['ok']);
 }
Exemplo n.º 4
0
 public function testIdentityMapOverflow()
 {
     $model = new TestSchema(['title' => 'TitleFirst']);
     $model->save();
     $first_id = $model->_id;
     for ($i = 0; $i < 1000; $i++) {
         $model = new TestSchema(['title' => 'Title' . $i]);
         $model->save();
     }
     $this->assertFalse(TestSchema::getCollection()->getIdentityMap($first_id));
     TestSchema::deleteAll();
 }
Exemplo n.º 5
0
 public function testRelationDocumentSaveAndFetch()
 {
     $document = new TestSchema();
     $document->title = 'TestSchemaTitle';
     $document->object = new \stdClass();
     $document->save();
     $stdClassEmbedOne = new \stdClass();
     $stdClassEmbedOne->user_id = new \MongoId();
     $stdClassEmbedOne->title = 'stdClassTitle';
     $testSchema = TestSchema::findOne();
     $model = new TestRelDocument();
     $model->title = 'TestRelDocumentTitle';
     $model->testSchemaRefPk = $testSchema;
     $model->testSchemaRefOne = $testSchema;
     $model->stdClassEmbedOne = $stdClassEmbedOne;
     $model->testSchemaEmbedOne = $testSchema;
     $model->testSchemaRefMany = [$testSchema, $testSchema];
     $model->testSchemaEmbedMany = [$testSchema, $stdClassEmbedOne];
     $model->save();
     // Save
     $document = TestRelDocument::getMongoCollection()->findOne();
     $this->assertEquals('TestRelDocumentTitle', $document['title']);
     $this->assertEquals($testSchema->_id, $document['test_schema_id']);
     $this->assertEquals(['$ref' => 'test_model_mongo_document', '$id' => $testSchema->_id], $document['ref_one']);
     $this->assertTrue(is_array($document['ref_many']));
     $this->assertEquals([['$ref' => 'test_model_mongo_document', '$id' => $testSchema->_id], ['$ref' => 'test_model_mongo_document', '$id' => $testSchema->_id]], $document['ref_many']);
     $this->assertEquals(['user_id' => $stdClassEmbedOne->user_id, 'title' => 'stdClassTitle'], $document['std_embed_one']);
     $this->assertEquals($testSchema->title, $document['embed_one']['title']);
     $this->assertEquals($testSchema->_id, $document['embed_one']['_id']);
     $this->assertTrue(is_array($document['embed_many']));
     $this->assertEquals([$testSchema->title, $stdClassEmbedOne->title], [$document['embed_many'][0]['title'], $document['embed_many'][1]['title']]);
     // Fetch All
     //$testRelDocument = TestRelDocument::find();
     // Fetch One
     $testRelDocument = TestRelDocument::findOne();
     $model = $testRelDocument->testSchemaRefPk;
     $this->assertInstanceOf('\\Model\\Mongo\\TestSchema', $model);
     $this->assertEquals('TestSchemaTitle', $model->title);
     $testRelDocument->testSchemaRefOne;
     $model = $testRelDocument->testSchemaRefOne;
     $this->assertInstanceOf('\\Model\\Mongo\\TestSchema', $model);
     $this->assertEquals('TestSchemaTitle', $model->title);
     $models = $testRelDocument->testSchemaRefMany;
     $this->assertTrue(is_array($models));
     $this->assertInstanceOf('\\Model\\Mongo\\TestSchema', $models[0]);
     $this->assertEquals('TestSchemaTitle', $models[0]->title);
     $this->assertCount(2, $models);
     $model = $testRelDocument->stdClassEmbedOne;
     $this->assertInstanceOf('\\stdClass', $model);
     $this->assertEquals('stdClassTitle', $model->title);
     $this->assertEquals($stdClassEmbedOne->user_id, $model->user_id);
     $model = $testRelDocument->testSchemaEmbedOne;
     $this->assertInstanceOf('\\Model\\Mongo\\TestSchema', $model);
     $this->assertEquals('TestSchemaTitle', $model->title);
     $models = $testRelDocument->testSchemaEmbedMany;
     $this->assertTrue(is_array($models));
     $this->assertInstanceOf('\\Model\\Mongo\\TestSchema', $models[0]);
     $this->assertEquals('TestSchemaTitle', $models[0]->title);
     $this->assertCount(2, $models);
     // Delete cascade
     //$testRelDocument->delete();
 }