/** * @group postgres * @test */ public function shouldBatchInsertWithoutReturning() { //given $product1 = Product::create(array('name' => 'product1')); $order1 = Order::create(array('name' => 'order1')); $product2 = Product::create(array('name' => 'product2')); $order2 = Order::create(array('name' => 'order2')); $inserter = new BatchInserter(); $inserter->add(new OrderProduct(array('id_order' => $order1->getId(), 'id_product' => $product1->getId()))); $inserter->add(new OrderProduct(array('id_order' => $order2->getId(), 'id_product' => $product2->getId()))); //when $inserter->execute(); //then $this->assertNotNull(OrderProduct::where(array('id_order' => $order1->getId()))->fetch()); $this->assertNotNull(OrderProduct::where(array('id_order' => $order2->getId()))->fetch()); }
/** * @test */ public function shouldOptimizeDuplicatedRelationFetches() { //given $category = Category::create(array('name' => 'phones')); $manufacturer = Manufacturer::create(array('name' => 'sony')); $product = Product::create(array('name' => 'sony', 'id_category' => $category->getId(), 'id_manufacturer' => $manufacturer->id)); OrderProduct::create(array('id_product' => $product->getId())); Stats::reset(); //when $orderProduct = OrderProduct::where()->with('product->category')->with('product->manufacturer')->fetch(); //then $this->assertEquals($product->id, $orderProduct->product->id); $this->assertEquals($category, $orderProduct->product->category); $this->assertEquals($manufacturer, $orderProduct->product->manufacturer); $this->assertEquals(4, Stats::getNumberOfQueries()); }