PHPackages                             kent013/artisan-command-spectator-test - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. kent013/artisan-command-spectator-test

ActiveLibrary[API Development](/categories/api)

kent013/artisan-command-spectator-test
======================================

An artisan command to generate HTTP test using OpenAPI and Spectator.

v0.0.6(2y ago)051MITPHPPHP ^8.3

Since Aug 17Pushed 2y ago1 watchersCompare

[ Source](https://github.com/kent013/artisan-command-spectator-test)[ Packagist](https://packagist.org/packages/kent013/artisan-command-spectator-test)[ RSS](/packages/kent013-artisan-command-spectator-test/feed)WikiDiscussions main Synced 4w ago

READMEChangelogDependencies (8)Versions (7)Used By (0)

artisan-command-spectator-test
==============================

[](#artisan-command-spectator-test)

Artisan make command to generate HTTP testcases with OpenAPI and [spectator](https://github.com/hotmeteor/spectator).

Disclaimer
----------

[](#disclaimer)

This command generate only a scaffold. You need further implementation to test your API.

I'm using [api blueprint](https://apiblueprint.org/) for API specification. Generating OpenAPI json with using [apib2swagger](https://github.com/kminami/apib2swagger).

While I'm not writing OpenAPI directly, some data such as operation ID is not natural. Perhaps it will cause a problem on this command.

Installation
------------

[](#installation)

```
composer require --dev kent013/artisan-command-spectator-test

```

Generate config file
--------------------

[](#generate-config-file)

```
php artisan vendor:publish --tag="spectator-test"

```

Configuration
-------------

[](#configuration)

### Default namespace

[](#default-namespace)

If you want to change test namespaces, please add following line in your `.env` file and change the values.

```
SPECTATORTEST_NAMESPACE=Feature

```

### OpenAPI file path

[](#openapi-file-path)

You can set default open api path with adding following line in your `.env` file and change the values.

```
SPECTATORTEST_OPENAPI_PATH=documents/api/api.openapi3.json

```

This value is able to overide with `openapi-path` option.

Command line arguments
----------------------

[](#command-line-arguments)

```
./artisan make:spectator-test TestCaseClassName APIMethodPath...

```

Where `APIMethodPath` goes like

```
/api/v1/organization/{organization_id}/projects/{project_id}

```

Will be generate all HTTP methods corresponds on the path. If you want to select HTTP methods to generate test, prefix the path with comma-separated http methods as following.

```
GET,PUT:/api/v1/organization/{organization_id}/projects/{project_id}

```

Also you can pass multiple `APIMethodPath` to command as following.

```
GET,PUT:/api/v1/organization/{organization_id}/projects/{project_id} GET,DELETE:/api/v1/organization/{organization_id}/projects/{project_id}

```

For example,

```
./artisan make:spectator-test Http/Api/V1/OrganizationProjectTest GET,PUT:/api/v1/organization/{organization_id}

```

### Using tag

[](#using-tag)

If you using tag to group API paths, then you can use `--tags` argument as following.

```
./artisan make:spectator-test:testcase --tags Http/Api/V1/ProjectTest projects

```

Command line options
--------------------

[](#command-line-options)

`--openapi-path`

Path to Open API specification. You can specify Json or Yaml path or URL.

`--force`

Overrite class file or not;

`--tags`

Generate test methods matched with tags. With no `--tags` option, arguments will be processed as a path. You cannot select HTTP methods with tags.

`--test-name-with-path`Generate test method name from path like `testApiV1OrganizationProjectsPut204`. By default command will use operationId like `testProjects200`

### Example Test

[](#example-test)

```
./artisan make:spectator-test Http/Api/V1/OrganizationProjectTest GET,PUT:/api/v1/organization/{organization_id}/projects/{project_id}

```

```
