예제 #1
0
 /**
  * @test
  */
 public function shouldBuildNotExistsClause()
 {
     // when
     $result = WhereClause::notExists(Product::where(array('name' => 'phone')));
     // then
     $this->assertEquals(array('phone'), $result->getParameters());
     Assert::thatString($result->toSql())->startsWith('NOT EXISTS (SELECT')->endsWith('FROM products WHERE name = ?)');
 }
예제 #2
0
 /**
  * @test
  */
 public function shouldTreatEmptyWhereClauseAsNothingWasGivenAsParameter()
 {
     // given
     Product::create(array('name' => 'one'));
     Product::create(array('name' => 'two'));
     // when
     $products = Product::where(new EmptyWhereClause())->fetchAll();
     // then
     Assert::thatArray($products)->hasSize(2);
 }
예제 #3
0
 /**
  * @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());
 }
예제 #4
0
 /**
  * @test
  */
 public function shouldFetchIteratorAndFetchRelationsInBatches()
 {
     //given
     Product::create(array('name' => '1', 'id_category' => Category::create(array('name' => 'cat1'))->getId()));
     Product::create(array('name' => '2', 'id_category' => Category::create(array('name' => 'cat2'))->getId()));
     Product::create(array('name' => '3', 'id_category' => Category::create(array('name' => 'cat3'))->getId()));
     Stats::reset();
     //when
     $results = Product::where()->with('category')->fetchIterator(2);
     //then
     Assert::thatArray(iterator_to_array($results))->extracting('name')->containsExactly('1', '2', '3');
     $this->assertEquals(3, Stats::getNumberOfQueries());
 }
예제 #5
0
 /**
  * @group non-sqlite3
  * @test
  */
 public function shouldReturnModelUsingRegexpRestriction()
 {
     //given
     $product = Product::create(array('name' => 'name1', 'description' => 'desc'));
     Product::create(array('name' => 'other product', 'description' => 'desc'));
     //when
     $loadedProduct = Product::where(array('name' => Restrictions::regexp('ame')))->fetch();
     //then
     Assert::thatModel($loadedProduct)->isEqualTo($product);
 }
예제 #6
0
 /**
  * @group non-sqlite3
  * @test
  */
 public function shouldSelectForUpdate()
 {
     // given
     Product::create(array('name' => 'Sport', 'price' => '123'));
     // when
     $products = Product::where()->lockForUpdate()->fetchAll();
     // then
     $this->assertCount(1, $products);
 }