상속: extends Ouzo\Model
예제 #1
0
 /**
  * @test
  */
 public function shouldCallDbFunction()
 {
     //given
     $category = Category::create(array('name' => 'test'));
     //when
     $name = $category->getName('test');
     //then
     $this->assertEquals('test', $name);
 }
예제 #2
0
 /**
  * @test
  */
 public function shouldOrderEagerlyFetchedRelation()
 {
     //given
     $category = Category::where(array('name' => 'sony'))->fetch();
     //when
     $products = $category->products_ordered_by_name;
     //then
     Assert::thatArray($products)->onProperty('name')->containsExactly('a', 'b', 'c');
 }
예제 #3
0
 /**
  * @test
  */
 public function shouldNotCompareRelations()
 {
     $cars = Category::create(array('name' => 'phones'));
     $product = Product::create(array('name' => 'Reno', 'id_category' => $cars->getId()));
     $productWithoutLoadedCategory = Product::findById($product->getId());
     // when relation is loaded
     $product->category;
     //then
     Assert::thatModel($product)->hasSameAttributesAs($productWithoutLoadedCategory);
 }
예제 #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());
 }
 /**
  * @test
  */
 public function shouldFetchHasOneWithAlias()
 {
     //when
     $searchCategory = Category::alias('c')->innerJoin('product_named_billy', 'p')->fetch();
     //then
     $product = self::getNoLazy($searchCategory, 'product_named_billy');
     $this->assertEquals('billy', $product->name);
 }
예제 #6
0
 /**
  * @test
  */
 public function shouldAcceptSingleParamInFindBySql()
 {
     //given
     Category::create(array('name' => 'phones1'));
     Category::create(array('name' => 'phones2'));
     //when
     $found = Category::findBySql("SELECT * FROM categories where name = ?", 'phones1');
     //then
     Assert::thatArray($found)->onProperty('name')->containsOnly('phones1');
 }