Inheritance: extends Ouzo\Model
Beispiel #1
0
 /**
  * @test
  */
 public function shouldCallDbFunction()
 {
     //given
     $category = Category::create(array('name' => 'test'));
     //when
     $name = $category->getName('test');
     //then
     $this->assertEquals('test', $name);
 }
 /**
  * @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');
 }
Beispiel #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);
 }
 /**
  * @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);
 }
Beispiel #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');
 }