phpjit / apidoc-tests-generator
Generate PHPUnit test classes for a apidoc.
dev-main / 1.0.x-dev
2021-07-05 15:30 UTC
Requires
- php: ^7.1
- nikic/php-parser: ^4.1
Requires (Dev)
- doctrine/coding-standard: ^5.0
- fakerphp/faker: ^1.14
- hautelook/alice-bundle: ^2.9
- jetbrains/phpstorm-attributes: ^1.0
- justinrainbow/json-schema: ^5.2
- nesbot/carbon: ^2.49
- phpunit/phpunit: ^7.4
This package is auto-updated.
Last update: 2024-11-05 22:41:24 UTC
README
This PHP tool can generate ApiTestCase test classes for your ApiDoc.
Install
$ composer require --dev phpjit/apidoc-tests-generator
Generate Test Class
/srv/api # rm -rf tests/Func/Auto && bin/console generate-test-class Generating test class for PhpJit\ApidocTestsGenerator\TemplateClass\GetTemplateClassItemTest
<?php declare(strict_types=1); namespace Test\Func\Auto\Books; use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase; use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\Client; use ApiPlatform\Core\Bridge\Symfony\Routing\Router; use App\Tests\Api\RefreshDatabaseTrait; use PhpJit\ApidocTestsGenerator\TptClassTestInterface; class GetBooksItemTest extends ApiTestCase implements TptClassTestInterface { private Client $client; private Router $router; use RefreshDatabaseTrait; protected function setup(): void { $this->client = static::createClient(); $router = static::$container->get('api_platform.router'); if (!$router instanceof Router) { throw new \RuntimeException('api_platform.router service not found.'); } $this->router = $router; } public function testGetBooksCollection(): void { $this->client->request('GET', '/books/1'); self::assertResponseIsSuccessful(); self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); self::assertJsonContains([ '@context' => '/contexts/Books', '@id' => '/books', '@type' => 'hydra:Item' ]); } }
Test class written to /srv/api/tests/Func/Auto/Books/GetBooksItemTest.php Generating test class for PhpJit\ApidocTestsGenerator\TemplateClass\GetTemplateClassCollectionTest
fork by jwage/phpunit-test-generator