Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jwage/phpunit-test-generator
https://github.com/jwage/phpunit-test-generator
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/jwage/phpunit-test-generator
- Owner: jwage
- License: mit
- Created: 2018-10-31T01:57:44.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-06T11:20:47.000Z (almost 5 years ago)
- Last Synced: 2024-10-20T15:58:55.117Z (3 months ago)
- Language: PHP
- Size: 3.4 MB
- Stars: 28
- Watchers: 2
- Forks: 6
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHPUnit Test Generator
This PHP tool can generate PHPUnit test classes for your PHP classes.
This tool currently only supports the PSR4 autoloading strategy. If you would like to see it support
other autoloading strategies and application organizational structures, pull requests are welcome.## Install
```console
$ composer require --dev jwage/phpunit-test-generator
```You can also download the latest PHAR from the [releases](https://github.com/jwage/phpunit-test-generator/releases) page.
## Generate Test Class
Take a class named `App\Services\MyService` located in `src/Services/MyService.php`:
```php
namespace App\Services;class MyService
{
/** @var Dependency */
private $dependency;/** @var int */
private $value;public function __construct(Dependency $dependency, int $value)
{
$this->dependency = $dependency;
$this->value = $value;
}public function getDependency() : Dependency
{
return $this->dependency;
}public function getValue() : int
{
return $this->value;
}
}
```And a dependency to this class named `App\Services\Dependency` located in `src/Services/Dependency.php`:
```php
myService->getDependency());
}public function testGetValue() : void
{
self::assertSame(1, $this->myService->getValue());
}protected function setUp() : void
{
$this->dependency = $this->createMock(Dependency::class);
$this->value = 1;$this->myService = new MyService(
$this->dependency,
$this->value
);
}
}
```Now you have a skeleton unit test and you can fill in the defails of the generated methods.