https://github.com/svenluijten/laravel-collection-testing-helpers
🧑🏫 Convenience methods on your Laravel collections to make testing them more fluent.
https://github.com/svenluijten/laravel-collection-testing-helpers
collections laravel laravel-collections laravel-package laravel-testing phpunit-assertions
Last synced: 2 months ago
JSON representation
🧑🏫 Convenience methods on your Laravel collections to make testing them more fluent.
- Host: GitHub
- URL: https://github.com/svenluijten/laravel-collection-testing-helpers
- Owner: svenluijten
- License: mit
- Created: 2021-04-19T19:28:26.000Z (about 4 years ago)
- Default Branch: 1.x
- Last Pushed: 2024-03-26T15:44:27.000Z (about 1 year ago)
- Last Synced: 2025-01-28T23:23:04.054Z (4 months ago)
- Topics: collections, laravel, laravel-collections, laravel-package, laravel-testing, phpunit-assertions
- Language: PHP
- Homepage: https://svenluijten.com
- Size: 30.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README

# Laravel Collection Testing Helpers
[![Latest Version on Packagist][ico-version]][link-packagist]
[![Total Downloads][ico-downloads]][link-downloads]
[![Software License][ico-license]](LICENSE.md)
[![Build Status][ico-build]][link-build]
[![StyleCI][ico-styleci]][link-styleci]This package adds several convenience methods to your Laravel collections to make
assertions against them more fluent and readable.## Installation
You'll have to follow a couple of simple steps to install this package.### Downloading
Via [composer](http://getcomposer.org):```bash
$ composer require sven/laravel-collection-testing-helpers --dev
```Or add the package to your development dependencies in `composer.json` and run
`composer update` on the command line to download the package:```json
{
"require-dev": {
"sven/laravel-collection-testing-helpers": "^1.0"
}
}
```## Usage
To use this package in your tests, you must first call the `\Sven\LaravelCollectionTestingHelpers\Helpers::enable()`
method where you want to use the assertions. You may then use the methods directly on your collections:```php
assertContains('apple')
->assertNotContains('orange');
}public function test_callable_filtering()
{
Helpers::enable();
collect(['apple', 'pear', 'banana'])
->assertContains(fn ($fruit) => $fruit === 'pear')
->assertNotContains(fn ($fruit) => $fruit === 'kiwi');
}public function test_keyed_collections()
{
Helpers::enable();
collect([['name' => 'apple'], ['name' => 'pear'], ['name' => 'banana']])
->assertContains('name', 'apple')
->assertNotContains('name', 'grape');
}
}
```## Credits
Big thanks to [@eduarguz](https://github.com/eduarguz) for [his original work on this](https://github.com/svenluijten/laravel-testing-utils/pull/4)
in the now-abandoned [`sven/laravel-testing-utils`](https://github.com/svenluijten/laravel-testing-utils) package.## Contributing
All contributions (pull requests, issues and feature requests) are
welcome. Make sure to read through the [CONTRIBUTING.md](CONTRIBUTING.md) first,
though. See the [contributors page](../../graphs/contributors) for all contributors.## License
`sven/laravel-collection-testing-helpers` is licensed under the MIT License (MIT).
Please see the [license file](LICENSE.md) for more information.[ico-version]: https://img.shields.io/packagist/v/sven/laravel-collection-testing-helpers.svg?style=flat-square
[ico-license]: https://img.shields.io/badge/license-MIT-green.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/sven/laravel-collection-testing-helpers.svg?style=flat-square
[ico-build]: https://img.shields.io/github/actions/workflow/status/svenluijten/laravel-collection-testing-helpers/run-tests.yml?style=flat-square
[ico-styleci]: https://styleci.io/repos/359575155/shield[link-packagist]: https://packagist.org/packages/sven/laravel-collection-testing-helpers
[link-downloads]: https://packagist.org/packages/sven/laravel-collection-testing-helpers
[link-build]: https://github.com/svenluijten/laravel-collection-testing-helpers/actions/workflows/run-tests.yml
[link-styleci]: https://styleci.io/repos/359575155