solido / test-utils
Test utilities for solido suite
Installs: 11 023
Dependents: 2
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 0
Open Issues: 1
Requires
- php: ^8.1
- cache/array-adapter: ^1.0
- phpspec/prophecy-phpunit: ^2.0
- solido/common: ^0.3 || ^0.4
Requires (Dev)
- ext-json: *
- doctrine/dbal: ^2.10 || ^3.0
- doctrine/mongodb-odm: ^2.0
- doctrine/orm: ^2.7
- laravel/framework: ^8.0 || ^9.0 || ^10.0
- nyholm/psr7: ^1.0
- phpunit/phpunit: ^9.4
- refugis/doctrine-extra: ^2.1 || ^3.0
- refugis/elastica-odm: 2.x-dev
- roave/security-advisories: dev-master
- solido/php-coding-standards: dev-master
- solido/query-language: dev-master
- solido/security-policy-checker: dev-master
- symfony/browser-kit: ^5.4 || ^6.0 || ^7.0
- symfony/cache: ^5.4 || ^6.0 || ^7.0
- symfony/flex: ^2.0
- symfony/framework-bundle: ^5.4 || ^6.0 || ^7.0
- symfony/property-access: ^5.4 || ^6.0 || ^7.0
- symfony/translation: ^5.4 || ^6.0 || ^7.0
- symfony/validator: ^5.4 || ^6.0 || ^7.0
This package is auto-updated.
Last update: 2024-10-22 14:46:51 UTC
README
This package contains some testing utilities common to various solido suite packages.
Functional tests
JsonResponseTrait
Provides assertions to check content and deep properties of a returned json response.
The response has to be provided by a static getResponse
method and must be an instance of
Symfony\Component\HttpFoundation\Response
.
Property paths
The assertions in this trait allow checking deep properties into the returned JSON passing a property path to the assertion method.
Dots (.
) are used to access object properties, while brackets ([]
) are used to access
array indexes.
Example: user.emails[1]
should return the second element of the emails
property of the
user
object.
A special property path .
can be used to indicate the entire json object or array
contained in the response.
Assertions
assertJsonResponse(string $message = '')
Asserts that the response contains a JSON and has a Content-Type
header containing application/json
.
If the response content cannot be decoded, the assertion will fail.
assertJsonResponsePropertiesExist(array $expected, string $message = '')
Asserts that the JSON response contains all the properties in the $expected
array. The properties
are specified as property paths.
assertJsonResponsePropertyExists(string $propertyPath, string $message = '')
Asserts that one property path exists in the response object.
assertJsonResponsePropertyDoesNotExist(string $propertyPath, string $message = '')
Asserts that one property path does not exist in the response object.
assertJsonResponsePropertyEquals($expected, string $propertyPath, string $message = '')
Asserts that the value in property path equals the $expected
value.
PHPUnit IsEqual
constraint is used to check the values equality.
assertJsonResponsePropertyNotEquals($expected, string $propertyPath, string $message = '')
Asserts that the value in property path does not equal the $expected
value.
assertJsonResponsePropertyIsType(string $expected, string $propertyPath, string $message = '')
Asserts that the value in property path is of the specified type.
Type can be a FQCN or builtin type (array, bool, float, int, null, object, resource, string, scalar, callable).
PHPUnit IsType
constraint is used to check the property type.
assertJsonResponsePropertyIsArray(string $propertyPath, string $message = '')
Short-hand method for assertJsonResponsePropertyIsType('array', $propertyPath, $message)
assertJsonResponsePropertyCount(int $expected, string $propertyPath, string $message = '')
Asserts that the value in property path is countable and its count
is equal to $expected
.
assertJsonResponsePropertyContains($expected, string $propertyPath, string $message = '')
Asserts the specific response property contains the expected value.
Examples:
["Hello", "world", "!"]
contains "world"[{one: "Hello"}]
contains{ one: 'Hello' }
assertJsonResponsePropertyNotContains($unexpected, string $propertyPath, string $message = '')
Asserts the specific response property does not contain the expected value.
assertJsonResponsePropertyContainsString(string $expected, string $propertyPath, string $message = '')
Asserts that the property is a string and contains the given value.
ResponseStatusTrait
Provides assertions to check the status code of a Response
object retrieved by
a static getResponse
method.
assertResponseIs(int $expectedCode, string $message = '')
Asserts that the response code is exactly the one passed in $expectedCode
.
Short-hand assertions:
assertResponseIsOk(string $message = '')
- Expects status code 200assertResponseIsCreated(string $message = '')
- Expects status code 201assertResponseIsAccepted(string $message = '')
- Expects status code 202assertResponseIsNoContent(string $message = '')
- Expects status code 204assertResponseIsBadRequest(string $message = '')
- Expects status code 400assertResponseIsUnauthorized(string $message = '')
- Expects status code 401assertResponseIsPaymentRequired(string $message = '')
- Expects status code 402assertResponseIsForbidden(string $message = '')
- Expects status code 403assertResponseIsNotFound(string $message = '')
- Expects status code 404assertResponseIsMethodNotAllowed(string $message = '')
- Expects status code 405assertResponseIsPreconditionFailed(string $message = '')
- Expects status code 412assertResponseIsUnprocessableEntity(string $message = '')
- Expects status code 422
Assertions that checks multiple status codes:
assertResponseIsRedirect(string $message = '')
- Expects status code 3xxassertResponseIsNotRedirect(string $message = '')
- Expects status code not to be 3xxassertResponseIsSuccessful(string $message = '')
- Expects status code 2xxassertResponseIsNotSuccessful(string $message = '')
- Expects status code not to be 2xx
FunctionalTestTrait
Provides convenient methods to perform a request on a Symfony WebTestCase
.
Includes ResponseStatusTrait
and JsonResponseTrait
.
Doctrine ORM
EntityManagerTrait
Provides an instance of EntityManager upon a mocked DBAL connection.
Useful to test a raw SQL composition and result hydration.
onEntityManagerCreated method can be used to customize the entity manager instance (or load/inject metadata) just after entity manager creation.
MockPlatform
Dummy DBAL platform for EntityManagerTrait.
Doctrine Mongo ODM
DocumentManagerTrait
Provides an instance of DocumentManager for mongo upon a mocked mongo Client.
Elastica ODM
DocumentManagerTrait
Provides an instance of DocumentManager for elastica upon a mocked elastica Client.