コード例 #1
0
ファイル: DbRefTest.php プロジェクト: vegas-cmf/odm
 public function testShouldCreateDBRefFromCollection()
 {
     $collection = new Product();
     $collection->setName('Test');
     $collection->save();
     $dbRef = DbRef::create($collection->getSource(), $collection);
     $this->assertTrue(\MongoDbRef::isRef($dbRef));
     $this->assertEquals($collection->getId(), $dbRef['$id']);
     $this->assertEquals($collection->getSource(), $dbRef['$ref']);
 }
コード例 #2
0
 public function testQueryWithGivenFields()
 {
     /** @var Product $collection */
     $collection = new Product();
     $collection->setName('test');
     $collection->setPrice(199);
     $collection->save();
     $parameters = ['fields' => ['name']];
     $cursor = Product::_getCursor($parameters, $collection, $collection->getConnection());
     $cursor = new \Fixtures\Collection\Lib\ExtendedCursor($cursor, $collection, is_array($parameters) && isset($parameters['fields']) ? $parameters['fields'] : null);
     $fields = $cursor->getFields();
     $this->assertEquals(1, count($fields));
     $item = $cursor->current();
     $this->assertEquals($collection->getName(), $item->getName());
 }
コード例 #3
0
ファイル: CollectionTest.php プロジェクト: vegas-cmf/odm
 public function testShouldSaveNotLoadedReference()
 {
     $category = new Category();
     $category->setName('Category 1');
     $category->setDesc('Category 1 desc');
     $category->save();
     $product = new Product();
     $product->setCategory($category);
     $product->setName('Product 1');
     $product->setPrice(100);
     $product->setIsActive(true);
     $product->setCreatedAt(time());
     $product->save();
     $product = Product::findById($product->getId());
     $product->save();
     $product = Product::findById($product->getId());
     $category1 = $product->getCategory();
     $category2 = $product->getCategory();
     $this->assertInstanceOf('Fixtures\\Collection\\Category', $category1);
     $this->assertInstanceOf('Fixtures\\Collection\\Category', $category2);
     $this->assertSame($category2->getName(), $category1->getName());
 }
コード例 #4
0
ファイル: BenchmarkTest.php プロジェクト: vegas-cmf/odm
 private function setupDummyData($mainCategoryNum = 10, $subCategoryNum = 100, $productNum = 40)
 {
     for ($i = 0; $i <= $mainCategoryNum; $i++) {
         /** @var Category $parent */
         $parent = new Category();
         $parent->setCategory(null);
         $parent->setName('Category ' . $i);
         $parent->setDesc('Lorem ipsum dolor ' . $i . 'sit amet');
         $parent->save();
         for ($k = 0; $k <= $subCategoryNum; $k++) {
             /** @var Category $category */
             $category = new Category();
             $category->setCategory($parent);
             $category->setName('Subcategory' . $k . '-' . $i);
             $category->setDesc('test ' . uniqid('', true));
             $category->save();
             for ($j = 0; $j <= $productNum; $j++) {
                 /** @var Product $parent */
                 $parent = new Product();
                 $parent->setCategory($category);
                 $parent->setName('Product ' . $j);
                 $parent->setPrice(rand(89, 8899));
                 $parent->setIsActive(true);
                 $parent->save();
             }
         }
     }
 }