Download the PHP package gromatics/http-fixtures without Composer

On this page you can find all versions of the php package gromatics/http-fixtures. 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 http-fixtures

Laravel HTTP Fixtures

This package helps you create mock HTTP responses for Laravel tests. It combines Laravel's Http::fake functionality with Faker data generation to create realistic test data in a format similar to Laravel factories.

Contents


1. Installation

That's all you need to install the package as a development dependency in your Laravel project.

2. What is a HTTP fixture and why do I need it?

An HTTP fixture is a class that mocks the data of a JSON API endpoint. Sometimes you don't want to hit a real API in your tests. APIs can go down, and while your code may work perfectly, a downed API can cause your tests to fail. A common way to solve this is to save the JSON response and serve it using Http::fake, like this:

A saved JSON response can contain sensitive data, and it can be cumbersome to filter all of it out before committing the JSON to your repository. The Laravel HTTP Fixture package handles this for you. It can automatically create a fixture from an HTTP request and uses the Faker library to replace sensitive values, similar to how Laravel factories work. A HTTP fixture looks like this:


3. Creating a Fixture

3.1 Create a fixture from a real JSON response

The easiest way to create a fixture is by recording a real HTTP request in your test. You can do this by placing the Http::record() method before calling the service that makes the HTTP requests. After the service has finished, use HttpResponseRecorder::recordedToHttpFixture() to save the responses as fixtures.

A service can make multiple requests, and for each unique request, a new fixture will be created. If the same request is made more than once, it won’t duplicate the fixture.

For example:

This will create a StackexchangeSearchFixture.php file in /tests/Fixtures, which might look like this:


3.2 Create a fixture using the Artisan command

You can also create a fixture using an Artisan command. Just run the command below and follow the on-screen instructions:


3.3 Create a fixture from a JSON file

You can also create a fixture from a saved JSON file. For example, if you’ve saved a Stripe API response in your storage directory, you can do the following:

If your Stripe response looks like this;

Then the command will generate a fixture class similar to this:


4. Use a HTTP fixture in tests

You can use your HTTP fixture in your tests like this:

You can override specific keys when initializing the fixture:

This will return a JSON response similar to:

You can also use dot notation to update nested values:

This will produce a response where the first item's name is set to "John Doe".


5. Fixture options

The output of the fixture can be in JSON, XML, array and a Laravel collection.

XML

If you want to return XML instead of JSON, you can use the toXML() method and pass the root element name as a parameter. For example:

This will return na XML response similar to:


All versions of http-fixtures with dependencies

PHP Build Version
Package Version
Requires fakerphp/faker Version ^1
laravel/framework Version ^12
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 gromatics/http-fixtures contains the following files

Loading the files please wait ....