Download the PHP package newman/laravel-graphql-test-utils without Composer

On this page you can find all versions of the php package newman/laravel-graphql-test-utils. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-graphql-test-utils

Laravel GraphQL testing utility

This package helps you to test your GraphQL queries & mutations in your TestCases. It works with any laravel GraphQL server.

Requirements

Installation

Require the package via Composer:

:book: Documentation & Usage

To start using it, import our trait in your TestCase

Now you can explore our available builder methods.

Default assertions

By default, we don't assert anything for you after response is retrieved, but we expose function to register your handler to customize this behaviour.

Builder methods

setQuery

Set your GraphQL query.

setVariables

Set multiple GraphQL variables as key-value pair.

Note: Calling setVariables, will replace all previously set variables. You may want to use mergeVariables in that case instead.

setVariable

Set variables one-by-one.

You can also mix it with setVariables and mergeVariables.

Note: Calling setVariable with the same key will override previous value.

mergeVariables

Instead of resetting all variables like setVariables does, this method merges previously set variables with a pair of new variables.

schema

Specifies which GraphQL schema (name) to use.

Note: Depending on the driver used, it may automatically resolve HTTP method to use based on schema. More.

httpMethod

Forces specific HTTP method to use. By default, it will resolve from schema (if driver provides that), otherwise POST will be used.

driver

Optionally you can switch this query to other driver than default. Probably you won't need this.

withToken

Adds an Bearer Authorization token to request.

withoutToken

Remove the authorization token from the request.

withHeader

Add single header to request.

withHeader

Add multiple headers to request.

modifyRequest

Since in base we use Laravel`s MakesHttpRequests Trait, you can access those functions as well.

withDefaultAssertions and withoutDefaultAssertions

You may want to disable or re-enable default assertions individually.

Disable default assertions for this query:

call

Makes the call to GraphQL and returns our TestResponse class. Function has 2 arguments

Note: Variables passed to this function will merge with existing ones.

Response

We extend default Laravel`s Illuminate\Testing\TestResponse with a few GraphQL related functions/assertions.

assertNoGraphQLErrors

Asserts no GraphQL errors were returned.

assertGraphQLUnauthorized

Asserts there is an Unauthorized error in corresponding GraphQL error format.

getQuery

Access used query in the request.

getVariables

Access used variables in the request.

getGraphQLErrors

Returns array of GraphQL errors or null when not present.

hasGraphQLErrors

Determines if there are any GraphQL errors.

getGraphQLValidationMessages

Get list of Laravel validation messages or empty array when none.

getValidationFieldMessages

Get Laravel validation messages on specific field or empty array when none or field is not present.

getValidationFieldFirstMessage

Get first Laravel validation message on specific field or null when none or field is not present.

:information_source: Remember you can access all Illuminate\Testing\TestResponse functions as well.

:question: Missing frequent response helper? Open up a new issue.

Custom Response class

This example shows you how to create your custom TestResponse class with your custom functions.

Then in your ServiceProvider (e.g. AppServiceProvider) or TestCase:

Custom Builder class

This example shows you how to create your custom GraphQLBuilder class with your custom functions.

Then in your ServiceProvider (e.g. AppServiceProvider):

Drivers

Drivers help you to construct request by pulling information from GraphQL server config, so you can discard some builder calls. You can write your custom driver if none of ours fits your needs.

RebingDriver (Default)

https://github.com/rebing/graphql-laravel

It reads URL prefix from config graphql.route.prefix and takes first HTTP method from config by schema name.

This is the default driver.

NullDriver

It uses /graphql URL prefix and POST HTTP Method.

To use, call GraphQLTesting::useNullDriver() in your AppServiceProvider.php boot() method.

Custom driver

Example on how to implement custom driver with name myCustom.

Then in your ServiceProvider (e.g. AppServiceProvider):

:handshake: Contributing

We'll appreciate your collaboration to this package.

When making pull requests, make sure:


All versions of laravel-graphql-test-utils with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/contracts Version ^8.12|^9.0|^10.0|^11.0
illuminate/support Version ^8.12|^9.0|^10.0|^11.0
illuminate/testing Version ^8.12|^9.0|^10.0|^11.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package newman/laravel-graphql-test-utils contains the following files

Loading the files please wait ....