https://github.com/pschocke/testmacros
A set of useful Laravel testing macros
https://github.com/pschocke/testmacros
laravel macros php testing
Last synced: 2 months ago
JSON representation
A set of useful Laravel testing macros
- Host: GitHub
- URL: https://github.com/pschocke/testmacros
- Owner: pschocke
- License: other
- Created: 2019-12-14T21:54:02.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-15T21:57:10.000Z (over 6 years ago)
- Last Synced: 2025-03-29T08:52:03.050Z (over 1 year ago)
- Topics: laravel, macros, php, testing
- Language: PHP
- Homepage:
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- Contributing: contributing.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel Test-Macros
This Package is inspired by Spaties [Laravel Collections](https://github.com/spatie/laravel-collection-macros) package and extends Laravels default Testing methods with a few useful macros.
## Installation
Via Composer
``` bash
$ composer require pschocke/testmacros --dev
```
The package will automatically register itself.
## Macros
### TestResponse
- [`assertResource`](#assertResource)
- [`asArray`](#asArray)
- [`resourceAsArray`](#resourceAsArray)
#### `assertResource`
Asserts that a response is a resource
```php
$model = factory(App\Model::class)->create();
$this->json('GET', '/route/to/resource')->assertResource(new ModelResource($model));
```
#### `asArray`
Returns the response of a call
```php
$responseArray = $this->json('GET', '/route/to/response')->asArray();
```
#### `ResourceAsArray`
Returns the data attribute of a API resource response
```php
$responseArray = $this->json('GET', '/route/to/resource')->resourceAsArray();
```
## Change log
Please see the [changelog](changelog.md) for more information on what has changed recently.
## Testing
`TODO`
## Contributing
Please see [contributing.md](contributing.md) for details and a todolist.
## Security
If you discover any security related issues, please email patrick@ausbildung-ms.de instead of using the issue tracker.
## License
MIT. Please see the [license file](license.md) for more information.
[ico-version]: https://img.shields.io/packagist/v/pschocke/testmacros.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/pschocke/testmacros.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/pschocke/testmacros/master.svg?style=flat-square
[ico-styleci]: https://styleci.io/repos/12345678/shield
[link-packagist]: https://packagist.org/packages/pschocke/testmacros
[link-downloads]: https://packagist.org/packages/pschocke/testmacros
[link-travis]: https://travis-ci.org/pschocke/testmacros
[link-styleci]: https://styleci.io/repos/12345678
[link-author]: https://github.com/pschocke
[link-contributors]: ../../contributors