PHP Class Flugg\Responder\Tests\Unit\SuccessResponseBuilderTest

Author: Alexander Tømmerås ([email protected])
Inheritance: extends Flugg\Responder\Tests\TestCase
Datei anzeigen Open project: flugger/laravel-responder

Public Methods

Method Description
addMetaMethodShouldAddMetaDataToResource ( ) Test that the [addMeta] method adds the meta data to the resource instance.
addMetaMethodShouldMergeMetaDataWithExisting ( ) Test that the [addMeta] method merges new meta data with existing meta data set on the resource.
addMetaMethodShouldReturnItself ( ) Test that the [addMeta] method returns the response builder, allowing for fluent method chaining.
itShouldCreateANullResourceByDefault ( ) Test that a new instance of [\League\Fractal\Resource\NullResource] is created when the response builder is instantiated.
itShouldUsePackageSerializerByDefault ( ) Test that a serializer is set to [\Flugg\Responder\Serializers\ApiSerializer] when you leave the configuration to the defaults.
respondMethodShouldAllowSettingHeaders ( ) Test that you can set any headers to the JSON response by passing a second argument to the [respond] method.
respondMethodShouldAllowSettingStatusCode ( ) Test that the [respond] method allows passing a status code as the first parameter.
respondMethodShouldReturnAJsonResponse ( ) Test that the [respond] method converts the success response into an instance of [\Illuminate\Http\JsonResponse] with a default status code of 200.
serializerMethodShouldFailIfSerializerIsInvalid ( ) Test that the [serializer] method throws an [\InvalidArgumentException] when the given serializer is not a valid value.
serializerMethodShouldResolveSerializerFromClassName ( ) Test that the [serializer] method allows for setting serializer using a string.
serializerMethodShouldReturnItself ( ) Test that the [serializer] method returns the response builder, allowing for fluent method chaining.
serializerMethodShouldSetSerializerOnTheManager ( ) Test that the [serializer] method sets the serializer given on the Fractal manager.
setStatusMethodShouldFailIfStatusCodeIsInvalid ( ) Test that the [setStatus] method throws an [\InvalidArgumentException] when the status code given is not a valid successful HTTP status code.
setStatusMethodShouldReturnItself ( ) Test that the [setStatus] method returns the response builder, allowing for fluent method chaining.
setStatusMethodShouldSetStatusCode ( ) Test that the [setStatus] method sets the HTTP status code on the response, providing an alternative, more explicit way of setting the status code.
toArrayMethodShouldSerializeData ( ) Test that the [toArray] method serializes the data given, using the default serializer and no data.
toArrayMethodShouldTransformData ( ) Test that the [toArray] method also transforms the data using the set transformer.
toCollectionMethodShouldReturnACollection ( ) Test that the [toCollection] serializes the data into a collection.
toJsonMethodShouldReturnJson ( ) Test that the [toJson] serializes the data into a JSON string.
transformMethodShouldAllowSettingAResourceKey ( ) Test that a resource key can be set explicitly on the response by passing a third argument to the [transform] method.
transformMethodShouldAllowSettingATransformer ( ) Test that a transformer can be set explicitly on the response by passing a second argument to the [transform] method.
transformMethodShouldAllowSettingATransformerUsingClassName ( ) Test that you can use a class name string to set the transformer on the [transform] method.
transformMethodShouldAllowSettingATransformerUsingClosure ( ) Test that you can also use an anonymous function as a transformer instead of a full blown transformer class when using the [transform] method.
transformMethodShouldCreateClosureIfNoTransformerIsFound ( ) Test that the [transform] method creates a closure transformer substitute from the model's fillable array.
transformMethodShouldFailIfNoModelIsFound ( ) Test that the [transform] method throws an [\InvalidArgumentException] when the given data doesn't contain, or is itself, an Eloquent model.
transformMethodShouldGetResourceKeyFromModelMethod ( ) Test that you can set a resource key directly on your models by taking use of the [getResourceKey] method.
transformMethodShouldMergeRelationsWithExisting ( ) Test that the [transform] method merges the eager loaded relations with relations set directly on the transformer.
transformMethodShouldResolveResourceFromData ( ) Test that the Fractal resource instance on the response is updated when calling the [transform] method using the resource factory.
transformMethodShouldResolveResourceKeyFromTableNameByDefault ( ) Test that the [transform] method resolves resource key from the model's table name if not set explicitly.
transformMethodShouldResolveTransformerFromModel ( ) Test that the [transform] method resolves a transformer from the model resolved from the given data.
transformMethodShouldResolveTransformerUsingClassName ( ) Test that the [transform] method can resolve a transformer from the model, when the [transformer] method returns a class name string.
transformMethodShouldReturnItself ( ) Test that the [transform] method returns the response builder, allowing for fluent method chaining.
transformMethodShouldSetRelations ( ) Test that the [transform] method sets the eager loaded relations from the model on the transformer and manager.
transformMethodShouldSetResourceToNullResourceWhenGivenNoData ( ) Test that the resource instance is set to [\League\Fractal\Resource\NullResource] when given no data to the [transform] method.
youCanChangeSerializerInTheConfig ( ) Test that you can change serializer by changing the [serializer] key in the package configuration file.
youCanGetTheManagerInstance ( ) Test that you can get an instance of [\League\Fractal\Manager] from the response builder.
youCanGetTheResourceInstance ( ) Test that you can get an instance of [\League\Fractal\Resource\ResourceAbstract] from the response builder.
youCanResolveAManagerFromTheContainer ( ) Test that you can resolve an instance of [\League\Fractal\Manager] from the service container.
youCanResolveASuccessResponseBuilderFromTheContainer ( ) Test that you can resolve an instance of [\Flugg\Responder\SuccessResponseBuilder] from the service container.

