code
stringlengths 31
1.39M
| docstring
stringlengths 23
16.8k
| func_name
stringlengths 1
126
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
166
| url
stringlengths 50
220
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
public function __invoke($apiName, array $config)
{
return new CustomResolver((array) $config['resources']);
}
|
@param $apiName
@param array $config
@return CustomResolver
|
__invoke
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Resolver/CreateCustomResolver.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Resolver/CreateCustomResolver.php
|
Apache-2.0
|
public function testBinding()
{
config()->set('json-api-v1.resolver', 'my-resolver');
$this->app->instance('my-resolver', new CustomResolver([
'foobars' => Post::class,
]));
$post = factory(Post::class)->create();
$response = $this
->jsonApi('foobars')
->get(url('/api/v1/foobars', $post));
$response->assertFetchedOne([
'type' => 'foobars',
'id' => $post,
'attributes' => [
'title' => $post->title,
],
]);
}
|
Use a resolver returned from a container binding.
|
testBinding
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Resolver/ResolverTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Resolver/ResolverTest.php
|
Apache-2.0
|
public static function recordProvider()
{
$args = self::$defaults;
unset($args['index'], $args['create']);
return $args;
}
|
Provider of all routes that relate to a specific record, i.e. have an id in them.
@return array
|
recordProvider
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testDefaults($method, $url, $action)
{
$this->withRoutes(function (RouteRegistrar $api) {
$api->resource('posts', [
'has-one' => ['author'],
'has-many' => ['tags', 'comments'],
]);
});
$this->assertMatch($method, $url, '\\' . JsonApiController::class . $action);
}
|
@param $method
@param $url
@param $action
@dataProvider defaultsProvider
|
testDefaults
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testFluentDefaults($method, $url, $action)
{
$this->withFluentRoutes()->routes(function (RouteRegistrar $api) {
$api->resource('posts')->relationships(function (RelationshipsRegistration $rel) {
$rel->hasOne('author');
$rel->hasMany('tags');
$rel->hasMany('comments');
});
});
$this->assertMatch($method, $url, '\\' . JsonApiController::class . $action);
}
|
@param $method
@param $url
@param $action
@dataProvider defaultsProvider
|
testFluentDefaults
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testUriIsDifferentFromResourceType(string $method, string $url, string $action): void
{
$this->withFluentRoutes()->routes(function (RouteRegistrar $api) {
$api->resource('posts')->uri('blog_posts')->relationships(function (RelationshipsRegistration $rel) {
$rel->hasOne('author');
$rel->hasMany('tags');
$rel->hasMany('comments')->uri('post_comments');
});
});
$route = $this->assertMatch($method, $url, '\\' . JsonApiController::class . $action);
$this->assertSame('posts', $route->parameter('resource_type'));
if (Str::contains($url, 'post_comments')) {
$this->assertSame('comments', $route->parameter('relationship_name'));
}
}
|
@param $method
@param $url
@param $action
@dataProvider uriProvider
|
testUriIsDifferentFromResourceType
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testControllerIsTrue($method, $url, $action)
{
$this->withRoutes(function (RouteRegistrar $api) {
$api->resource('posts', [
'controller' => true,
'has-one' => 'author',
'has-many' => 'comments',
]);
});
$expected = 'DummyApp\Http\Controllers\PostsController';
$this->assertMatch($method, $url, $expected . $action);
}
|
@param $method
@param $url
@param $action
@dataProvider defaultsProvider
|
testControllerIsTrue
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testFluentControllerIsTrue($method, $url, $action)
{
$this->withFluentRoutes()->routes(function (RouteRegistrar $api) {
$api->resource('posts')->controller()->relationships(function (RelationshipsRegistration $rel) {
$rel->hasOne('author');
$rel->hasMany('tags');
$rel->hasMany('comments');
});
});
$expected = 'DummyApp\Http\Controllers\PostsController';
$this->assertMatch($method, $url, $expected . $action);
}
|
@param $method
@param $url
@param $action
@dataProvider defaultsProvider
|
testFluentControllerIsTrue
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testFluentControllerIsTrueAndSingular($method, $url, $action)
{
$this->withFluentRoutes()->singularControllers()->routes(function (RouteRegistrar $api) {
$api->resource('posts')->controller()->relationships(function (RelationshipsRegistration $rel) {
$rel->hasOne('author');
$rel->hasMany('tags');
$rel->hasMany('comments');
});
});
$expected = 'DummyApp\Http\Controllers\PostController';
$this->assertMatch($method, $url, $expected . $action);
}
|
@param $method
@param $url
@param $action
@dataProvider defaultsProvider
|
testFluentControllerIsTrueAndSingular
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testControllerIsString($method, $url, $action)
{
$expected = '\Foo\Bar';
$this->withRoutes(function (RouteRegistrar $api) use ($expected) {
$api->resource('posts', [
'controller' => $expected,
'has-one' => 'author',
'has-many' => 'comments',
]);
});
$this->assertMatch($method, $url, $expected . $action);
}
|
@param $method
@param $url
@param $action
@dataProvider defaultsProvider
|
testControllerIsString
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testFluentControllerIsString($method, $url, $action)
{
$expected = '\Foo\Bar';
$this->withRoutes(function (RouteRegistrar $api) use ($expected) {
$api->resource('posts')->controller($expected)->relationships(function (RelationshipsRegistration $rel) {
$rel->hasOne('author');
$rel->hasMany('tags');
$rel->hasMany('comments');
});
});
$this->assertMatch($method, $url, $expected . $action);
}
|
@param $method
@param $url
@param $action
@dataProvider defaultsProvider
|
testFluentControllerIsString
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testOnly($only, array $matches)
{
$this->withRoutes(function (RouteRegistrar $api) use ($only) {
$api->resource('posts', ['only' => $only]);
});
$this->assertRoutes($matches);
}
|
@param $only
@param array $matches
@dataProvider onlyProvider
|
testOnly
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testFluentOnly($only, array $matches)
{
$only = Arr::wrap($only);
$this->withRoutes(function (RouteRegistrar $api) use ($only) {
$api->resource('posts')->only(...$only);
});
$this->assertRoutes($matches);
}
|
@param $only
@param array $matches
@dataProvider onlyProvider
|
testFluentOnly
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testExcept($except, array $matches)
{
$this->withRoutes(function (RouteRegistrar $api) use ($except) {
$api->resource('posts', ['except' => $except]);
});
$this->assertRoutes($matches);
}
|
@param $except
@param array $matches
@dataProvider exceptProvider
|
testExcept
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testFluentExcept($except, array $matches)
{
$except = Arr::wrap($except);
$this->withRoutes(function (RouteRegistrar $api) use ($except) {
$api->resource('posts')->except(...$except);
});
$this->assertRoutes($matches);
}
|
@param $except
@param array $matches
@dataProvider exceptProvider
|
testFluentExcept
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testHasOneOnly($only, array $matches)
{
$this->withRoutes(function (RouteRegistrar $api) use ($only) {
$api->resource('posts', [
'has-one' => [
'author' => [
'only' => $only,
],
],
]);
});
$this->assertRoutes($matches);
}
|
@param $only
@param array $matches
@dataProvider hasOneOnlyProvider
|
testHasOneOnly
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testFluentHasOneOnly($only, array $matches)
{
$only = Arr::wrap($only);
$this->withFluentRoutes()->routes(function (RouteRegistrar $api) use ($only) {
$api->resource('posts')->relationships(function (RelationshipsRegistration $rel) use ($only) {
$rel->hasOne('author')->only(...$only);
});
});
$this->assertRoutes($matches);
}
|
@param $only
@param array $matches
@dataProvider hasOneOnlyProvider
|
testFluentHasOneOnly
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testHasOneExcept($except, array $matches)
{
$this->withRoutes(function (RouteRegistrar $api) use ($except) {
$api->resource('posts', [
'has-one' => [
'author' => [
'except' => $except,
],
],
]);
});
$this->assertRoutes($matches);
}
|
@param $except
@param array $matches
@dataProvider hasOneExceptProvider
|
testHasOneExcept
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testFluentHasOneExcept($except, array $matches)
{
$except = Arr::wrap($except);
$this->withRoutes(function (RouteRegistrar $api) use ($except) {
$api->resource('posts')->relationships(function (RelationshipsRegistration $rel) use ($except) {
$rel->hasOne('author')->except(...$except);
});
});
$this->assertRoutes($matches);
}
|
@param $except
@param array $matches
@dataProvider hasOneExceptProvider
|
testFluentHasOneExcept
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testHasManyOnly($only, array $matches)
{
$this->withRoutes(function (RouteRegistrar $api) use ($only) {
$api->resource('posts', [
'has-many' => [
'tags' => [
'only' => $only,
],
],
]);
});
$this->assertRoutes($matches);
}
|
@param $only
@param array $matches
@dataProvider hasManyOnlyProvider
|
testHasManyOnly
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testFluentHasManyOnly($only, array $matches)
{
$only = Arr::wrap($only);
$this->withRoutes(function (RouteRegistrar $api) use ($only) {
$api->resource('posts')->relationships(function (RelationshipsRegistration $rel) use ($only) {
$rel->hasMany('tags')->only(...$only);
});
});
$this->assertRoutes($matches);
}
|
@param $only
@param array $matches
@dataProvider hasManyOnlyProvider
|
testFluentHasManyOnly
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testHasManyExcept($except, array $matches)
{
$this->withRoutes(function (RouteRegistrar $api) use ($except) {
$api->resource('posts', [
'has-many' => [
'tags' => [
'except' => $except,
],
],
]);
});
$this->assertRoutes($matches);
}
|
@param $except
@param array $matches
@dataProvider hasManyExceptProvider
|
testHasManyExcept
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testFluentHasManyExcept($except, array $matches)
{
$except = Arr::wrap($except);
$this->withRoutes(function (RouteRegistrar $api) use ($except) {
$api->resource('posts')->relationships(function (RelationshipsRegistration $rel) use ($except) {
$rel->hasMany('tags')->except(...$except);
});
});
$this->assertRoutes($matches);
}
|
@param $except
@param array $matches
@dataProvider hasManyExceptProvider
|
testFluentHasManyExcept
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testResourceIdConstraint($method, $url)
{
$this->withRoutes(function (RouteRegistrar $api) {
$api->resource('posts', [
'has-one' => ['author'],
'has-many' => ['tags', 'comments'],
'id' => '^[A-Z]+$',
]);
});
$this->assertNotFound($method, $url);
}
|
@param $method
@param $url
@dataProvider recordProvider
|
testResourceIdConstraint
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testFluentResourceIdConstraint($method, $url)
{
$this->withRoutes(function (RouteRegistrar $api) {
$api->resource('posts')->id('^[A-Z]+$')->relationships(function (RelationshipsRegistration $rel) {
$rel->hasOne('author');
$rel->hasMany('tags');
$rel->hasMany('comments');
});
});
$this->assertNotFound($method, $url);
}
|
@param $method
@param $url
@dataProvider recordProvider
|
testFluentResourceIdConstraint
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testDefaultIdConstraint($method, $url)
{
$this->withRoutes(function (RouteRegistrar $api) {
$api->resource('posts', [
'has-one' => ['author'],
'has-many' => ['tags', 'comments'],
]);
}, ['id' => '^[A-Z]+$']);
$this->assertNotFound($method, $url);
}
|
@param $method
@param $url
@dataProvider recordProvider
|
testDefaultIdConstraint
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testFluentDefaultIdConstraint($method, $url)
{
$this->withFluentRoutes()->defaultId('^[A-Z]+$')->routes(function (RouteRegistrar $api) {
$api->resource('posts')->relationships(function (RelationshipsRegistration $rel) {
$rel->hasOne('author');
$rel->hasMany('tags');
$rel->hasMany('comments');
});
});
$this->assertNotFound($method, $url);
}
|
@param $method
@param $url
@dataProvider recordProvider
|
testFluentDefaultIdConstraint
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testDefaultIdConstraintCanBeIgnoredByResource($method, $url)
{
$this->withRoutes(function (RouteRegistrar $api) {
$api->resource('posts', [
'has-one' => ['author'],
'has-many' => ['tags', 'comments'],
'id' => null,
]);
}, ['id' => '^[A-Z]+$']);
$this->assertMatch($method, $url);
}
|
If there is a default ID constraint, it can be removed using `null` on a resource.
@param $method
@param $url
@dataProvider recordProvider
|
testDefaultIdConstraintCanBeIgnoredByResource
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testFluentDefaultIdConstraintCanBeIgnoredByResource($method, $url)
{
$this->withFluentRoutes()->defaultId('^[A-Z]+$')->routes(function (RouteRegistrar $api) {
$api->resource('posts')->id(null)->relationships(function (RelationshipsRegistration $rel) {
$rel->hasOne('author');
$rel->hasMany('tags');
$rel->hasMany('comments');
});
});
$this->assertMatch($method, $url);
}
|
If there is a default ID constraint, it can be removed using `null` on a resource.
@param $method
@param $url
@dataProvider recordProvider
|
testFluentDefaultIdConstraintCanBeIgnoredByResource
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testResourceIdConstraintOverridesDefaultIdConstraint($method, $url)
{
$this->withRoutes(function (RouteRegistrar $api) {
$api->resource('posts', [
'has-one' => ['author'],
'has-many' => ['tags', 'comments'],
'id' => '^[A-Z]+$',
]);
}, ['id' => '^[0-9]+$']);
$this->assertNotFound($method, $url);
}
|
If there is a default and a resource ID constraint, the resource ID constraint is used.
@param $method
@param $url
@dataProvider recordProvider
|
testResourceIdConstraintOverridesDefaultIdConstraint
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testFluentResourceIdConstraintOverridesDefaultIdConstraint($method, $url)
{
$this->withFluentRoutes()->defaultId('^[0-9]+$')->routes(function (RouteRegistrar $api) {
$api->resource('posts')->id('^[A-Z]+$')->relationships(function (RelationshipsRegistration $rel) {
$rel->hasOne('author');
$rel->hasMany('tags');
$rel->hasMany('comments');
});
});
$this->assertNotFound($method, $url);
}
|
If there is a default and a resource ID constraint, the resource ID constraint is used.
@param $method
@param $url
@dataProvider recordProvider
|
testFluentResourceIdConstraintOverridesDefaultIdConstraint
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testMultiWordResourceType($resourceType)
{
$this->withRoutes(function (RouteRegistrar $api) use ($resourceType) {
$api->resource($resourceType, [
'has-one' => ['author'],
'has-many' => ['tags'],
]);
});
$base = "/api/v1/$resourceType";
$this->assertMatch('GET', $base, '\\' . JsonApiController::class . '@index');
}
|
@param $resourceType
@dataProvider multiWordProvider
@see https://github.com/cloudcreativity/laravel-json-api/issues/224
|
testMultiWordResourceType
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testAsync(string $method, string $url, string $action): void
{
$this->withRoutes(function (RouteRegistrar $api) {
$api->resource('photos', [
'async' => true,
]);
}, ['id' => '^\d+$']);
$this->assertMatch($method, $url, '\\' . JsonApiController::class . $action);
}
|
@param string $method
@param string $url
@param string $action
@dataProvider processProvider
|
testAsync
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testFluentAsync(string $method, string $url, string $action): void
{
$this->withFluentRoutes()->defaultId('^\d+$')->routes(function (RouteRegistrar $api) {
$api->resource('photos')->async();
});
$this->assertMatch($method, $url, '\\' . JsonApiController::class . $action);
}
|
@param string $method
@param string $url
@param string $action
@dataProvider processProvider
|
testFluentAsync
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testAsyncDefaultConstraint(): void
{
$this->withRoutes(function (RouteRegistrar $api) {
$api->resource('photos', [
'async' => true,
]);
});
$this->assertNotFound('GET', '/api/v1/photos/queue-jobs/123456');
}
|
Test that the default async job id constraint is a UUID.
|
testAsyncDefaultConstraint
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testAsyncCustomConstraint(): void
{
$this->withRoutes(function (RouteRegistrar $api) {
$api->resource('photos', [
'async' => true,
'async_id' => '^\d+$',
]);
});
$this->assertMatch('GET', '/api/v1/photos/queue-jobs/123456');
}
|
Test that the default async job id constraint is a UUID.
|
testAsyncCustomConstraint
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function testFluentAsyncCustomConstraint(): void
{
$this->withRoutes(function (RouteRegistrar $api) {
$api->resource('photos')->async('^\d+$');
});
$this->assertMatch('GET', '/api/v1/photos/queue-jobs/123456');
}
|
Test that the default async job id constraint is a UUID.
|
testFluentAsyncCustomConstraint
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
private function assertRoute($method, $url, $expected = 200)
{
if (405 === $expected) {
$this->assertMethodNotAllowed($method, $url);
} elseif (404 === $expected) {
$this->assertNotFound($method, $url);
} else {
$this->assertMatch($method, $url);
}
}
|
@param $method
@param $url
@param int $expected
|
assertRoute
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
private function assertMatch($method, $url, $expected = null)
{
$request = $this->createRequest($method, $url);
$route = null;
try {
$route = Route::getRoutes()->match($request);
$matched = true;
} catch (NotFoundHttpException $e) {
$matched = false;
} catch (MethodNotAllowedHttpException $e) {
$matched = false;
}
$this->assertTrue($matched, "Route $method $url did not match.");
if ($expected) {
$this->assertSame($expected, $route->action['controller']);
}
return $route;
}
|
@param $method
@param $url
@param $expected
@return \Illuminate\Routing\Route
|
assertMatch
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
private function createRequest($method, $url)
{
return Request::create($url, $method);
}
|
@param $method
@param $url
@return Request
|
createRequest
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Routing/Test.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Routing/Test.php
|
Apache-2.0
|
public function test(array $attributes, array $rules, array $expected): void
{
$data = [
'type' => 'posts',
'attributes' => $attributes,
];
$this->validator->method('rules')->willReturn($rules);
$response = $this
->jsonApi('posts')
->withData($data)
->post('/api/v1/posts');
$response
->assertExactErrorStatus($expected);
}
|
@param array $attributes
@param array $rules
@param array $expected
@dataProvider rulesProvider
|
test
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Validation/FailedMetaTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Validation/FailedMetaTest.php
|
Apache-2.0
|
public function testUnique(): void
{
$post = factory(Post::class)->create();
$data = [
'type' => 'posts',
'attributes' => [
'value' => $post->slug,
],
];
$expected = [
'status' => '422',
'title' => 'Unprocessable Entity',
'detail' => 'The value has already been taken.',
'meta' => [
'failed' => [
'rule' => 'unique',
// no options as they reveal database settings.
],
],
'source' => [
'pointer' => '/data/attributes/value',
],
];
$this->validator->method('rules')->willReturn([
'value' => Rule::unique('posts', 'slug'),
]);
$response = $this
->jsonApi('posts')
->withData($data)
->post('/api/v1/posts');
$response
->assertExactErrorStatus($expected);
}
|
The unique rule is tested separately as we need to set up the database first.
As with other database rules, we expect the options to not be included in the
meta as they reveal database information.
|
testUnique
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Validation/FailedMetaTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Validation/FailedMetaTest.php
|
Apache-2.0
|
public function testSearch(array $params, string $param, string $detail)
{
$expected = [
'title' => 'Invalid Query Parameter',
'status' => '400',
'detail' => $detail,
'source' => ['parameter' => $param],
];
$response = $this
->jsonApi('posts')
->query($params)
->get('/api/v1/posts');
$response->assertExactErrorStatus($expected);
}
|
@param array $params
@param string $param
@param string $detail
@dataProvider searchProvider
|
testSearch
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Validation/QueryValidationTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Validation/QueryValidationTest.php
|
Apache-2.0
|
public function testSearchRelated(array $params, string $param, string $detail)
{
$country = factory(Country::class)->create();
$expected = [
'detail' => $detail,
'source' => ['parameter' => $param],
'status' => '400',
];
$response = $this
->jsonApi('countries')
->query($params)
->get(url('/api/v1/countries', [$country, 'posts']));
$response->assertErrorStatus($expected);
}
|
@param array $params
@param string $param
@param string $detail
@dataProvider searchProvider
|
testSearchRelated
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Validation/QueryValidationTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Validation/QueryValidationTest.php
|
Apache-2.0
|
public function testToOne($data, array $error)
{
$post = factory(Post::class)->create();
$this->doInvalidRequest("/api/v1/posts/{$post->getKey()}/relationships/author", $data, 'PATCH')
->assertStatus((int) $error['status'])
->assertExactJson(['errors' => [$error]]);
}
|
@param $data
@param array $error
@dataProvider toOneProvider
|
testToOne
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Validation/Spec/RelationshipValidationTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Validation/Spec/RelationshipValidationTest.php
|
Apache-2.0
|
public function testToMany($data, array $error)
{
$post = factory(Post::class)->create();
$this->doInvalidRequest("/api/v1/posts/{$post->getKey()}/relationships/tags", $data, 'PATCH')
->assertStatus((int) $error['status'])
->assertExactJson(['errors' => [$error]]);
}
|
@param $data
@param array $error
@dataProvider toManyProvider
|
testToMany
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Validation/Spec/RelationshipValidationTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Validation/Spec/RelationshipValidationTest.php
|
Apache-2.0
|
public function testPost($data, array $error)
{
$this->doInvalidRequest('/api/v1/posts', $data)
->assertErrorStatus($error);
}
|
@param $data
@param array $error
@dataProvider postProvider
|
testPost
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Validation/Spec/ResourceValidationTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Validation/Spec/ResourceValidationTest.php
|
Apache-2.0
|
public function testPatch($data, array $error)
{
$post = factory(Post::class)->create();
if (1 != $post->getKey()) {
$this->fail('Test scenario expects id to be 1.');
}
$this->doInvalidRequest("/api/v1/posts/{$post->getKey()}", $data, 'PATCH')
->assertErrorStatus($error);
}
|
@param $data
@param array $error
@dataProvider patchProvider
|
testPatch
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Validation/Spec/ResourceValidationTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Validation/Spec/ResourceValidationTest.php
|
Apache-2.0
|
public function testRejectsUnrecognisedTypeInResourceRelationship()
{
$this->resourceType = 'comments';
$comment = factory(Comment::class)->states('post')->make();
$data = [
'type' => 'comments',
'attributes' => [
'content' => $comment->content,
],
'relationships' => [
'commentable' => [
'data' => [
'type' => 'post', // invalid type as expecting the plural,
'id' => (string) $comment->commentable_id,
],
],
],
];
$response = $this
->actingAsUser()
->jsonApi()
->withData($data)
->post('/api/v1/comments');
$response->assertStatus(400)->assertJson([
'errors' => [
[
'detail' => "Resource type post is not recognised.",
'status' => '400',
'source' => [
'pointer' => '/data/relationships/commentable/data/type',
],
]
],
]);
}
|
The client must receive a 400 error with a correct JSON API pointer if an invalid
resource type is sent for a resource relationship.
@see https://github.com/cloudcreativity/laravel-json-api/issues/139
|
testRejectsUnrecognisedTypeInResourceRelationship
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Validation/Spec/ResourceValidationTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Validation/Spec/ResourceValidationTest.php
|
Apache-2.0
|
protected function doInvalidRequest($uri, $content, $method = 'POST'): TestResponse
{
if (!is_string($content)) {
$content = json_encode($content);
}
$headers = $this->transformHeadersToServerVars([
'CONTENT_LENGTH' => mb_strlen($content, '8bit'),
'CONTENT_TYPE' => 'application/vnd.api+json',
'Accept' => 'application/vnd.api+json',
]);
return TestResponse::cast(
$this->call($method, $uri, [], [], [], $headers, $content)
);
}
|
@param $uri
@param $content
@param $method
@return TestResponse
|
doInvalidRequest
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Integration/Validation/Spec/TestCase.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Integration/Validation/Spec/TestCase.php
|
Apache-2.0
|
public function testAdapterForInvalidResourceType()
{
$this->illuminateContainer->expects($this->never())->method('make');
$this->assertNull($this->container->getAdapterByResourceType('comments'));
}
|
If a resource type is not valid, we expect `null` to be returned for the adapter.
This is so that we can detect an unknown resource type as we expect all known
resource types to have adapters.
|
testAdapterForInvalidResourceType
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/ContainerTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/ContainerTest.php
|
Apache-2.0
|
public function testInvalidJson($content, $jsonError = false)
{
$actual = null;
try {
json_decode($content);
} catch (InvalidJsonException $ex) {
$actual = $ex;
}
$this->assertNotNull($actual);
if ($jsonError) {
$this->assertJsonError($ex);
}
}
|
@param $content
@param bool $jsonError
@dataProvider invalidJsonProvider
|
testInvalidJson
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/HelpersTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/HelpersTest.php
|
Apache-2.0
|
public function testRequestContainsBody(array $headers, $expected)
{
$request = new Request('GET', '/api/posts', $headers);
$this->assertSame($expected, http_contains_body($request));
}
|
@param array $headers
@param $expected
@dataProvider requestContainsBodyProvider
|
testRequestContainsBody
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/HelpersTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/HelpersTest.php
|
Apache-2.0
|
public function testIlluminateRequestContainsBody(array $headers, $expected)
{
$request = IlluminateRequest::create('/api/posts', 'GET');
foreach ($headers as $header => $value) {
$request->headers->set($header, $value);
}
$this->assertSame($expected, http_contains_body($request));
}
|
@param array $headers
@param $expected
@dataProvider requestContainsBodyProvider
|
testIlluminateRequestContainsBody
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/HelpersTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/HelpersTest.php
|
Apache-2.0
|
public function testSymfonyRequestContainsBody(array $headers, $expected)
{
$request = SymfonyRequest::create('/api/posts', 'GET');
foreach ($headers as $header => $value) {
$request->headers->set($header, $value);
}
$this->assertSame($expected, http_contains_body($request));
}
|
@param array $headers
@param $expected
@dataProvider requestContainsBodyProvider
|
testSymfonyRequestContainsBody
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/HelpersTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/HelpersTest.php
|
Apache-2.0
|
public function testResponseContainsBody($expected, $method, $status, $headers = [], $body = null)
{
$request = new Request($method, '/api/posts');
$response = new Response($status, $headers, $body);
$this->assertSame($expected, http_contains_body($request, $response));
}
|
@param $expected
@param $method
@param $status
@param array $headers
@param $body
@dataProvider responseContainsBodyProvider
|
testResponseContainsBody
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/HelpersTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/HelpersTest.php
|
Apache-2.0
|
public function testIlluminateResponseContainsBody($expected, $method, $status, $headers = [], $body = null)
{
$request = IlluminateRequest::create('/api/posts', $method);
$response = new IlluminateResponse($body, $status, $headers);
$this->assertSame($expected, http_contains_body($request, $response));
}
|
@param $expected
@param $method
@param $status
@param array $headers
@param $body
@dataProvider responseContainsBodyProvider
|
testIlluminateResponseContainsBody
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/HelpersTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/HelpersTest.php
|
Apache-2.0
|
public function testSymfonyResponseContainsBody($expected, $method, $status, $headers = [], $body = null)
{
$request = SymfonyRequest::create('/api/posts', $method);
$response = new SymfonyResponse($body, $status, $headers);
$this->assertSame($expected, http_contains_body($request, $response));
}
|
@param $expected
@param $method
@param $status
@param array $headers
@param $body
@dataProvider responseContainsBodyProvider
|
testSymfonyResponseContainsBody
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/HelpersTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/HelpersTest.php
|
Apache-2.0
|
public function testWantsJsonApi($accept, $expected)
{
$request = new IlluminateRequest();
$request->headers->set('Accept', $accept);
$this->assertSame($expected, Helpers::wantsJsonApi($request));
}
|
@param $accept
@param $expected
@dataProvider mediaTypesProvider
|
testWantsJsonApi
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/HelpersTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/HelpersTest.php
|
Apache-2.0
|
public function testIsJsonApi($contentType, $expected)
{
$request = new IlluminateRequest();
$request->headers->set('Content-Type', $contentType);
$this->assertSame($expected, Helpers::isJsonApi($request));
}
|
@param $contentType
@param $expected
@dataProvider mediaTypesProvider
|
testIsJsonApi
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/HelpersTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/HelpersTest.php
|
Apache-2.0
|
public function testHttpErrorStatus(array $errors, int $expected): void
{
$errors = collect($errors)->map(function (?int $status) {
return new Error(null, null, null, $status);
})->all();
$this->assertSame(Helpers::httpErrorStatus($errors), $expected);
}
|
@param array $errors
@param int $expected
@dataProvider httpErrorProvider
|
testHttpErrorStatus
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/HelpersTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/HelpersTest.php
|
Apache-2.0
|
public function testDuplicateFields(): void
{
$this->values['attributes']['author'] = null;
$resource = ResourceObject::create($this->values);
$this->assertSame($this->values['relationships']['author']['data'], $resource['author']);
}
|
Fields share a common namespace, so if there is a duplicate field
name in the attributes and relationships, there is a collision.
We expect the relationship to be returned.
|
testDuplicateFields
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Document/ResourceObjectTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Document/ResourceObjectTest.php
|
Apache-2.0
|
public function testPointer(string $key, string $expected): void
{
$this->assertSame($expected, $this->resource->pointer($key));
$this->assertSame($expected, $this->resource->pointer($key, '/'), 'with slash prefix');
}
|
@param string $key
@param string $expected
@dataProvider pointerProvider
|
testPointer
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Document/ResourceObjectTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Document/ResourceObjectTest.php
|
Apache-2.0
|
public function testPointerWithPrefix(string $key, string $expected): void
{
// @see https://github.com/cloudcreativity/laravel-json-api/issues/255
$expected = rtrim("/data" . $expected, '/');
$this->assertSame($expected, $this->resource->pointer($key, '/data'));
}
|
@param string $key
@param string $expected
@dataProvider pointerProvider
|
testPointerWithPrefix
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Document/ResourceObjectTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Document/ResourceObjectTest.php
|
Apache-2.0
|
public function testPointerForRelationship(string $key, ?string $expected): void
{
if (!is_null($expected)) {
$this->assertSame($expected, $this->resource->pointerForRelationship($key, '/foo/bar'));
return;
}
$this->assertSame('/', $this->resource->pointerForRelationship($key));
$this->assertSame('/data', $this->resource->pointerForRelationship($key, '/data'));
}
|
@param string $key
@param string|null $expected
@return void
@dataProvider pointerForRelationshipProvider
|
testPointerForRelationship
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Document/ResourceObjectTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Document/ResourceObjectTest.php
|
Apache-2.0
|
public function testIterable(\Closure $scenario): void
{
$object1 = $this->createMock(Post::class);
$object2 = $this->createMock(Post::class);
$object3 = $this->createMock(Post::class);
$data = $scenario($object1, $object2, $object3);
$includePaths = $this->withIncludePaths($object1);
$actual = $this->analyser->getRootObject($data);
$this->assertSame($object1, $actual);
$this->assertSame($includePaths, $this->analyser->getIncludePaths($data));
if (!is_array($data)) {
// the iterator needs to work when iterated over again.
$this->assertSame([$object1, $object2, $object3], iterator_to_array($data));
}
}
|
@param \Closure $scenario
@return void
@dataProvider iteratorProvider
|
testIterable
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Encoder/DataAnalyserTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Encoder/DataAnalyserTest.php
|
Apache-2.0
|
public function testEmptyIterable(\Closure $scenario): void
{
$data = $scenario();
$this->container
->method('hasSchema')
->with($this->identicalTo($data))
->willReturn(false);
$this->container
->expects($this->never())
->method('getSchema');
$actual = $this->analyser->getRootObject($data);
$this->assertNull($actual);
$this->assertEmpty($this->analyser->getIncludePaths($data));
if (!is_array($data)) {
// the iterator needs to work when iterated over again.
$this->assertEmpty(iterator_to_array($data));
}
}
|
@param \Closure $scenario
@return void
@dataProvider iteratorProvider
|
testEmptyIterable
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Encoder/DataAnalyserTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Encoder/DataAnalyserTest.php
|
Apache-2.0
|
public function testIssue221(): void
{
$type1 = new MediaType('multipart', 'form-data', ['boundary' => '*']);
$type2 = new MediaType('multipart', 'form-data', ['boundary' => '----WebKitFormBoundaryAAA']);
$this->assertFalse($type1->matchesTo($type2));
$this->assertTrue($type2->matchesTo($type1));
}
|
@return void
@see https://github.com/neomerx/json-api/issues/221
|
testIssue221
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Http/Headers/MediaTypeTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Http/Headers/MediaTypeTest.php
|
Apache-2.0
|
public function testByResource($resourceType, $type, $namespace)
{
$resolver = $this->createResolver(true);
$this->assertResourceNamespace($resolver, $resourceType, $type, $namespace);
}
|
@param $resourceType
@param $type
@param $namespace
@dataProvider byResourceProvider
|
testByResource
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Resolver/NamespaceResolverTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Resolver/NamespaceResolverTest.php
|
Apache-2.0
|
public function testNotByResource($resourceType, $type, $singular)
{
$resolver = $this->createResolver(false);
$this->assertUnitNamespace($resolver, $resourceType, $type, 'App\JsonApi', $singular);
}
|
@param $resourceType
@param $type
@param $singular
@dataProvider notByResourceProvider
|
testNotByResource
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Resolver/NamespaceResolverTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Resolver/NamespaceResolverTest.php
|
Apache-2.0
|
public function testNamedAuthorizer($name, $expected, $byResource)
{
$resolver = $this->createResolver($byResource);
$this->assertSame($expected, $resolver->getAuthorizerByName($name));
}
|
@param $name
@param $expected
@param $byResource
@dataProvider genericAuthorizerProvider
|
testNamedAuthorizer
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Resolver/NamespaceResolverTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Resolver/NamespaceResolverTest.php
|
Apache-2.0
|
private function createResolver($byResource = true, $withType = true)
{
return new NamespaceResolver('App\JsonApi', [
'posts' => 'App\Post',
'comments' => 'App\Comment',
], $byResource, $withType);
}
|
@param bool $byResource
@param bool $withType
@return NamespaceResolver
|
createResolver
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Resolver/NamespaceResolverTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Resolver/NamespaceResolverTest.php
|
Apache-2.0
|
private function assertResolver(
$resolver,
$resourceType,
$type,
$schema,
$adapter,
$validator,
$auth,
$contentNegotiator
) {
$exists = !is_null($type);
$this->assertSame($exists, $resolver->isType($type));
$this->assertSame($exists, $resolver->isResourceType($resourceType));
$this->assertSame($exists ? $type : null, $resolver->getType($resourceType));
$this->assertSame($exists ? $resourceType : null, $resolver->getResourceType($type));
$this->assertSame($exists ? $schema : null, $resolver->getSchemaByType($type));
$this->assertSame($schema, $resolver->getSchemaByResourceType($resourceType));
$this->assertSame($exists ? $adapter : null, $resolver->getAdapterByType($type));
$this->assertSame($adapter, $resolver->getAdapterByResourceType($resourceType));
$this->assertSame($exists ? $validator : null, $resolver->getValidatorsByType($type));
$this->assertSame($validator, $resolver->getValidatorsByResourceType($resourceType));
$this->assertSame($exists ? $auth : null, $resolver->getAuthorizerByType($type));
$this->assertSame($auth, $resolver->getAuthorizerByResourceType($resourceType));
$this->assertSame($contentNegotiator, $resolver->getContentNegotiatorByResourceType($resourceType));
}
|
@param ResolverInterface $resolver
@param $resourceType
@param $type
@param $schema
@param $adapter
@param $validator
@param $auth
@param $contentNegotiator
|
assertResolver
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Resolver/NamespaceResolverTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Resolver/NamespaceResolverTest.php
|
Apache-2.0
|
private function assertResourceNamespace($resolver, $resourceType, $type, $namespace)
{
$this->assertResolver(
$resolver,
$resourceType,
$type,
"{$namespace}\Schema",
"{$namespace}\Adapter",
"{$namespace}\Validators",
"{$namespace}\Authorizer",
"{$namespace}\ContentNegotiator"
);
}
|
@param $resolver
@param $resourceType
@param $type
@param $namespace
|
assertResourceNamespace
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Resolver/NamespaceResolverTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Resolver/NamespaceResolverTest.php
|
Apache-2.0
|
private function assertUnitNamespace($resolver, $resourceType, $type, $namespace, $singular)
{
$this->assertResolver(
$resolver,
$resourceType,
$type,
"{$namespace}\Schemas\\{$singular}Schema",
"{$namespace}\Adapters\\{$singular}Adapter",
"{$namespace}\Validators\\{$singular}Validator",
"{$namespace}\Authorizers\\{$singular}Authorizer",
"{$namespace}\ContentNegotiators\\{$singular}ContentNegotiator"
);
}
|
@param $resolver
@param $resourceType
@param $type
@param $namespace
@param $singular
|
assertUnitNamespace
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Resolver/NamespaceResolverTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Resolver/NamespaceResolverTest.php
|
Apache-2.0
|
public function testAlreadyParsedParameters(SchemaFields $expected): void
{
$paths = [
'a1',
'a2',
'a1.b1',
'a2.b2.c2',
];
$fieldSets = [
'articles' => ['title', 'body', 'a1'],
'people' => ['name'],
];
$actual = new SchemaFields($paths, $fieldSets);
$this->assertEquals($expected, $actual);
}
|
@param SchemaFields $expected
@return void
@depends test
|
testAlreadyParsedParameters
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Schema/SchemaFieldsTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Schema/SchemaFieldsTest.php
|
Apache-2.0
|
public function testQuery()
{
$params = new QueryParameters();
$expected = new \DateTime();
$store = $this->store([
'posts' => $this->willNotQuery(),
'users' => $this->willQuery($params, $expected),
]);
$this->assertSame($expected, $store->queryRecords('users', $params));
}
|
A query request must be handed off to the adapter for the resource type
specified.
|
testQuery
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
public function testCannotQuery()
{
$store = $this->store(['posts' => $this->willNotQuery()]);
$this->expectException(RuntimeException::class);
$store->queryRecords('users', new QueryParameters());
}
|
If there is no adapter for the resource type, an exception must be thrown.
|
testCannotQuery
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
public function testReadRecord()
{
$params = new QueryParameters();
$expected = new \stdClass();
$store = $this->storeByTypes([
\DateTime::class => $this->willNotQuery(),
\stdClass::class => $this->willReadRecord($expected, $params),
]);
$this->assertSame($expected, $store->readRecord($expected, $params));
}
|
A query record request must be handed off to the adapter for the resource type
specified in the identifier.
|
testReadRecord
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
public function testQueryRelated()
{
$parameters = new QueryParameters();
$record = new \DateTime();
$expected = new \DateInterval('P1W');
$store = $this->storeByTypes([
\DateTimeZone::class => $this->willNotQuery(),
\DateTime::class => $this->willQueryRelated($record, 'user', $parameters, $expected),
]);
$this->assertSame($expected, $store->queryRelated($record, 'user', $parameters));
}
|
A query related request must be handed off to the relationship adapter provided by the
resource adapter.
|
testQueryRelated
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
public function testQueryRelationship()
{
$parameters = new QueryParameters();
$record = new \DateTime();
$expected = new \DateInterval('P1W');
$store = $this->storeByTypes([
\DateTimeZone::class => $this->willNotQuery(),
\DateTime::class => $this->willQueryRelationship($record, 'user', $parameters, $expected),
]);
$this->assertSame($expected, $store->queryRelationship($record, 'user', $parameters));
}
|
A query relationship request must be handed off to the relationship adapter provided by
the resource adapter.
|
testQueryRelationship
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
public function testExistsCalledOnce()
{
$store = $this->store([
'posts' => $this->adapter(),
'users' => $this->willExist('99', true, $this->once())
]);
$this->assertTrue($store->exists('users', '99'));
$this->assertTrue($store->exists('users', '99'));
}
|
If exists is called multiple times, we expect the adapter to only be queried once.
|
testExistsCalledOnce
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
public function testFindCalledOnce()
{
$expected = new \DateTime();
$store = $this->store([
'posts' => $this->adapter(),
'users' => $this->willFind('99', $expected, $this->once()),
]);
$this->assertSame($expected, $store->find('users', '99'));
$this->assertSame($expected, $store->find('users', '99'));
}
|
If find is called multiple times, we expected the adapter to only be queried once.
|
testFindCalledOnce
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
public function testFindBeforeExists()
{
$expected = new \DateTime();
$mock = $this->adapter();
$mock->expects($this->never())->method('exists');
$mock->method('find')->with('99')->willReturn($expected);
$store = $this->store(['users' => $mock]);
$this->assertSame($expected, $store->find('users', '99'));
$this->assertTrue($store->exists('users', '99'));
}
|
If find returns the objects, then exists is called, the adapter does not need to be queried
because the store already knows that it exists.
|
testFindBeforeExists
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
public function testFindNoneBeforeExists()
{
$mock = $this->adapter();
$mock->expects($this->never())->method('exists');
$store = $this->store(['users' => $mock]);
$this->assertNull($store->find('users', '99'));
$this->assertFalse($store->exists('users', '99'));
}
|
If find does not return the object, then exists is called, the adapter does not need to be
queried because the store already knows that it does not exist.
|
testFindNoneBeforeExists
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
public function testDoesNotExistBeforeFind()
{
$mock = $this->adapter();
$mock->expects($this->once())->method('exists')->with('99')->willReturn(false);
$mock->expects($this->never())->method('find');
$store = $this->store(['users' => $mock]);
$this->assertFalse($store->exists('users', '99'));
$this->assertNull($store->find('users', '99'));
}
|
If exists returns false and then find is called, null should be returned without the adapter
being queried because the store already knows it does not exist.
|
testDoesNotExistBeforeFind
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
public function testFindManyReturnsEmpty()
{
$identifiers = [
['type' => 'posts', 'id' => '1'],
['type' => 'users', 'id' => '99'],
['type' => 'posts', 'id' => '3'],
];
$store = $this->store([
'posts' => $this->willFindMany(['1', '3']),
'users' => $this->willFindMany(['99']),
'tags' => $this->willNotFindMany(),
]);
$this->assertSame([], $store->findMany($identifiers));
}
|
A find many request hands the ids off to the adapter of each resource type,
and returns an empty array if no records are found.
|
testFindManyReturnsEmpty
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
public function testFindMany()
{
$post = (object) ['foo' => 'bar'];
$user = (object) ['baz' => 'bat'];
$identifiers = [
['type' => 'posts', 'id' => '1'],
['type' => 'posts', 'id' => '3'],
['type' => 'users', 'id' => '99'],
];
$store = $this->store([
'posts' => $this->willFindMany(['1', '3'], [$post]),
'users' => $this->willFindMany(['99'], [$user]),
'tags' => $this->willNotFindMany(),
]);
$this->assertSame([$post, $user], $store->findMany($identifiers));
}
|
A find many request hands the ids off to the adapter of each resource type,
and returns an array containing all found records.
|
testFindMany
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
public function testFindManyWithIdentifiers()
{
$post = (object) ['type' => 'posts', 'id' => '1'];
$user = (object) ['type' => 'users', 'id' => '99'];
$identifiers = [
['type' => 'posts', 'id' => '1'],
['type' => 'posts', 'id' => '3'],
['type' => 'users', 'id' => '99'],
];
$store = $this->store([
'posts' => $this->willFindMany(['1', '3'], [$post]),
'users' => $this->willFindMany(['99'], [$user]),
'tags' => $this->willNotFindMany(),
]);
$this->assertSame([$post, $user], $store->findMany($identifiers));
}
|
A find many request hands the ids off to the adapter of each resource type,
and returns an array containing all found records.
|
testFindManyWithIdentifiers
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
public function testCannotFindMany()
{
$identifiers = [
['type' => 'posts', 'id' => '1'],
['type' => 'posts', 'id' => '3'],
['type' => 'users', 'id' => '99'],
];
$store = $this->store([
'posts' => $this->willFindMany(['1', '3']),
]);
$this->expectException(RuntimeException::class);
$store->findMany($identifiers);
}
|
An exception is thrown if a resource type in the find many identifiers
is not recognised.
|
testCannotFindMany
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
private function willExist($resourceId, $exists = true, $expectation = null)
{
$expectation = $expectation ?: $this->any();
$mock = $this->adapter();
$mock->expects($expectation)
->method('exists')
->with($resourceId)
->willReturn($exists);
return $mock;
}
|
@param string $resourceId
@param bool $exists
@param $expectation
@return MockObject
|
willExist
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
private function willNotExist($resourceId, $expectation = null)
{
return $this->willExist($resourceId, false, $expectation);
}
|
@param $resourceId
@param $expectation
@return MockObject
|
willNotExist
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
private function willFind($resourceId, $record, $expectation = null)
{
$mock = $this->adapter();
$mock->expects($expectation ?: $this->any())
->method('find')
->with($resourceId)
->willReturn($record);
return $mock;
}
|
@param $resourceId
@param $record
@param $expectation
@return MockObject
|
willFind
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
private function willNotFind($resourceId, $expectation = null)
{
return $this->willFind($resourceId, null, $expectation);
}
|
@param $resourceId
@param $expectation
@return MockObject
|
willNotFind
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
private function willFindMany(array $resourceIds, array $results = [])
{
$mock = $this->adapter();
$mock->expects($this->atLeastOnce())
->method('findMany')
->with(collect($resourceIds))
->willReturn($results);
return $mock;
}
|
@param array $resourceIds
@param array $results
@return MockObject
|
willFindMany
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
private function willQuery($params, $results, $expectation = null)
{
$mock = $this->adapter();
$mock->expects($expectation ?: $this->any())
->method('query')
->with($params)
->willReturn($results);
return $mock;
}
|
@param $params
@param $results
@param null $expectation
@return MockObject
|
willQuery
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
private function willCreateRecord($document, $params, $expected)
{
$mock = $this->adapter();
$mock->expects($this->once())
->method('create')
->with($document, $params)
->willReturn($expected);
return $mock;
}
|
@param $document
@param $params
@param $expected
@return MockObject
|
willCreateRecord
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
private function willReadRecord($record, $params)
{
$mock = $this->adapter();
$mock->expects($this->atLeastOnce())
->method('read')
->with($record, $params)
->willReturn($record);
return $mock;
}
|
@param $record
@param $params
@return MockObject
|
willReadRecord
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
private function willUpdateRecord($record, $resourceObject, $params, $expected)
{
$mock = $this->adapter();
$mock->expects($this->once())
->method('update')
->with($record, $resourceObject, $params)
->willReturn($expected);
return $mock;
}
|
@param $record
@param $resourceObject
@param $params
@param $expected
@return MockObject
|
willUpdateRecord
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
private function willDeleteRecord($record, $params, $result = true)
{
$mock = $this->adapter();
$mock->expects($this->once())
->method('delete')
->with($record, $params)
->willReturn($result);
return $mock;
}
|
@param $record
@param $params
@param bool $result
@return MockObject
|
willDeleteRecord
|
php
|
cloudcreativity/laravel-json-api
|
tests/lib/Unit/Store/StoreTest.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/tests/lib/Unit/Store/StoreTest.php
|
Apache-2.0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.