GithubHelp home page GithubHelp logo

haberkamp / phluent Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 195 KB

A fluent assertion library for PHPUnit. Make your tests read the same way you speak.

License: MIT License

Dockerfile 1.04% PHP 98.96%
assertions fluent php phpunit testing

phluent's Introduction

๐Ÿ“ฆ 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.

self::assertToBeGreaterThan(4, 3)
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

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:

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:

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 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.

Special thanks to the maintainers and contributors of PHPUnit for creating such an awesome project.

phluent's People

Contributors

haberkamp avatar philipp-doblhofer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.