Method Details

addMetaMethodShouldAddMetaDataToResource() public method

Test that the [addMeta] method adds the meta data to the resource instance.

addMetaMethodShouldMergeMetaDataWithExisting() public method

Test that the [addMeta] method merges new meta data with existing meta data set on the resource.

addMetaMethodShouldReturnItself() public method

Test that the [addMeta] method returns the response builder, allowing for fluent method chaining.

itShouldCreateANullResourceByDefault() public method

Test that a new instance of [\League\Fractal\Resource\NullResource] is created when the response builder is instantiated.

itShouldUsePackageSerializerByDefault() public method

Test that a serializer is set to [\Flugg\Responder\Serializers\ApiSerializer] when you leave the configuration to the defaults.

respondMethodShouldAllowSettingHeaders() public method

Test that you can set any headers to the JSON response by passing a second argument to the [respond] method.

respondMethodShouldAllowSettingStatusCode() public method

Test that the [respond] method allows passing a status code as the first parameter.

respondMethodShouldReturnAJsonResponse() public method

Test that the [respond] method converts the success response into an instance of [\Illuminate\Http\JsonResponse] with a default status code of 200.

serializerMethodShouldFailIfSerializerIsInvalid() public method

Test that the [serializer] method throws an [\InvalidArgumentException] when the given serializer is not a valid value.

serializerMethodShouldResolveSerializerFromClassName() public method

Test that the [serializer] method allows for setting serializer using a string.

serializerMethodShouldReturnItself() public method

Test that the [serializer] method returns the response builder, allowing for fluent method chaining.

serializerMethodShouldSetSerializerOnTheManager() public method

Test that the [serializer] method sets the serializer given on the Fractal manager.

setStatusMethodShouldFailIfStatusCodeIsInvalid() public method

Test that the [setStatus] method throws an [\InvalidArgumentException] when the status code given is not a valid successful HTTP status code.

setStatusMethodShouldReturnItself() public method

Test that the [setStatus] method returns the response builder, allowing for fluent method chaining.

setStatusMethodShouldSetStatusCode() public method

Test that the [setStatus] method sets the HTTP status code on the response, providing an alternative, more explicit way of setting the status code.

toArrayMethodShouldSerializeData() public method

Test that the [toArray] method serializes the data given, using the default serializer and no data.

toArrayMethodShouldTransformData() public method

Test that the [toArray] method also transforms the data using the set transformer.

toCollectionMethodShouldReturnACollection() public method

Test that the [toCollection] serializes the data into a collection.

toJsonMethodShouldReturnJson() public method

Test that the [toJson] serializes the data into a JSON string.

transformMethodShouldAllowSettingAResourceKey() public method

Test that a resource key can be set explicitly on the response by passing a third argument to the [transform] method.

transformMethodShouldAllowSettingATransformer() public method

Test that a transformer can be set explicitly on the response by passing a second argument to the [transform] method.

transformMethodShouldAllowSettingATransformerUsingClassName() public method

Test that you can use a class name string to set the transformer on the [transform] method.

transformMethodShouldAllowSettingATransformerUsingClosure() public method

Test that you can also use an anonymous function as a transformer instead of a full blown transformer class when using the [transform] method.

transformMethodShouldCreateClosureIfNoTransformerIsFound() public method

Test that the [transform] method creates a closure transformer substitute from the model's fillable array.

transformMethodShouldFailIfNoModelIsFound() public method

Test that the [transform] method throws an [\InvalidArgumentException] when the given data doesn't contain, or is itself, an Eloquent model.

transformMethodShouldGetResourceKeyFromModelMethod() public method

Test that you can set a resource key directly on your models by taking use of the [getResourceKey] method.

transformMethodShouldMergeRelationsWithExisting() public method

Test that the [transform] method merges the eager loaded relations with relations set directly on the transformer.

transformMethodShouldResolveResourceFromData() public method

Test that the Fractal resource instance on the response is updated when calling the [transform] method using the resource factory.

transformMethodShouldResolveResourceKeyFromTableNameByDefault() public method

Test that the [transform] method resolves resource key from the model's table name if not set explicitly.

transformMethodShouldResolveTransformerFromModel() public method

Test that the [transform] method resolves a transformer from the model resolved from the given data.

transformMethodShouldResolveTransformerUsingClassName() public method

Test that the [transform] method can resolve a transformer from the model, when the [transformer] method returns a class name string.

transformMethodShouldReturnItself() public method

Test that the [transform] method returns the response builder, allowing for fluent method chaining.

transformMethodShouldSetRelations() public method

Test that the [transform] method sets the eager loaded relations from the model on the transformer and manager.

transformMethodShouldSetResourceToNullResourceWhenGivenNoData() public method

Test that the resource instance is set to [\League\Fractal\Resource\NullResource] when given no data to the [transform] method.

youCanChangeSerializerInTheConfig() public method

Test that you can change serializer by changing the [serializer] key in the package configuration file.

youCanGetTheManagerInstance() public method

Test that you can get an instance of [\League\Fractal\Manager] from the response builder.

youCanGetTheResourceInstance() public method

Test that you can get an instance of [\League\Fractal\Resource\ResourceAbstract] from the response builder.

youCanResolveAManagerFromTheContainer() public method

Test that you can resolve an instance of [\League\Fractal\Manager] from the service container.

youCanResolveASuccessResponseBuilderFromTheContainer() public method

Test that you can resolve an instance of [\Flugg\Responder\SuccessResponseBuilder] from the service container.