Exemple #1
0
    describe("::encode()", function () {
        it("encodes in json", function () {
            $json = Media::encode('json', ['key' => 'value']);
            expect($json)->toBe('{"key":"value"}');
        });
        it("encodes objects in json", function () {
            $json = Media::encode('json', new Collection(['key' => 'value']));
            expect($json)->toBe('{"key":"value"}');
        });
        it("encodes in form data", function () {
            $json = Media::encode('form', ['key1' => 'value1', 'key2' => 'value2']);
            expect($json)->toBe('key1=value1&key2=value2');
        });
    });
    describe("::decode()", function () {
        it("decodes json", function () {
            $data = Media::decode('json', '{"key":"value"}');
            expect($data)->toBe(['key' => 'value']);
        });
        it("decodes form data", function () {
            $data = Media::decode('form', 'key1=value1&key2=value2');
            expect($data)->toBe(['key1' => 'value1', 'key2' => 'value2']);
        });
    });
    describe("::to()", function () {
        it("delegates to `::encode()`", function () {
            expect(Media::class)->toReceive('::encode')->with('json', '', ['key' => 'value']);
            Media::to('json', '', ['key' => 'value']);
        });
    });
});