/** * @test */ function it_handles_basic_retrieval_operations() { // all $result = $this->repository->all(); $this->assertInstanceOf(Collection::class, $result, "Did not get Collection for all()"); $this->assertCount(3, $result, "Did not get correct count for all()"); // get an id that we can use find on $someId = $result->first()->id; $this->assertNotEmpty($someId, "Did not get a valid Model's id from the all() result"); // find $this->assertInstanceOf(Model::class, $this->repository->find($someId), "Did not get Model for find()"); // count $this->assertEquals(3, $this->repository->count(), "Did not get correct result for count()"); // first $this->assertInstanceOf(Model::class, $this->repository->first(), "Did not get Model for first() on all"); // findBy $this->assertInstanceOf(Model::class, $this->repository->findBy(self::UNIQUE_FIELD, '1337'), "Did not get Model for findBy() for unique field value"); // findAllBy $this->assertCount(2, $this->repository->findAllBy('active', true), "Did not get correct count for result for findAllBy(active = true)"); // paginate $this->assertCount(2, $this->repository->paginate(2), "Did not get correct count for paginate()"); // lists $list = $this->repository->lists(self::UNIQUE_FIELD); $this->assertCount(3, $list, "Did not get correct array count for lists()"); $this->assertContains('1337', $list, "Did not get correct array content for lists()"); }
/** * @test */ function where_has_criteria_works() { $this->repository->pushCriteria(new WhereHas('translations', function ($query) { return $query->where('translated_string', 'vertaalde_attribuutwaarde hoepla'); })); $result = $this->repository->all(); $this->assertCount(1, $result, "WhereHas Criteria doesn't work (wrong count)"); $this->assertEquals('1337', $result->first()->{self::UNIQUE_FIELD}, "WhereHas Criteria doesn't work (wrong model)"); }