{"id":15008319,"url":"https://github.com/pitchart/phlunit","last_synced_at":"2026-01-29T09:05:46.529Z","repository":{"id":45319856,"uuid":"337744382","full_name":"pitchart/phlunit","owner":"pitchart","description":"Fluent checks for phpunit","archived":false,"fork":false,"pushed_at":"2022-07-13T12:49:16.000Z","size":185,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T01:29:08.334Z","etag":null,"topics":["fluent","fluent-testing","php","phpunit","phpunit-assertions","tdd"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pitchart.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-10T14:12:02.000Z","updated_at":"2022-02-28T18:10:29.000Z","dependencies_parsed_at":"2022-08-28T13:53:16.099Z","dependency_job_id":null,"html_url":"https://github.com/pitchart/phlunit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pitchart%2Fphlunit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pitchart%2Fphlunit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pitchart%2Fphlunit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pitchart%2Fphlunit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pitchart","download_url":"https://codeload.github.com/pitchart/phlunit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pitchart%2Fphlunit/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259085459,"owners_count":22803206,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fluent","fluent-testing","php","phpunit","phpunit-assertions","tdd"],"created_at":"2024-09-24T19:17:36.847Z","updated_at":"2026-01-29T09:05:41.490Z","avatar_url":"https://github.com/pitchart.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.com/pitchart/phlunit.svg?branch=master)](https://travis-ci.com/pitchart/phlunit)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/pitchart/phlunit/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/pitchart/phlunit/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/pitchart/phlunit/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/pitchart/phlunit/?branch=master)\n\n# Phlunit: PHP Fluent Unit Testing\n\n`Check::that(tdd())-\u003ewith($phlunit)-\u003eisAnInstanceOf(Awesomeness::class);`\n\n__*Fluent assertions for phpunit.*__\n\n## Why ?\n\n`Phlunit` will make your tests:\n\n- **fluent to write:** juste type `Check::that($sut)` and let auto-completion guide you.\n- **fluent to read:** very close to plain English, making it easier for non-technical people to read test code.\n- **fluent to troubleshoot:** every failing check throws an Exception with a clear message status to ease your TDD experience.\n- **less error-prone:** no more confusion about the order of the \"expected\" and \"actual\" values.\n\n## Installation\n```bash\ncomposer require --dev pitchart/phlunit\n```\n\n## Write checks\n\nWrite test cases and test methods as usual, just switch to `Check::that()` to write your assertions :\n\n```php\nuse Pitchart\\Phlunit\\Check;\n\n$integers = [1, 2, 3, 4, 5, 42];\nCheck::that($integers)-\u003econtains(2, 3, 42);\n\n\n$heroes = \"Batman and Robin\";\nCheck::that($heroes)\n    -\u003estartsWith(\"Batman\")\n    -\u003econtains(\"Robin\")\n;\n\n// Collection checks\nCheck::that([0, 1, 2])\n    -\u003eisACollectionOf('integer')\n    -\u003ehasElementAt(1)\n    -\u003eand-\u003ehasNoElementAt(12)\n    -\u003ehasLength(3)\n    -\u003ehasNotLength(12)\n    -\u003econtains(1, 2)\n    -\u003eisSubsetOf(0, 1, 2, 3, 4)\n    -\u003econtainsNoDuplicateItem()\n;\n\n// PSR-7 ResponseInterface checks\n$response = (new Response(200))\n    -\u003ewithHeader('xxx-header', 'xxx-header-value')\n    -\u003ewithBody(Utils::streamFor('{\"name\": \"Batman\", \"city\": \"Gotham City\"}'))\n;\n\nCheck::that($response)\n    -\u003easJson()\n        -\u003ematchesSchema(['type' =\u003e 'object', 'required' =\u003e ['name'], 'properties' =\u003e ['name' =\u003e ['type' =\u003e 'string']]]);\n```\n\n`Phlunit` provides checks for the following types and classes :\n - string, boolean, integer, float, array\n - xml and json formats\n - iterable\n - callable\n - Throwable\n - ResponseInterface (PSR-7)\n - DateTimeInterface\n\n## Syntactic sugar\n\nImprove readability using `that()` and `andThat()` methods :\n\n```php\nCheck::thatCall([$spiderman, 'saveGotham'])-\u003ewith('batman', 'superman')\n    -\u003ethrows(\\LogicException::class)\n    -\u003ethat()-\u003eisDescribedBy(\"Sorry, we are not in the same univers!\");\n\nCheck::that($batman-\u003egetFirstname())-\u003eisEqualTo('Bruce')\n    -\u003eandThat($batman-\u003egetLastname())-\u003eisEqualTo('Wayne');\n```\n\n## Need more checks ?\n\n### Use custom constraints\n\nWrite custom phpunit constraints and use them thanks to methods `is()`, `has()`, `isNot()` or `hasNot()` :\n\n```php\nclass CustomConstraint extends Constraint\n{\n    //...\n}\n\nCheck::that($sut)-\u003eis(new CustomConstraint());\n```\n\n### Create custom Check class\n\n```php\nclass CustomClassCheck implements FluentCheck\n{\n    //...\n}\n\n// Register your custom checks for dedicated classes in phpunit's bootstrap file\nCheck::registerChecksFor(Custom::class, CustomClassChecks::class);\n\n//\nCheck::that(Check::that(new Custom))-\u003eisAnInstanceOf(CustomClassChecks::class);\n```\n\n## Test data builder\n\n`Phlunit` provides a simple and extensible way to implement the [test data builder pattern](http://www.natpryce.com/articles/000714.html).\n\nHere is the recommended way to use it, to not break the fluent experience:\n\n```php\nuse Pitchart\\Phlunit\\Builder;\n\nclass HeroBuilder extends Builder\n{\n    protected function __construct(array $arguments)\n    {\n        parent::__construct(Hero::class, $arguments);\n    }\n    \n    public function build(): Hero\n    {\n        return $this-\u003ebuildInstance();\n    }\n    \n    public static function create(): self\n    {\n        return new self([\n            'name' =\u003e 'Batman',\n            'firstname' =\u003e 'Bruce',\n            'lastname' =\u003e 'Wayne',\n        ]);\n    }\n    \n    public static function batman(): self\n    {\n        return self::create();\n    }\n}\n\n// Use it in your test cases:\n$batman = HeroBuilder::batman()-\u003ebuild();\n\n$superman = HeroBuilder::create()\n    -\u003ewithName('Superman')\n    -\u003eandFirstname('Clark')\n    -\u003eandLastname('Kent')\n    -\u003ebuild()\n;\n```\n\n## Expect exceptions\n\n`Phlunit` provides a fluent way to expect exception from your code, using the `Expect` class:\n\n```php\nuse Pitchart\\Phlunit\\Expect;\n\npublic function test_an_exception_is_thrown()\n{\n    Expect::after($this)\n        -\u003eanException(\\InvalidArgumentException)\n        -\u003edescribedBy('An exception message')\n        -\u003ehavingCode(42);\n    \n    // Act\n}\n```\n\n## Credits\n\nThis package has been mainly inspired by [NFluent](http://www.n-fluent.net/) and [AssertJ](https://joel-costigliola.github.io/assertj/)\n\nThanks to [Bruno Boucard](https://github.com/boucardbruno) for the inspiration.\n\n## Licence\n\nThe [MIT Licence](LICENCE.md)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpitchart%2Fphlunit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpitchart%2Fphlunit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpitchart%2Fphlunit/lists"}