{"id":17323912,"url":"https://github.com/sanmai/phpunit-legacy-adapter","last_synced_at":"2026-05-02T03:10:20.092Z","repository":{"id":52235419,"uuid":"289403879","full_name":"sanmai/phpunit-legacy-adapter","owner":"sanmai","description":"PHPUnit Legacy Versions Adapter","archived":false,"fork":false,"pushed_at":"2026-05-02T01:43:10.000Z","size":87,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-05-02T02:29:44.218Z","etag":null,"topics":["phpunit","phpunit-legacy-adapter"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sanmai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["sanmai"]}},"created_at":"2020-08-22T02:23:51.000Z","updated_at":"2026-05-02T01:42:15.000Z","dependencies_parsed_at":"2024-06-19T17:39:55.211Z","dependency_job_id":"b314caf2-19f5-4063-8f5b-89871596b7b0","html_url":"https://github.com/sanmai/phpunit-legacy-adapter","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/sanmai/phpunit-legacy-adapter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanmai%2Fphpunit-legacy-adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanmai%2Fphpunit-legacy-adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanmai%2Fphpunit-legacy-adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanmai%2Fphpunit-legacy-adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sanmai","download_url":"https://codeload.github.com/sanmai/phpunit-legacy-adapter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanmai%2Fphpunit-legacy-adapter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32521183,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T01:12:54.858Z","status":"online","status_checked_at":"2026-05-02T02:00:05.923Z","response_time":132,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["phpunit","phpunit-legacy-adapter"],"created_at":"2024-10-15T14:09:31.432Z","updated_at":"2026-05-02T03:10:20.074Z","avatar_url":"https://github.com/sanmai.png","language":"PHP","funding_links":["https://github.com/sponsors/sanmai"],"categories":[],"sub_categories":[],"readme":"## PHPUnit Legacy Versions Adapter\n\nAs you're here, you are probably well aware that PHPUnit 8+ requires [common template methods](https://phpunit.readthedocs.io/en/latest/fixtures.html) \nlike `setUp()` or `tearDown()` to have a `void` return type declaration, which methods naturally break anything below PHP 7.1.\n\nAlthough it is not a big deal to automatically update your code to use these return type declaration with help from the likes of [PHP-CS-Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer) or [Rector](https://github.com/rectorphp/rector/blob/master/docs/rector_rules_overview.md#phpunit), \nit might become a problem if, for whatever unfortunate (but, hopefully, lucrative) reasons, you have to ensure your code is working under PHP 7.0 or PHP 5.6, all the \nwhile wanting using the best world can give you in the more-less recent versions of PHPUnit.\n\nIn this case, you'll have two problems. One, newer versions of PHPUnit [do not have old assertions](https://thephp.cc/news/2019/02/help-my-tests-stopped-working), but you can find a way around this, and another,\nas mentioned, newer versions of PHPUnit require  `void` return type declarations for the convenient template methods, and then you're stuck because \nrewriting tests to work without these template methods is a major pain and might be impossible even. And then this small library comes to save your day!\n\n```\ncomposer require --dev sanmai/phpunit-legacy-adapter:\"^6.4 || ^8.2.1\"\n```\n\n### How to use\n\nFirst, update your tests to extend from `\\LegacyPHPUnit\\TestCase` instead of `\\PHPUnit\\Framework\\TestCase`:\n\n```diff\n- class MyTest extends \\PHPUnit\\Framework\\TestCase\n+ class MyTest extends \\LegacyPHPUnit\\TestCase\n```\n\nThen, where you had to use `setUp(): void`  template method, use `doSetUp()` method, omitting all any any return types in a fully backward-compatible way. \n\n```diff\n- protected function setUp(): void\n+ protected function doSetUp()\n```\n\nThere are similar replacements for most other template method:\n\n```diff\n- public static function setUpBeforeClass(): void\n+ public static function doSetUpBeforeClass()\n```\n\n```diff\n- public static function tearDownAfterClass(): void\n+ public static function doTearDownAfterClass()\n```\n\n```diff\n- protected function setUp(): void\n+ protected function doSetUp()\n```\n\n```diff\n- protected function tearDown(): void\n+ protected function doTearDown()\n```\n\n```diff\n- protected function assertPreConditions(): void\n+ protected function doAssertPreConditions()\n```\n\n```diff\n- protected function assertPostConditions(): void\n+ protected function doAssertPostConditions()\n```\n\n### Reference\n\n|  Method     | Replacement                   |\n| ----------- | ----------------------------- |\n| `setUpBeforeClass(): void` | `doSetUpBeforeClass()` |\n| `tearDownAfterClass(): void` | `doTearDownAfterClass()` |\n| `setUp(): void` | `doSetUp()` |\n| `tearDown(): void` | `doTearDown()` |\n| `assertPreConditions(): void` | `doAssertPreConditions()` |\n| `assertPostConditions(): void` | `doAssertPostConditions()` |\n\n\n### Supported versions\n\n- 6.x version branch supports [PHPUnit 4](https://phpunit.de/getting-started/phpunit-4.html), [PHPUnit 5](https://phpunit.de/getting-started/phpunit-5.html), and [PHPUnit 6](https://phpunit.de/getting-started/phpunit-6.html). \n  - It was tested to work under PHP 5.3 - PHP 7.4. \n  - ![Continuous Integration](https://github.com/sanmai/phpunit-legacy-adapter/workflows/Continuous%20Integration/badge.svg?branch=master)\n- 8.x version branch supports [PHPUnit 7](https://phpunit.de/getting-started/phpunit-7.html), [PHPUnit 8](https://phpunit.de/getting-started/phpunit-8.html), and [PHPUnit 9](https://phpunit.de/getting-started/phpunit-9.html). \n  - It was tested to work under PHP 7.1 - PHP 8.1.\n  - ![Continuous Integration](https://github.com/sanmai/phpunit-legacy-adapter/workflows/Continuous%20Integration/badge.svg?branch=legacy)\n\nFuture versions will likely follow the same pattern.\n\n### What this library does not do\n\nAlthough this library solves the most annoying part of the problem, there are other parts the library was not designed to cover. For example:\n\n- Some versions of PHPUnit allow `assertContains` to be used with strings, while other do not. \n- In some versions one method is called `expectExceptionMessageRegExp`, while in others the same method is called `expectExceptionMessageMatches`.\n- And so on and on.\n\nThere are polyfills for these changed methods (see below), but it should not be a big deal to write an ad hoc polyfill just for the methods you need. E.g.:\n\n```php\n    public function __call($method, $args)\n    {\n        if ($method === 'assertStringContainsString') {\n            $this-\u003eassertContains(...$args);\n        }\n        \n        if ($method === 'assertIsBool') {\n            $this-\u003eassertTrue(\\is_bool($args[0]));\n        }\n        \n        if ($method === 'expectExceptionMessageRegExp') {\n            $this-\u003eexpectExceptionMessageMatches(...$args);\n        }\n        \n        throw new \\InvalidArgumentException();\n    }\n```\n\nIf there are several modular (and not) multi-version polyfills for these, and other methods:\n\n- One of the most used is one that comes with [Symfony's PHPUnit Bridge](https://github.com/symfony/phpunit-bridge). You can [check the source here](https://github.com/symfony/phpunit-bridge/tree/5.x/Legacy). Note that [it does not support inheritance](https://github.com/symfony/symfony/pull/35311) (you'll have to import the trait into every class).\n- There's [`yoast/phpunit-polyfills`](https://github.com/Yoast/PHPUnit-Polyfills/).\n- There's [`phpunitgoodpractices/polyfill`](https://github.com/PHPUnitGoodPractices/polyfill).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanmai%2Fphpunit-legacy-adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsanmai%2Fphpunit-legacy-adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanmai%2Fphpunit-legacy-adapter/lists"}