Download the PHP package cerbero/octane-testbench without Composer
On this page you can find all versions of the php package cerbero/octane-testbench. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cerbero/octane-testbench
More information about cerbero/octane-testbench
Files in cerbero/octane-testbench
Package octane-testbench
Short Description Set of utilities to test Laravel applications powered by Octane.
License MIT
Homepage https://github.com/cerbero90/octane-testbench
Informations about the package octane-testbench
⛽ Octane Testbench
Set of utilities to test Laravel applications powered by Octane.
Install
Via Composer:
In tests/TestCase.php
, use the TestsOctaneApplication
trait:
Now all tests extending this class, even previously created tests, can run on Octane.
Usage
- Requests and responses
- Concurrency
- Cache
- Tables
- Events
- Container
In a nutshell, Octane Testbench
- is progressive: existing tests keep working, making Octane adoption easier for existing Laravel apps
- stubs out workers and clients: tests don't need a Swoole or RoadRunner server to run
- preserves the application state after a request, so assertions can be performed after the response
- offers fluent assertions tailored to Octane:
Requests and responses
HTTP requests are performed with the same methods we would normally call to test any Laravel application, except they will work for both standard and Octane routes:
Responses are wrapped in a ResponseTestCase
instance that lets us call response assertions, any assertion of the Laravel testing suite and the following exception assertions:
Furthermore, responses and exceptions can be debugged by calling the dd()
and dump()
methods:
Concurrency
Concurrency works fine during tests. However, PHP 8 forbids the serialization of reflections (hence mocks) and concurrent tasks are serialized before being dispatched. If tasks involve mocks, we can fake the concurrency:
In the test above we are running tasks sequentially without serialization, allowing mocked methods to be executed (we will see more about mocks later).
If we need more control over how concurrent tasks run, we can pass a closure to expectsConcurrency()
. For example, the test below runs only the first task:
To manipulate the results of concurrent tasks, we can use expectsConcurrencyResults()
:
Finally we can make concurrent tasks fail to test our code when something wrong happens:
Cache
Octane Testbench provides the following assertions to test the Octane cache:
Tables
Octane tables can be tested with the following assertions:
Events
By default listeners for the Octane RequestReceived
event are disabled to perform assertions on the application state. However we can register listeners for any Octane event if need be:
Container
Octane Testbench also introduces the following helpers to bind and mock services at the same time while preserving a fluent syntax:
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
Contributing
Please see CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Andrea Marco Sartori
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of octane-testbench with dependencies
laravel/octane Version ^1.0
mockery/mockery Version ^1.0
phpunit/phpunit Version >=9.3