Introduction
Rest-Control console is the command-line interface that provides access to a set of useful commands, that will make writing Rest-Control tests much easier and more efficient.
To see all the available commands, run the following:
user@computer:/path/to/project php vendor/bin/rest-control help
Configuration
By default configuration file is located in project directory under the name rest-control.yml.
tests: namespace: Sample\\ path: /sample classSuffix: Test.php methodPrefix: test #responseFilters: # - \Sample\Filter\Response\Class #apiMockResponses # - \Sample\ApiMockResponse apiClient: \RestControl\ApiClient\HttpGuzzleClient #Custom variables loaded for all testCases #variables: # sample: value # sample2: # - arrayValue # - arrayValue2
Tests namespace
tests: namespace: Sample\\ path: /sample classSuffix: Test.php methodPrefix: myTests
The runtime environment allows to run tests from namespace in PSR-4 format. Namespace configuration should consist of namespace and the path attributes.
Optionally you can specify classSuffix, a string that will be added at the end of test class name, also optional is methodPrefix which in turn will add provided string before every method name inside each command generated test class.
Upon running create:test command with above configuration will generate following test class:
// #path/to/project/tests/SampleClassTest.php class SampleClassTest { public function myTestsSampleGetMethod() { //.. } }
Response filters(todo)
responseFilters: - \Sample\Filter\Response\Class
Custom ApiClient(todo)
apiClient: \RestControl\ApiClient\HttpGuzzleClient
Variables(todo)
#Custom variables loaded for all testCases #variables: # sample: value # sample2: # - arrayValue # - arrayValue2
Command: run
Executes all tests that are located in any of the namespaces provided in rest-control.yml file.
Usage examples:
//run all tests user@computer:/path/to/project php vendor/bin/rest-control run //run selected tests by specifying tags that should be included: user@computer:/path/to/project php vendor/bin/rest-control run --tags=sampleTag,apiv1,rest
Command: create:test
Generates test class in given namespace, you can also opt to generate a method boilerplate inside that class.
user@computer:/path/to/project php vendor/bin/rest-control create:test sample.namespace.testCase
This command requires namesapce to be provided as a parameter, it needs to be formatted in dotnotation and camelCase.
Namespace used for this command must match with namespace specified in rest-control.yml file.
Additionally this command can generate test methods along with descriptions as per user input. This step is optional to skip it press enter.