/** * @test * @group postgres */ public function shouldBatchInsertWhenModelHasFetchedRelation() { //given $product1 = new Product(array('name' => 'product1')); $product2 = new Product(array('name' => 'product2')); $product1->category; $inserter = new BatchInserter(); $inserter->add($product1); $inserter->add($product2); //when $inserter->execute(); //then $this->assertNotNull(Product::where(array('name' => 'product1'))->fetch()); $this->assertNotNull(Product::where(array('name' => 'product2'))->fetch()); }
/** * @test */ public function shouldThrowOnBatchInsert() { //given $previous = Config::getValue('sql_dialect'); Config::overrideProperty('sql_dialect')->with('Ouzo\\Db\\Dialect\\MySqlDialect'); $inserter = new BatchInserter(); $inserter->add(new Product(array('name' => 'product1'))); //when CatchException::when($inserter)->execute(); //then CatchException::assertThat()->hasMessage("Batch insert not supported in mysql")->isInstanceOf('InvalidArgumentException'); Config::overrideProperty('sql_dialect')->with($previous); }