{"id":15014540,"url":"https://github.com/hyperia-sk/codecept-unittest-generator","last_synced_at":"2025-04-12T08:08:43.741Z","repository":{"id":56987758,"uuid":"113591208","full_name":"hyperia-sk/codecept-unittest-generator","owner":"hyperia-sk","description":"Generate PHPUnit tests from annotations, which you can write in your methods documentation","archived":false,"fork":false,"pushed_at":"2021-08-04T10:19:06.000Z","size":16,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-12T08:05:35.938Z","etag":null,"topics":["annotations","php","phpunit","phpunit-skeleton","testgenerator","unittest"],"latest_commit_sha":null,"homepage":null,"language":"HTML","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/hyperia-sk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-08T15:53:35.000Z","updated_at":"2024-01-17T12:19:24.000Z","dependencies_parsed_at":"2022-08-21T09:40:29.065Z","dependency_job_id":null,"html_url":"https://github.com/hyperia-sk/codecept-unittest-generator","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperia-sk%2Fcodecept-unittest-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperia-sk%2Fcodecept-unittest-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperia-sk%2Fcodecept-unittest-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperia-sk%2Fcodecept-unittest-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyperia-sk","download_url":"https://codeload.github.com/hyperia-sk/codecept-unittest-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248537138,"owners_count":21120709,"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":["annotations","php","phpunit","phpunit-skeleton","testgenerator","unittest"],"created_at":"2024-09-24T19:45:44.918Z","updated_at":"2025-04-12T08:08:43.707Z","avatar_url":"https://github.com/hyperia-sk.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Codecept UnitTest generator\n\nThis package allows you to generate PHPUnit tests from annotations, which you can write in your methods documentation.\n\n- Basic usage of this package is to generate your tests skeleton and basic tests.\n- You must check and complete all tests you generate, including the most basic methods.\n- Files to parse must declare one class, abstract class, trait or interface to be accepted.\n\n![screenshot_2017-12-08_17-12-32-github](https://user-images.githubusercontent.com/6382002/33774260-0aaacebc-dc3b-11e7-8a97-34265a4818cc.png)\n\n## Installation\n\nThe preferred way to install this extension is through [composer](http://getcomposer.org/download/).\n\nEither run\n\n```shell\ncomposer require hyperia/codecept-unittest-generator:\"^1.0\"\n```\n\nor add\n\n```\n\"hyperia/codecept-unittest-generator\": \"^1.0\"\n```\n\nto the require section of your composer.json.\n\n## Configuration\n\nenable `UnitGenerator` extension in base `/codeception.yml` config file:\n\n```yaml\nextensions:\n    enabled:\n        - Codeception\\Extension\\RunFailed\n    commands:\n        - Codeception\\Command\\UnitGenerator\nunitgenerator:\n    config: \n        # erase old target files with new one\n        overwrite: true \n        # if you want to generate tests for Interface too\n        interface: false\n        # automaticaly generate tests for getter / setter method\n        auto: true\n        # ignore errors that can be ignored\n        ignore: true\n        # regex (/.*config.php/ for example) that files must not match to have a tests generation\n        exclude: '/.*Trait.*/'\n        # regex (/.*.php/ for example) that files should match to have a tests generation\n        include: '/.*.php/'\n    dirs:\n        # source directory =\u003e target directory\n        - common/models: tests/unit/unitgen/common/models/\n        - console/models: tests/unit/unitgen/console/models/\n```\n\n## Usage \n\n`./vendor/bin/codecept generate:unit`\n\n### Annotations\n\n```php\n/**\n * @PHPUnitGen\\\u003cphpunit_assertion_method\u003e(\u003cexpectation\u003e:{\u003cparameters...\u003e}) \n */\n```\n\nThis annotation use some parameters:\n\n* __phpunit_assertion_method__: It is the PHPUnit assertion method\nyou want ot use (like _assertEquals_, _assertInstanceOf_, _assertTrue_ ...).\n\n* __expectation__: The method return expected value. Some PHPUnit methods\ndoes not need it (like _assertTrue_), so in those cases, it can be null.\n\n* __parameters__: The method parameters.\n\nSee this example, we want to auto generate some simple test for this method:\n\n```php\n\u003c?php\n// The class to test content\n\n/** @PHPUnitGen\\AssertEquals('expected string':{1, 2, 'a string'}) */\n/** @PHPUnitGen\\AssertTrue(:{4, 5, 'another'}) */\n/** @PHPUnitGen\\AssertEquals(null) */\n/** @PHPUnitGen\\AssertNull() */\npublic function method(int $arg1 = 0, int $arg2 = 0, string $arg3 = 'default') {}\n```\n\nThose annotations will create basic PHPUnit tests:\n\n```php\n\u003c?php\n// The generated test for \"method\" in tests class\n\n$this-\u003eassertEquals('expectation string', $this-\u003emethod(1, 2, 'a string'));\n$this-\u003eassertTrue($this-\u003emethod(4, 5, 'another'));\n$this-\u003eAssertEquals(null, $this-\u003emethod());\n$this-\u003eassertNull($this-\u003emethod());\n```\n\n#### Getter and setter annotation\n\n```php\n\u003c?php\n// The class to test content\n\n/** @PHPUnitGen\\Get() */\n/** @PHPUnitGen\\Set() */\n```\n\nThose two annotations will allow you to auto-generate tests for simple getter / setter.\nYour getter / setter needs to be named like the following:\n\n```\nget\u003cMyProperty\u003e() {}\nset\u003cMyProperty\u003e() {}\n```\n\nPHPUnit Generator has an \"auto\" option: If you activate it, \nit will search for the property when it find a method beginning \nwith \"get\" or \"set\", and if the property exists, it will generate tests.\n\n#### Private or protected method\n\nIf the method to test is private or protected, PHPUnit Generator will access the method with PHP ReflectionClass.\n\n\n## Requirements\n\nUnitGenerator needs the following components to run:\n\n- Codeception UnitGenerator is a module for **Codeception**. It will need a running version of this tool.\n- [Phpunit-generator](https://github.com/paul-thebaud/phpunit-generator) package.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperia-sk%2Fcodecept-unittest-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyperia-sk%2Fcodecept-unittest-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperia-sk%2Fcodecept-unittest-generator/lists"}