{"id":16725225,"url":"https://github.com/potherca-abandoned/phpunit-testcase-traits","last_synced_at":"2025-03-23T15:30:59.334Z","repository":{"id":57044029,"uuid":"106012057","full_name":"potherca-abandoned/phpunit-testcase-traits","owner":"potherca-abandoned","description":"Traits that offer helper functions to be used in PHPUnit TestCases.","archived":true,"fork":false,"pushed_at":"2024-05-11T20:44:13.000Z","size":166,"stargazers_count":0,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-26T05:33:36.318Z","etag":null,"topics":["php","php53-compatible","phpunit","potherca","traits"],"latest_commit_sha":null,"homepage":"https://pother.ca/phpunit-testcase-traits/","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/potherca-abandoned.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}},"created_at":"2017-10-06T14:10:11.000Z","updated_at":"2024-05-13T08:33:03.000Z","dependencies_parsed_at":"2023-12-26T12:08:51.047Z","dependency_job_id":"b6b53a91-3014-4804-b66e-0676dcda7944","html_url":"https://github.com/potherca-abandoned/phpunit-testcase-traits","commit_stats":{"total_commits":59,"total_committers":5,"mean_commits":11.8,"dds":"0.18644067796610164","last_synced_commit":"e203627b31d9fa1df6935a50f8d6211817a0ed53"},"previous_names":["potherca/phpunit-testcase-traits"],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/potherca-abandoned%2Fphpunit-testcase-traits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/potherca-abandoned%2Fphpunit-testcase-traits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/potherca-abandoned%2Fphpunit-testcase-traits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/potherca-abandoned%2Fphpunit-testcase-traits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/potherca-abandoned","download_url":"https://codeload.github.com/potherca-abandoned/phpunit-testcase-traits/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245122671,"owners_count":20564355,"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","php53-compatible","phpunit","potherca","traits"],"created_at":"2024-10-12T22:48:21.509Z","updated_at":"2025-03-23T15:30:59.317Z","avatar_url":"https://github.com/potherca-abandoned.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Traits for PHPUnit Testcases\n\n[![project-stage-badge]][project-stage-page]\n[![license-badge]][gpl-3]\n\n\u003e Traits that offer helper functions to be used in PHPUnit TestCases.\n\n## Introduction\n\nThis projects contains various traits that offer convenience methods for tasks\nthat occur when creating test code.\n\n## Installation\n\n    composer require 'potherca/phpunit-testcase-traits'\n\n## Usage\n\nAdd a `use` statement for a desired trait to a class definition. The public API\nof that trait can then be used in the defined class.\n\nFor full details on how to use traits, please refer to [the section on traits in the PHP manual][php-traits].\n\n### PHP 5.3 compatibility\n\nTraits were not introduced until PHP5.4 so for older versions (i.e. PHP5.3) \nanother way to load the trait's functionality is needed. A `traitShim` function \nis provided that can be used from a [magic `__call` method][__call-magic-method].\n\nThis is done by adding the following code to each (abstract base) test-case were\na Trait is to be used\u003csup\u003e(1)\u003c/sup\u003e:\n\n```php\n\nclass ExampleTest extends \\PHPUnit_Framework_TestCase\n{\n    // ....\n\n    final public function __call($name, array $parameters)\n    {\n        return \\Potherca\\PhpUnit\\Shim\\Util::traitShim($this, $name, $parameters);\n    }\n\n    // ....\n}\n```\n\nThe public API of _all_ traits can then be used. \n\nIn order to aid text-editors and IDEs in offering auto-completion, the following doc-block can be added to the\ntest-case class:\n\n```php\n/**\n * @method array[] createDataProvider(array $subject)\n * @method \\PHPUnit_Framework_MockObject_MockObject | \\PHPUnit\\Framework\\MockObject\\MockObject createObjectFromAbstractClass($className)\n * @method string getCompatibleExceptionName($exceptionName)\n * @method void setDataProviderMaximumKeyLength($length)\n * @method void setDataProviderSortByKey($sort)\n * @method void setNonPublicProperty($subject, $name, $value)\n */\n```\n\n\u003csup\u003e(1)\u003c/sup\u003e Alternatively, the `src/Shim/function.traitShim.php` could be [loaded using composer's autoloader][composer-load-files].\n\n## Available traits\n\n- **CreateDataProviderTrait** -- _Create data-provider arrays._  \n  Creates a `key/value` pair from a given one-dimensional array of values,\n  which is meant to be returned from a data-provider method in a TestCase.\n\n- **CreateObjectFromAbstractClassTrait** -- _Create an object instance from an abstract class._  \n  Creates a concrete object whose methods can be called and, thus, be tested.\n  \n- **GetCompatibleExceptionNameTrait** -- _Provide names of PHP5 compatible `PHPUnit_Framework_Exception` for (new) PHP7 Exceptions._\n\n- **SetNonPublicPropertyTrait** -- _Change the value of a non-public class properties._\n\nFunctioning usage examples are available in the [`example`](./example) directory. \nAll examples can be run with `phpunit`. Simply use the `--config` flag to point \nto the desired config file (either `example-php-phpunit.xml` for the traits or \n`example-php53-phpunit.xml` for the PHP5.3 compatible Trait shims).\n\n## Colophon\n\n- **Author**: Created by [Potherca][potherca].\n- **Homepage**: [packagist][packagist-page] / [git-repo][git-repo]\n- **License**: Licensed under the  [GPL-3.0 license][gpl-3] (GNU General Public License v3.0)\n\n[__call-magic-method]: http://php.net/manual/en/language.oop5.overloading.php#object.call\n[composer-load-files]: https://getcomposer.org/doc/04-schema.md#files\n[git-repo]: https://github.com/Potherca/phpunit-testcase-traits\n[gpl-3]: ./LICENSE.md\n[license-badge]: https://img.shields.io/badge/License-GPL--3.0-blue.svg\n[packagist-page]: https://packagist.org/packages/potherca/phpunit-testcase-traits\n[php-traits]: http://php.net/manual/en/language.oop5.traits.php\n[potherca]: http://pother.ca/\n[project-stage-badge]: http://img.shields.io/badge/Project%20Stage-Development-yellowgreen.svg\n[project-stage-page]: http://bl.ocks.org/potherca/raw/a2ae67caa3863a299ba0/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpotherca-abandoned%2Fphpunit-testcase-traits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpotherca-abandoned%2Fphpunit-testcase-traits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpotherca-abandoned%2Fphpunit-testcase-traits/lists"}