{"id":21493647,"url":"https://github.com/milanowicz/php-testing","last_synced_at":"2025-04-23T14:36:28.281Z","repository":{"id":37859818,"uuid":"465018694","full_name":"milanowicz/php-testing","owner":"milanowicz","description":"Library for PHPUnit testing","archived":false,"fork":false,"pushed_at":"2025-04-17T12:57:59.000Z","size":408,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-18T03:55:33.678Z","etag":null,"topics":["php","phpunit","testing","testing-tools","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/milanowicz.png","metadata":{"files":{"readme":"ReadMe.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2022-03-01T18:54:09.000Z","updated_at":"2025-04-17T12:57:56.000Z","dependencies_parsed_at":"2025-03-18T14:31:30.642Z","dependency_job_id":"36c2e818-dbd3-4062-82f8-e8fb00efc711","html_url":"https://github.com/milanowicz/php-testing","commit_stats":{"total_commits":217,"total_committers":3,"mean_commits":72.33333333333333,"dds":"0.16129032258064513","last_synced_commit":"ecb1eee13f0de2d80ea09fbe28569b02b15ff370"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milanowicz%2Fphp-testing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milanowicz%2Fphp-testing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milanowicz%2Fphp-testing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milanowicz%2Fphp-testing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/milanowicz","download_url":"https://codeload.github.com/milanowicz/php-testing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250453606,"owners_count":21433237,"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":["php","phpunit","testing","testing-tools","unit-testing"],"created_at":"2024-11-23T15:43:50.667Z","updated_at":"2025-04-23T14:36:28.264Z","avatar_url":"https://github.com/milanowicz.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Testing\n![Test](https://github.com/milanowicz/php-testing/workflows/Testing/badge.svg?branch=master)\n[![Mutation testing](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fmilanowicz%2Fphp-testing%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/milanowicz/php-testing/master)\n[![codecov](https://codecov.io/gh/milanowicz/php-testing/branch/master/graph/badge.svg?token=42G6ETI9NV)](https://codecov.io/gh/milanowicz/php-testing)\n\n![](https://img.shields.io/packagist/php-v/milanowicz/php-testing)\n![](https://img.shields.io/github/languages/top/milanowicz/php-testing)\n\n![](https://img.shields.io/github/v/tag/milanowicz/php-testing)\n![](https://img.shields.io/github/repo-size/milanowicz/php-testing)\n![](https://img.shields.io/github/languages/code-size/milanowicz/php-testing)\n\n![](https://img.shields.io/packagist/v/milanowicz/php-testing)\n![](https://img.shields.io/packagist/dt/milanowicz/php-testing)\n![](https://img.shields.io/packagist/dd/milanowicz/php-testing)\n![](https://img.shields.io/packagist/dm/milanowicz/php-testing)\n\n\nLibrary for PHPUnit testing.\n\n\n## Usage\n\nInstall by Composer\n\n```shell\n\u003e composer require --dev milanowicz/php-testing\n```\n\n\n### Methods\n\nExample for using abstract class in your ClassTest:\n\n```php\nclass UnitTest extends Milanowicz\\Testing\\TestCase\n{\n    public function testMethod(): void\n    {\n        // All Traits in abstract Milanowicz\\Testing\\TestCase are extends!\n        // See below for further details from Trait methods\n    }\n}\n```\n\nOR import Trait(s) for use them:\n\n```php\nclass UnitTest extends What\\Ever\\TestCase\n{\n    use Milanowicz\\Testing\\TestTrait;\n\n    public function testMethod(): void\n    {\n        // Access to private or protected Method\n        $this-\u003eaccessMethod((object) Class, (string) Method);\n        // Run test(s) in it and when an assertion failed would throw, see message and data for the reason\n        $this-\u003ecatchAssertionFailing((array) $data, function ($data) {\n            $this-\u003eassertEquals('whatEver', $data['whatEver']);\n        }, (string) $catchData = ExpectationFailedException::class);\n        // Create class without constructor\n        $this-\u003ecreateInstanceWithoutConstructor((string) Class);\n        // Call a private or protected Method with argument(s)\n        $this-\u003einvokeMethod((object) Class, (string) Method, (mixed) ArgumentsForMethod);\n        // Set a value to private or protected property \n        $this-\u003esetProperty((object) Class, (string) Property, (mixed) PropertyValue);\n        // Get a value from a private or protected property back\n        $this-\u003egetProperty((object) Class, (string) Property);\n        // Execute test of number tries to check, if it runs multiply times successfully\n        $this-\u003etestLoops((callable) Function, (int) NumberOfTries, (int) NumberOfErrors);\n        // Execute test and when it's throw an exception, then try it again\n        $this-\u003etryTest((callable) Function, (int) NumberOfTries);\n    }\n}\n\n```\n\nTestPerformanceTrait is to execute two functions and see which was faster of those:\n\n```php\nclass UnitTest extends What\\Ever\\TestCase\n{\n    use Milanowicz\\Testing\\TestPerformanceTrait;\n\n    public function testMethod(): void\n    {\n        // Example functions\n        $cb1 = static function () {\n            usleep(100);\n        };\n        $cb2 = static function () {\n            usleep(200);\n        };\n\n        // Call both methods after each other and save run times from them\n        $this-\u003emeasureTime((callable) $cb1, (callable) $cb2, (int) $n = 20);\n        // Check AVG and Student-Test\n        $this-\u003echeckPerformance((bool) $function1 = true, (float) $pValue = 0.05);\n        // $cb1 should be faster \n        $this-\u003echeckMeanTime((bool) $function1 = true);\n        // $cb2 should be slower and throw an Exception \n        $this-\u003echeckMeanTime((bool) false);\n        // Check if $cb1 is significant faster\n        $this-\u003echeckStudentTest((float) $pValue = 0.05);\n        // Get all time measures\n        $this-\u003egetTimeMeasures();\n        // Get both in array with AVG, STD and Median \n        $this-\u003egetTimeStats();\n        // Get result from Student-T test \n        $this-\u003egetTimeSignificance();\n        // Clear all times and measures\n        $this-\u003eclearTimes(); \n    }\n}\n```\n\n\n### Exception\n\nUsage for AssertionFailedException to get data in Exception message:\n\n```php\n$e = new AssertionFailedException(\n    (string) $message = 'Testing',\n    (array) $data = [1],\n    (int) $code = 1,\n    (null|Throwable) $previous = null,\n);\n$e-\u003etoArray(); // =\u003e [1]\n$e-\u003ecount(); // =\u003e 1\n$e-\u003etoString(); // =\u003e Message and Data as String\n\n// and all Exception methods are available:\n$e-\u003egetMessage(); // =\u003e Message and Data as String\n$e-\u003egetCode(); // =\u003e 1\n$e-\u003egetPrevious(); // =\u003e null OR a Throwable object\n```\n\n\n## Development\n\nRun all test suites\n```shell\n\u003e composer tests\n```\n\nRun PHP Code Styling\n```shell\n\u003e composer style\n```\n\nRun PHPStan to analyze code\n```shell\n\u003e composer analyze\n```\n\nRun PHPUnit tests\n```shell\n\u003e composer test\n```\n\nRun Mutation tests by Infection\n```shell\n\u003e composer infection\n```\n\n\n## License\n\n[GNU GPL Version 3](http://www.gnu.org/copyleft/gpl.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilanowicz%2Fphp-testing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmilanowicz%2Fphp-testing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilanowicz%2Fphp-testing/lists"}