コード例 #1
0
ファイル: Resource.spec.php プロジェクト: crysalead/resource
            $r->resource('Tag');
        });
        $this->connection = $connection;
        $this->fixtures = new Fixtures(['connection' => $connection, 'fixtures' => ['gallery' => 'Lead\\Resource\\Spec\\Fixture\\Schema\\Gallery', 'gallery_detail' => 'Lead\\Resource\\Spec\\Fixture\\Schema\\GalleryDetail', 'image' => 'Lead\\Resource\\Spec\\Fixture\\Schema\\Image', 'image_tag' => 'Lead\\Resource\\Spec\\Fixture\\Schema\\ImageTag', 'tag' => 'Lead\\Resource\\Spec\\Fixture\\Schema\\Tag']]);
    });
    afterEach(function () {
        $this->fixtures->drop();
        $this->fixtures->reset();
    });
    it("loads a resource", function () {
        $this->fixtures->populate('gallery');
        $r = $this->router;
        $route = $r->route('gallery/1', 'GET');
        $route->dispatch($this->response);
        expect($route->params)->toBe(['relation' => null, 'rid' => null, 'resource' => 'gallery', 'id' => '1', 'action' => null]);
        $data = $route->dispatched->data();
        $expected = Gallery::load(1)->first()->data();
        expect($data['gallery']->data())->toBe($expected);
    });
    it("loads some related resource", function () {
        $this->fixtures->populate('gallery');
        $this->fixtures->populate('image');
        $r = $this->router;
        $route = $r->route('gallery/1/image', 'GET');
        $route->dispatch($this->response);
        expect($route->params)->toBe(['relation' => 'gallery', 'rid' => '1', 'resource' => 'image', 'id' => null, 'action' => null]);
        $data = $route->dispatched->data();
        $expected = Image::find(['conditions' => ['gallery_id' => 1]])->all()->data();
        expect($data['image']->data())->toBe($expected);
    });
});
コード例 #2
0
ファイル: Payload.spec.php プロジェクト: crysalead/resource
     $this->fixtures = new Fixtures(['connection' => $connection, 'fixtures' => ['gallery' => 'Lead\\Resource\\Spec\\Fixture\\Schema\\Gallery', 'image' => 'Lead\\Resource\\Spec\\Fixture\\Schema\\Image', 'image_tag' => 'Lead\\Resource\\Spec\\Fixture\\Schema\\ImageTag', 'tag' => 'Lead\\Resource\\Spec\\Fixture\\Schema\\Tag']]);
 });
 afterEach(function () {
     $this->fixtures->drop();
     $this->fixtures->reset();
 });
 describe("->set()", function () {
     it("sets an error with trying to add a non Chaos entity", function () {
         $payload = new Payload();
         $payload->set(['hello' => 'world']);
         expect($payload->errors())->toBe([['status' => 500, 'code' => 500, 'title' => "The JSON-API serializer only supports Chaos entities."]]);
     });
     it("adds validation errors", function () {
         $validator = Gallery::validator();
         $validator->rule('name', 'not:empty');
         $gallery = Gallery::create();
         $gallery->validates();
         $payload = new Payload();
         $payload->set($gallery);
         expect($payload->errors())->toBe([['status' => 422, 'code' => 0, 'title' => "Validation Error", 'meta' => [['name' => ['is required']]]]]);
     });
 });
 describe("->delete()", function () {
     it("sets a delete payload", function () {
         $this->fixtures->populate('image');
         $payload = new Payload();
         $images = Image::all();
         $payload->delete($images);
         expect($payload->serialize())->toEqual(['data' => [['type' => 'image', 'id' => 1], ['type' => 'image', 'id' => 2], ['type' => 'image', 'id' => 3], ['type' => 'image', 'id' => 4], ['type' => 'image', 'id' => 5]]]);
     });
 });