Exemple #1
0
 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());
 }
Exemple #2
0
 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();
             }
         }
     }
 }