https://github.com/protung/functional-test-bundle
Symfony bundle for functional testing
https://github.com/protung/functional-test-bundle
php symfony-bundle testing
Last synced: about 1 month ago
JSON representation
Symfony bundle for functional testing
- Host: GitHub
- URL: https://github.com/protung/functional-test-bundle
- Owner: protung
- License: mit
- Created: 2016-07-15T14:18:35.000Z (almost 9 years ago)
- Default Branch: 2.x
- Last Pushed: 2024-05-29T08:37:05.000Z (about 1 year ago)
- Last Synced: 2024-05-29T20:45:19.546Z (about 1 year ago)
- Topics: php, symfony-bundle, testing
- Language: PHP
- Size: 328 KB
- Stars: 5
- Watchers: 5
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Speicher210 Functional Test Bundle
## Introduction
This Bundle provides base classes and functionality for writing and running functional tests
with focus on testing REST endpoint.
It provides help in setting up test database and loading fixtures and mocking services in DI (even private services).## Installation
### Download the Bundle
```bash
$ composer require --dev speicher210/functional-test-bundle
```### Enable the Bundle
#### Symfony
```php
['dev' => true, 'test' => true],
// ...
];
```## Basic usage
Bootstrap for PHPUnit:
```php
assertRestRequestReturns404('/api/user/1', Request::METHOD_GET);
}public function testReturns200AndUserData() : void
{
$this->assertRestGetPath('/api/user/1');
}
}
```The assertions are done using snapshots for comparison.
By default the framework will look under `Expected` directory (from where the test class is located)
for a file with the same name as the test and suffixed with `-1.json`.Example of expected output can be:
`Expected/testReturns200AndUserData-1.json`
```json
{
"id": "1",
"first_name": "John",
"last_name": "Doe",
"email": "@string@",
"sign_up_date_time": "@[email protected]()"
}
```
The `-1.json`suffix will be incremented for every REST assertion made under one test.
In the expected any functionality from `coduo/php-matcher` can be used.It is possible to automatically update content of expected files during test execution to the actual content by adding
this extension to your phpunit config:```xml
```
Fixtures are loaded using Doctrine fixtures.
By default the framework will look by default under `Fixtures` directory (from where the test class is located)
for a PHP file with the same name as the test. This file must return an array of class names that extend
`Speicher210\FunctionalTestBundle\Test\Loader\AbstractLoader` class.
Example of fixture file can be:```php
```
## Accessing and mocking services
Mocking services can be achieved by using
```php
mockContainerService('my_service_id', $myServiceMock);
```Services can also be accessed by using
```php
getContainerService('my_service_id');
```