Package Data | |
---|---|
Maintainer Username: | eviweb |
Maintainer Contact: | dev@eviweb.fr (Eric VILLARD) |
Package Create Date: | 2017-03-23 |
Package Last Update: | 2017-05-27 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-20 15:00:03 |
Package Statistics | |
---|---|
Total Downloads: | 13 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
This package provides helpers and utilities to facilitate testing of Laradev packages.
composer require --dev laradev/test-support
Simply extend the class Laradev\Test\Support\TestCase
.
namespace Example
use Laradev\Test\Support\TestCase;
final class ExampleClassTest extends TestCase
{
/** implement abstract methods **/
}
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.
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 the boot
method 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 the boot
method of a given service provider instance publishes the configuration file to the application configuration path.The MockProvider
trait offers a set of factory methods to facilitate the creation of mocks of the main classes of Laravel.
newMock($whatToMock = null)
: returns an instance of $whatToMock
or of Mockery\MockInterface
if the argument value is null.newAppMock()
: returns an instance of Illuminate\Contracts\Foundation\Application
.newConfigMock()
: returns an instance of Illuminate\Contracts\Config\Repository
.newFunctionMock(string $functionName)
: should be used to create a mock of a function, it returns an instance of Mockery\CompositeExpectation
.newAppContainerWithConfigMock()
: returns an instance of Illuminate\Contracts\Container\Container
containing a config mock instance that is accessible using the key config
.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.
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 theTestCase
abstract class, thereleaseMocks
method is automatically called at the end of each test in thetearDown
method.
If you intend to use theMockProvider
trait directly, it is important to note that you will need to call thereleaseMocks
method by yourself.
This project is licensed under the terms of the MIT License