Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/haberkamp/phluent
A fluent assertion library for PHPUnit. Make your tests read the same way you speak.
https://github.com/haberkamp/phluent
assertions fluent php phpunit testing
Last synced: 4 months ago
JSON representation
A fluent assertion library for PHPUnit. Make your tests read the same way you speak.
- Host: GitHub
- URL: https://github.com/haberkamp/phluent
- Owner: Haberkamp
- License: mit
- Created: 2024-08-02T11:29:38.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-08-19T14:21:11.000Z (5 months ago)
- Last Synced: 2024-10-09T11:43:32.227Z (4 months ago)
- Topics: assertions, fluent, php, phpunit, testing
- Language: PHP
- Homepage:
- Size: 190 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# đĻ Phluent
Make your tests read the same way you speak.
## đ Highlights
- Write your tests in the same way you speak
- Makes tests easier to understand
- Improves collaboration and communication## âšī¸ Overview
Phluent is an assertion library for PHPUnit. It's API design mimics how we speak as humans, this way it's easier
for you and your team members to understand what the test is doing.Compare the two assertions below, the first is using PHPUnit's Assert class and the other example uses Phluent.
```php
self::assertToBeGreaterThan(4, 3)
``````php
Expect(4)->toBeGreaterThan(3);
```The latter example is much easier to read and understand.
### âī¸ Authors
Hello, I'm Nils Haberkamp. I strongly believe that writing better tests makes one a better developer, leads to better
communication and collaboration and overall a better software. This package is my take on creating better tests.## đ Usage
```php
use PHPUnit\Framework\TestCase;
use function Phluent\Expect;class SomeTest extends TestCase {
public function test_one_plus_one_equals_two(): void
{
$result = 1 + 1;Expect($result)->toBe(2);
}
}
```Available assertions
* toBeEmpty
* toBe
* toBeAnInteger
* toBeNegative
* toBeInBetween
* toBePositive
* toBeGreaterThan
* toBeLessThan
* toBeAFloat
* toBeLessThanOrEqual
* toBeGreaterThanOrEqual
* toBeAString
* toBeEmpty
* toStartWith
* toEndWith
* toBeABoolean
* toBeAnArray
* toBeInstanceOf
* toBeNull
* toBeFalse
* toBeTrue
* toContainAllOf
* toContainAnyOf
* toContain
* toHaveALengthOf
* toThrow
* withMessage
* toHaveThrown
* withMessage## âŦī¸ Installation
First, install the package via composer:
```bash
composer require --dev phluent/phluent
```Now you need to include phluent in your autoloader. To do this open
the file that bootstraps PHPUnit. (This file is often located under: `tests/bootstrap.php`)
Open the file and add the following code:```php
require dirname(__DIR__) . '/vendor/phluent/phluent/src/Expect.php';
require dirname(__DIR__) . '/vendor/phluent/phluent/src/Act.php';
```The installation is now complete, and you're all set.
Requirements:
* PHP 7.4 or higher
* PHPUnit 9.0 or higher## đ Feedback and Contributing
Thank you for taking an interest in contributing to this project. Feel free to open an [issue](https://github.com/Haberkamp/phluent/issues/new)
or a pull request if you have any suggestions or improvements.## đ Thank you
I want to thank the people who contributed to the following projects. Without them, this project would
not exist.* [Fluent Assertions](https://github.com/fluentassertions/fluentassertions)
* [jest-extended](https://github.com/jest-community/jest-extended)
* [expect-more-jest](https://github.com/JamieMason/expect-more/tree/master/packages/expect-more-jest)Special thanks to the maintainers and contributors of [PHPUnit](https://github.com/sebastianbergmann/phpunit)
for creating such an awesome project.