public function test_if_apply_returns_data() { $class = $this->repository->model(); $result = $this->criteria->apply(new $class(), $this->repository)->get()->first(); $this->assertEquals('Category 1', $result->name); $this->assertEquals('Description 1', $result->description); }
public function test_can_list_category() { $result = $this->repository->all(); $this->assertCount(3, $result); $this->assertNotNull($result[0]->description); $result = $this->repository->all(['name']); $this->assertNull($result[0]->description); }
public function test_can_findby_categories() { $result = $this->repository->findBy('name', 'Category 1'); $this->assertCount(1, $result); $this->assertInstanceOf(Category::class, $result[0]); $this->assertEquals('Category 1', $result[0]->name); $result = $this->repository->findBy('name', 'Category 10'); $this->assertCount(0, $result); $result = $this->repository->findBy('name', 'Category 1', ['name']); $this->assertCount(1, $result); $this->assertInstanceOf(Category::class, $result[0]); $this->assertNull($result[0]->description); }
public function test_can_clear_criterias() { $this->createCategoryDescription(); $criteria1 = new FindByName('Category Two'); $criteria2 = new OrderDescById(); $this->repository->addCriteria($criteria1)->addCriteria($criteria2); $this->assertInstanceOf(CategoryRepository::class, $this->repository->clearCriteria()); $result = $this->repository->findBy('description', 'Description'); $this->assertCount(3, $result); $reflectionClass = new \ReflectionClass($this->repository); $reflectionProperty = $reflectionClass->getProperty('model'); $reflectionProperty->setAccessible(true); $result = $reflectionProperty->getValue($this->repository); $this->assertInstanceOf(Category::class, $result); }