Example #1
0
         $query = new Query(['model' => $this->gallery, 'finders' => $finders]);
         $result = $query->fooGallery()->all()->data();
         expect($result)->toEqual([['id' => '1', 'name' => 'Foo Gallery']]);
     });
     it("throws an exception if no `Finders` has been defined", function () {
         $this->fixtures->populate('gallery');
         $closure = function () {
             $this->query->fooGallery();
         };
         expect($closure)->toThrow(new DatabaseException("No finders instance has been defined."));
     });
     it("throws an exception if the finder method doesn't exist", function () {
         $this->fixtures->populate('gallery');
         $closure = function () {
             $query = new Query(['model' => $this->gallery, 'finders' => new Finders()]);
             $query->fooGallery();
         };
         expect($closure)->toThrow(new ChaosException("Unexisting finder `'fooGallery'`."));
     });
 });
 describe("->fields()", function () {
     it("sets an aliased COUNT(*) field", function () {
         $this->fixtures->populate('gallery');
         $result = $this->query->fields([[':as' => [[':plain' => 'COUNT(*)'], [':name' => 'count']]]])->first(['return' => 'array']);
         expect($result)->toEqual(['count' => 2]);
     });
 });
 describe("->where()", function () {
     it("filters out according conditions", function () {
         $this->fixtures->populate('gallery');
         $result = $this->query->where(['name' => 'Foo Gallery'])->get();