{"id":25842989,"url":"https://github.com/m50/phpunit-expect","last_synced_at":"2026-05-09T12:38:22.946Z","repository":{"id":47213742,"uuid":"384875482","full_name":"m50/phpunit-expect","owner":"m50","description":"An Expectation API for phpunit","archived":false,"fork":false,"pushed_at":"2021-09-08T04:59:40.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-24T07:43:55.520Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/m50.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-11T06:23:51.000Z","updated_at":"2021-09-08T04:59:42.000Z","dependencies_parsed_at":"2022-08-19T10:31:51.196Z","dependency_job_id":null,"html_url":"https://github.com/m50/phpunit-expect","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m50%2Fphpunit-expect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m50%2Fphpunit-expect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m50%2Fphpunit-expect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m50%2Fphpunit-expect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/m50","download_url":"https://codeload.github.com/m50/phpunit-expect/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241329400,"owners_count":19944982,"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":[],"created_at":"2025-03-01T06:35:21.898Z","updated_at":"2026-05-09T12:38:17.915Z","avatar_url":"https://github.com/m50.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHPUnit Expect\n\n![psalm type coverage](https://shepherd.dev/github/m50/phpunit-expect/coverage.svg)\n[![Test](https://github.com/m50/phpunit-expect/actions/workflows/test.yml/badge.svg)](https://github.com/m50/phpunit-expect/actions/workflows/test.yml)\n[![styleci status](https://github.styleci.io/repos/384875482/shield)](https://github.styleci.io/repos/384875482)\n\n[![Latest Stable Version](https://poser.pugx.org/m50/phpunit-expect/v/stable)](https://packagist.org/packages/m50/phpunit-expect)\n[![Total Downloads](https://poser.pugx.org/m50/phpunit-expect/downloads)](https://packagist.org/packages/m50/phpunit-expect)\n[![License](https://poser.pugx.org/m50/phpunit-expect/license)](https://packagist.org/packages/m50/phpunit-expect)\n\nAn expectation API for PHPUnit, inspired by [Jest](https://jestjs.io) for JS, and [Pest](https://pestphp.com) for PHP.\n\n## Install\n\n\u003e This requires PHP 8.\n\nThe best way to install this package is with Composer.\n\n```sh\ncomposer require --dev m50/phpunit-expect\n```\n\n## Usage\n\n\u003e For additional examples, check out the tests, every expectation is utilized in a test.\n\nWhen writing tests, instead of using the standard assert, you can use expect.\n\n```php\n\u003c?php\n\nnamespace Tests;\n\nuse Expect\\Traits\\Expect;\nuse PHPUnit\\Framework\\TestCase;\n\nclass Test extends TestCase\n{\n    use Expect;\n\n    public function testAdd()\n    {\n        $this-\u003eexpect(2 + 2)-\u003etoBe(4);\n    }\n}\n```\n\nAny assertion on your test case can be used with this API. For example:\n\n```php\nclass CustomerAssertTest extends TestCase\n{\n    use Expect;\n\n    public function assertCustomer($customer, string $message = ''): void\n    {\n        // Do some assertion\n    }\n\n    public function testCustomer()\n    {\n        // Populate the $customer variable with a possible Customer\n        $this-\u003eexpect($customer)-\u003etoBeCustomer();\n    }\n}\n```\n\nIt will replace `toBe` or `to` at the beginning of the function name with `assert`, so any assertion\nthat has not been translated, or any custom assertion you may have, can be utilized with this.\n\nAdditionally, you can chain assertions:\n\n```php\npublic function testStringChain()\n{\n    $this-\u003eexpect('Hello World')\n        -\u003etoLowerCase() // Converts a string all to lower case, to do case insensitive assertions.\n        -\u003etoStartWith('hello')\n        -\u003etoEndWith('world')\n    ;\n}\n```\n\nAnd, it also supports proxied/higher-order expectations:\n\n```php\npublic function testProxiedCalls()\n{\n    $this-\u003eexpect(['first' =\u003e 1, 'second' =\u003e 2])\n        -\u003efirst-\u003etoBe(1)\n        -\u003esecond-\u003etoBe(2)\n    ;\n\n    $class = new \\stdClass();\n    $class-\u003efirst = 1;\n    $class-\u003esecond = 2;\n\n    $this-\u003eexpect($class)\n        -\u003efirst-\u003etoBe(1)\n        -\u003esecond-\u003etoBe(2)\n    ;\n}\n\npublic function testSequence()\n{\n    $this-\u003eexpect(['first' =\u003e 1, 'second' =\u003e 2])-\u003esequence(\n        first: fn (Expectation $e) =\u003e $e-\u003etoBe(1),\n        second: fn(Expectation $e) =\u003e $e-\u003etoBe(2),\n    );\n\n    $class = new \\stdClass();\n    $class-\u003efirst = 1;\n    $class-\u003esecond = 2;\n}\n```\n\nAdditionally, you can `not` any expectation as well:\n\n```php\npublic function testAdd()\n{\n    $this-\u003eexpect(2 + 2)-\u003enot-\u003etoEqual(4);\n\n    // Or you can use the function, if you prefer.\n    $this-\u003eexpect(2 + 2)-\u003enot()-\u003etoEqual(4);\n}\n```\n\n## License\n\nPHPUnit-Expect is open-sourced software licensed under the [MIT license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm50%2Fphpunit-expect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fm50%2Fphpunit-expect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm50%2Fphpunit-expect/lists"}