laradev / test-support
Laravel development test support
Installs: 15
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/laradev/test-support
Requires
- php: ~7
- illuminate/container: ~5
- illuminate/support: ~5
- mockery/mockery: ~0.9
- phpunit/phpunit: ~5
This package is auto-updated.
Last update: 2025-10-13 17:09:39 UTC
README
This package provides helpers and utilities to facilitate testing of Laradev packages.
Install
composer require --dev laradev/test-support
Usage
Create a test case
Simply extend the class Laradev\Test\Support\TestCase.
namespace Example use Laradev\Test\Support\TestCase; final class ExampleClassTest extends TestCase { /** implement abstract methods **/ }
Utilities
The TestCase embeds a bunch of utilities in the form of traits.
Even if they can be used independently, it is more reliable to extends the TestCase class.
Assertions
The Assertions trait enhances the TestCase class with new assertions directly accessible to $this.
assertIsSubclassOf(string $expectedParent, string $actual, string $message = ''): asserts that the actual class is a sub class of a given one.assertBootMergesConfigForProvider(string $providerClass, string $configfile, string $message = ''): asserts that thebootmethod of a given service provider instance merges the configuration of its package with the main application one.assertBootPublishesConfigForProvider(string $providerClass, string $configfile, string $message = ''): asserts that thebootmethod of a given service provider instance publishes the configuration file to the application configuration path.
MockProvider
The MockProvider trait offers a set of factory methods to facilitate the creation of mocks of the main classes of Laravel.
Factory methods
newMock($whatToMock = null): returns an instance of$whatToMockor ofMockery\MockInterfaceif the argument value is null.newAppMock(): returns an instance ofIlluminate\Contracts\Foundation\Application.newConfigMock(): returns an instance ofIlluminate\Contracts\Config\Repository.newFunctionMock(string $functionName): should be used to create a mock of a function, it returns an instance ofMockery\CompositeExpectation.newAppContainerWithConfigMock(): returns an instance ofIlluminate\Contracts\Container\Containercontaining a config mock instance that is accessible using the keyconfig.
As the mock engine behind the scene is Mockery, all these instances implement the Mockery\MockInterface or Mockery\ExpectationInterface and then can be enhanced with expectations.
Other methods
releaseMocks(): releases all the mocks, does some cleanup.useFunction(string $functionName, ...$args): static method to call as the body of a mocked function (see MockProviderTest::testMockingFunctions() for an example on how to do this).
Note:
While extending theTestCaseabstract class, thereleaseMocksmethod is automatically called at the end of each test in thetearDownmethod.
If you intend to use theMockProvidertrait directly, it is important to note that you will need to call thereleaseMocksmethod by yourself.
License
This project is licensed under the terms of the MIT License