{"id":16856746,"url":"https://github.com/jwage/phpunit-test-generator","last_synced_at":"2025-03-22T06:31:10.607Z","repository":{"id":57003462,"uuid":"155483055","full_name":"jwage/phpunit-test-generator","owner":"jwage","description":null,"archived":false,"fork":false,"pushed_at":"2020-02-06T11:20:47.000Z","size":3561,"stargazers_count":29,"open_issues_count":7,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-12T12:05:57.439Z","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/jwage.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}},"created_at":"2018-10-31T01:57:44.000Z","updated_at":"2024-10-26T18:53:31.000Z","dependencies_parsed_at":"2022-08-21T14:10:59.303Z","dependency_job_id":null,"html_url":"https://github.com/jwage/phpunit-test-generator","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwage%2Fphpunit-test-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwage%2Fphpunit-test-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwage%2Fphpunit-test-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwage%2Fphpunit-test-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwage","download_url":"https://codeload.github.com/jwage/phpunit-test-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244189624,"owners_count":20412986,"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":"2024-10-13T14:05:18.442Z","updated_at":"2025-03-22T06:31:09.099Z","avatar_url":"https://github.com/jwage.png","language":"PHP","readme":"# PHPUnit Test Generator\n\nThis PHP tool can generate PHPUnit test classes for your PHP classes.\n\nThis tool currently only supports the PSR4 autoloading strategy. If you would like to see it support\nother autoloading strategies and application organizational structures, pull requests are welcome.\n\n## Install\n\n```console\n$ composer require --dev jwage/phpunit-test-generator\n```\n\nYou can also download the latest PHAR from the [releases](https://github.com/jwage/phpunit-test-generator/releases) page.\n\n## Generate Test Class\n\nTake a class named `App\\Services\\MyService` located in `src/Services/MyService.php`:\n\n```php\nnamespace App\\Services;\n\nclass MyService\n{\n    /** @var Dependency */\n    private $dependency;\n\n    /** @var int */\n    private $value;\n\n    public function __construct(Dependency $dependency, int $value)\n    {\n        $this-\u003edependency = $dependency;\n        $this-\u003evalue = $value;\n    }\n\n    public function getDependency() : Dependency\n    {\n        return $this-\u003edependency;\n    }\n\n    public function getValue() : int\n    {\n        return $this-\u003evalue;\n    }\n}\n```\n\nAnd a dependency to this class named `App\\Services\\Dependency` located in `src/Services/Dependency.php`:\n\n```php\n\u003c?php\n\nnamespace App\\Services;\n\nclass Dependency\n{\n    public function getSomething() : null\n    {\n        return null;\n    }\n}\n```\n\nNow you can generate a test class for `MyService` with the following command:\n\n```console\n$ php vendor/bin/generate-unit-test \"App\\Services\\MyService\"\n```\n\nYou can also pass a path to a class instead of giving the class name:\n\n```console\n$ php vendor/bin/generate-unit-test src/Services/MyService.php\n```\n\nA test would be generated at `tests/Services/MyServiceTest.php` that looks like this:\n\n```php\ndeclare(strict_types=1);\n\nnamespace App\\Tests\\Services;\n\nuse App\\Services\\Dependency;\nuse App\\Services\\MyService;\nuse PHPUnit\\Framework\\MockObject\\MockObject;\nuse PHPUnit\\Framework\\TestCase;\n\nclass MyServiceTest extends TestCase\n{\n    /** @var Dependency|MockObject */\n    private $dependency;\n\n    /** @var int */\n    private $value;\n\n    /** @var MyService */\n    private $myService;\n\n    public function testGetDependency() : void\n    {\n        self::assertInstanceOf(Dependency::class, $this-\u003emyService-\u003egetDependency());\n    }\n\n    public function testGetValue() : void\n    {\n        self::assertSame(1, $this-\u003emyService-\u003egetValue());\n    }\n\n    protected function setUp() : void\n    {\n        $this-\u003edependency = $this-\u003ecreateMock(Dependency::class);\n        $this-\u003evalue = 1;\n\n        $this-\u003emyService = new MyService(\n            $this-\u003edependency,\n            $this-\u003evalue\n        );\n    }\n}\n```\n\nNow you have a skeleton unit test and you can fill in the defails of the generated methods.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwage%2Fphpunit-test-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwage%2Fphpunit-test-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwage%2Fphpunit-test-generator/lists"}