Download the PHP package soyhuce/laravel-testing without Composer

On this page you can find all versions of the php package soyhuce/laravel-testing. 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-testing

Helpers for Laravel tests

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status GitHub PHPStan Action Status Total Downloads

Extra tools for your laravel tests

Installation

You can install the package via composer:

Usage

Laravel assertions

To use Laravel specific assertions, you will have to add \Soyhuce\Testing\Assertions\LaravelAssertions::class trait to your test class.

assertModelIs

Matches if the model is equal to the given model.

assertCollectionEquals

Matches if the collections are equal.

2 Collections are considered equal if they contain the same elements, indexed by the same keys and in the same order.

If the Collections contain Models, assertCollectionEquals will use Model comparison of assertIsModel.

You can give an array in the $expected parameter of assertCollectionEquals :

assertCollectionEqualsCanonicalizing

Matches if the collections are canonically equals.

2 Collections are considered equal if they contain the same elements, indexed by the same keys.

If the Collections contain Models, assertCollectionEqualsCanonicalizing will use Model comparison of assertIsModel.

You can give an array in the $expected parameter of assertCollectionEqualsCanonicalizing :

TestResponse assertions

All these methods are available in Illuminate\Testing\TestResponse:

Contract Testing

Requires hotmeteor/spectator package

Data

Json

View

FormRequest test in isolation

It's possible to test FormRequests in isolation thanks to the TestsFormRequests trait.

$testFormRequest have some methods to check authorization and validation of the request.

For exemple :

JsonResource test in isolation

It's possible to test the JsonResources in isolation thanks to the TestsJsonResources trait.

TestsJsonResources::createResponse(JsonResource $resource, ?Request $request = null) returns a Illuminate\Testing\TestResponse.

Matcher

Let's take this test

We can simplify this test by using a Matcher.

For Collections, we can use Matcher::collectionEquals() or Matcher::collectionEqualsCanonicalizing().

For more complex cases, we can use Matcher::make.

Partial match

In some cases, we wish to check only a few arguments or call argument methods:

We can use Matcher::match to define our assertions on $data:

In specific cases of object properties, we can use named parameters:

We can also check object type:

ActionMock

The trait MocksActions provides a mockAction method to simply mock an action. By convention, an action is a class with a execute method.

Under the hood, it uses Mockery::mock.

It allows to easily define your action's expectations. Instead of

you can write

You can also define the return value and capture it to use it in your test.

Helpers

It can be necessary to capture the return value of a callback, for exemple in returnUsing of mocks.

In this case, we will use capture function:

Once the mock executed, $version is created and will contain the returned value of the callback.

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-testing with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/database Version ^11.0|^12.0
illuminate/support Version ^11.0|^12.0
illuminate/testing Version ^11.0|^12.0
phpunit/phpunit Version ^11.0
spatie/invade Version ^2.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 soyhuce/laravel-testing contains the following files

Loading the files please wait ....