forked from loafle/openapi-generator-original
[php-slim4] Follow PDS skeleton (#9189)
* Rename test folder to tests * Put index.php and .htaccess into public * Refresh samples
This commit is contained in:
parent
f7bc2aa995
commit
84a6e31fb4
@ -57,6 +57,10 @@ public class PhpSlim4ServerCodegen extends AbstractPhpCodegen {
|
||||
public PhpSlim4ServerCodegen() {
|
||||
super();
|
||||
|
||||
// PDS skeleton recommends tests folder
|
||||
// https://github.com/php-pds/skeleton
|
||||
this.testBasePath = "tests";
|
||||
|
||||
modifyFeatureSet(features -> features
|
||||
.includeDocumentationFeatures(DocumentationFeature.Readme)
|
||||
.wireFormatFeatures(EnumSet.of(WireFormatFeature.JSON, WireFormatFeature.XML))
|
||||
@ -203,8 +207,8 @@ public class PhpSlim4ServerCodegen extends AbstractPhpCodegen {
|
||||
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("composer.mustache", "", "composer.json"));
|
||||
supportingFiles.add(new SupportingFile("index.mustache", "", "index.php"));
|
||||
supportingFiles.add(new SupportingFile(".htaccess", "", ".htaccess"));
|
||||
supportingFiles.add(new SupportingFile("index.mustache", "public", "index.php"));
|
||||
supportingFiles.add(new SupportingFile(".htaccess", "public", ".htaccess"));
|
||||
supportingFiles.add(new SupportingFile("SlimRouter.mustache", toSrcPath(invokerPackage, srcBasePath), "SlimRouter.php"));
|
||||
supportingFiles.add(new SupportingFile("phpunit.xml.mustache", "", "phpunit.xml.dist"));
|
||||
supportingFiles.add(new SupportingFile("phpcs.xml.mustache", "", "phpcs.xml.dist"));
|
||||
|
@ -38,9 +38,9 @@ Application requires at least one config file(`config/dev/config.inc.php` or `co
|
||||
|
||||
## Start devserver
|
||||
|
||||
Run the following command in terminal to start localhost web server, assuming `./php-slim-server/` is public-accessible directory with `index.php` file:
|
||||
Run the following command in terminal to start localhost web server, assuming `./php-slim-server/public/` is public-accessible directory with `index.php` file:
|
||||
```bash
|
||||
$ php -S localhost:8888 -t php-slim-server
|
||||
$ php -S localhost:8888 -t php-slim-server/public
|
||||
```
|
||||
> **Warning** This web server was designed to aid application development.
|
||||
> It may also be useful for testing purposes or for application demonstrations that are run in controlled environments.
|
||||
|
@ -7,7 +7,7 @@
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/{{#apiInfo}}
|
||||
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use {{invokerPackage}}\SlimRouter;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
@ -17,9 +17,9 @@ use OpenAPIServer\Mock\OpenApiDataMocker;
|
||||
|
||||
// load config file
|
||||
$config = [];
|
||||
if (is_array($prodConfig = @include(__DIR__ . '/config/prod/config.inc.php'))) {
|
||||
if (is_array($prodConfig = @include(__DIR__ . '/../config/prod/config.inc.php'))) {
|
||||
$config = $prodConfig;
|
||||
} elseif (is_array($devConfig = @include(__DIR__ . '/config/dev/config.inc.php'))) {
|
||||
} elseif (is_array($devConfig = @include(__DIR__ . '/../config/dev/config.inc.php'))) {
|
||||
$config = $devConfig;
|
||||
} else {
|
||||
throw new InvalidArgumentException('Config file missed or broken.');
|
||||
|
@ -1,11 +1,9 @@
|
||||
.gitignore
|
||||
.htaccess
|
||||
README.md
|
||||
composer.json
|
||||
config/.htaccess
|
||||
config/dev/example.inc.php
|
||||
config/prod/example.inc.php
|
||||
index.php
|
||||
lib/Api/AbstractPetApi.php
|
||||
lib/Api/AbstractStoreApi.php
|
||||
lib/Api/AbstractUserApi.php
|
||||
@ -39,4 +37,6 @@ lib/Model/User.php
|
||||
lib/SlimRouter.php
|
||||
phpcs.xml.dist
|
||||
phpunit.xml.dist
|
||||
test/BaseModelTest.php
|
||||
public/.htaccess
|
||||
public/index.php
|
||||
tests/BaseModelTest.php
|
||||
|
@ -27,9 +27,9 @@ Application requires at least one config file(`config/dev/config.inc.php` or `co
|
||||
|
||||
## Start devserver
|
||||
|
||||
Run the following command in terminal to start localhost web server, assuming `./php-slim-server/` is public-accessible directory with `index.php` file:
|
||||
Run the following command in terminal to start localhost web server, assuming `./php-slim-server/public/` is public-accessible directory with `index.php` file:
|
||||
```bash
|
||||
$ php -S localhost:8888 -t php-slim-server
|
||||
$ php -S localhost:8888 -t php-slim-server/public
|
||||
```
|
||||
> **Warning** This web server was designed to aid application development.
|
||||
> It may also be useful for testing purposes or for application demonstrations that are run in controlled environments.
|
||||
@ -40,7 +40,7 @@ $ php -S localhost:8888 -t php-slim-server
|
||||
### PHPUnit
|
||||
|
||||
This package uses PHPUnit 8 or 9(depends from your PHP version) for unit testing.
|
||||
[Test folder](test) contains templates which you can fill with real test assertions.
|
||||
[Test folder](tests) contains templates which you can fill with real test assertions.
|
||||
How to write tests read at [2. Writing Tests for PHPUnit - PHPUnit 8.5 Manual](https://phpunit.readthedocs.io/en/8.5/writing-tests-for-phpunit.html).
|
||||
|
||||
#### Run
|
||||
|
@ -27,7 +27,7 @@
|
||||
]}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": { "OpenAPIServer\\": "test/" }
|
||||
"psr-4": { "OpenAPIServer\\": "tests/" }
|
||||
},
|
||||
"scripts": {
|
||||
"test": [
|
||||
|
@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\BaseModel;
|
||||
|
||||
/**
|
||||
* InlineObject
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class InlineObject extends BaseModel
|
||||
{
|
||||
/**
|
||||
* @var string Models namespace.
|
||||
* Can be required for data deserialization when model contains referenced schemas.
|
||||
*/
|
||||
protected const MODELS_NAMESPACE = '\OpenAPIServer\Model';
|
||||
|
||||
/**
|
||||
* @var string Constant with OAS schema of current class.
|
||||
* Should be overwritten by inherited class.
|
||||
*/
|
||||
protected const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"name" : {
|
||||
"type" : "string",
|
||||
"description" : "Updated name of the pet"
|
||||
},
|
||||
"status" : {
|
||||
"type" : "string",
|
||||
"description" : "Updated status of the pet"
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use OpenAPIServer\BaseModel;
|
||||
|
||||
/**
|
||||
* InlineObject1
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
class InlineObject1 extends BaseModel
|
||||
{
|
||||
/**
|
||||
* @var string Models namespace.
|
||||
* Can be required for data deserialization when model contains referenced schemas.
|
||||
*/
|
||||
protected const MODELS_NAMESPACE = '\OpenAPIServer\Model';
|
||||
|
||||
/**
|
||||
* @var string Constant with OAS schema of current class.
|
||||
* Should be overwritten by inherited class.
|
||||
*/
|
||||
protected const MODEL_SCHEMA = <<<'SCHEMA'
|
||||
{
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"additionalMetadata" : {
|
||||
"type" : "string",
|
||||
"description" : "Additional data to pass to server"
|
||||
},
|
||||
"file" : {
|
||||
"type" : "string",
|
||||
"description" : "file to upload",
|
||||
"format" : "binary"
|
||||
}
|
||||
}
|
||||
}
|
||||
SCHEMA;
|
||||
}
|
@ -12,11 +12,11 @@
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Apis">
|
||||
<directory>./test/Api</directory>
|
||||
<directory>./tests/Api</directory>
|
||||
</testsuite>
|
||||
<testsuite name="Models">
|
||||
<file>./test/BaseModelTest.php</file>
|
||||
<directory>./test/Model</directory>
|
||||
<file>./tests/BaseModelTest.php</file>
|
||||
<directory>./tests/Model</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
|
@ -20,7 +20,7 @@
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use OpenAPIServer\SlimRouter;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
@ -29,9 +29,9 @@ use OpenAPIServer\Mock\OpenApiDataMocker;
|
||||
|
||||
// load config file
|
||||
$config = [];
|
||||
if (is_array($prodConfig = @include(__DIR__ . '/config/prod/config.inc.php'))) {
|
||||
if (is_array($prodConfig = @include(__DIR__ . '/../config/prod/config.inc.php'))) {
|
||||
$config = $prodConfig;
|
||||
} elseif (is_array($devConfig = @include(__DIR__ . '/config/dev/config.inc.php'))) {
|
||||
} elseif (is_array($devConfig = @include(__DIR__ . '/../config/dev/config.inc.php'))) {
|
||||
$config = $devConfig;
|
||||
} else {
|
||||
throw new InvalidArgumentException('Config file missed or broken.');
|
@ -1,114 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Please update the test case below to test the model.
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use OpenAPIServer\Model\InlineObject1;
|
||||
|
||||
/**
|
||||
* InlineObject1Test Class Doc Comment
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*
|
||||
* @coversDefaultClass \OpenAPIServer\Model\InlineObject1
|
||||
*/
|
||||
class InlineObject1Test extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Setup before running any test cases
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup before running each test case
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up after running each test case
|
||||
*/
|
||||
public function tearDown(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up after running all test cases
|
||||
*/
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test "InlineObject1"
|
||||
*/
|
||||
public function testInlineObject1()
|
||||
{
|
||||
$testInlineObject1 = new InlineObject1();
|
||||
$namespacedClassname = InlineObject1::getModelsNamespace() . '\\InlineObject1';
|
||||
$this->assertSame('\\' . InlineObject1::class, $namespacedClassname);
|
||||
$this->assertTrue(
|
||||
class_exists($namespacedClassname),
|
||||
sprintf('Assertion failed that "%s" class exists', $namespacedClassname)
|
||||
);
|
||||
$this->markTestIncomplete(
|
||||
'Test of "InlineObject1" model has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test attribute "additionalMetadata"
|
||||
*/
|
||||
public function testPropertyAdditionalMetadata()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'Test of "additionalMetadata" property in "InlineObject1" model has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test attribute "file"
|
||||
*/
|
||||
public function testPropertyFile()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'Test of "file" property in "InlineObject1" model has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getOpenApiSchema static method
|
||||
* @covers ::getOpenApiSchema
|
||||
*/
|
||||
public function testGetOpenApiSchema()
|
||||
{
|
||||
$schemaArr = InlineObject1::getOpenApiSchema();
|
||||
$this->assertIsArray($schemaArr);
|
||||
}
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* PHP version 7.2
|
||||
*
|
||||
* @package OpenAPIServer
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
* Generated by: https://github.com/openapitools/openapi-generator.git
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: This class is auto generated by the openapi generator program.
|
||||
* https://github.com/openapitools/openapi-generator
|
||||
* Please update the test case below to test the model.
|
||||
*/
|
||||
namespace OpenAPIServer\Model;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use OpenAPIServer\Model\InlineObject;
|
||||
|
||||
/**
|
||||
* InlineObjectTest Class Doc Comment
|
||||
*
|
||||
* @package OpenAPIServer\Model
|
||||
* @author OpenAPI Generator team
|
||||
* @link https://github.com/openapitools/openapi-generator
|
||||
*
|
||||
* @coversDefaultClass \OpenAPIServer\Model\InlineObject
|
||||
*/
|
||||
class InlineObjectTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Setup before running any test cases
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup before running each test case
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up after running each test case
|
||||
*/
|
||||
public function tearDown(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up after running all test cases
|
||||
*/
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test "InlineObject"
|
||||
*/
|
||||
public function testInlineObject()
|
||||
{
|
||||
$testInlineObject = new InlineObject();
|
||||
$namespacedClassname = InlineObject::getModelsNamespace() . '\\InlineObject';
|
||||
$this->assertSame('\\' . InlineObject::class, $namespacedClassname);
|
||||
$this->assertTrue(
|
||||
class_exists($namespacedClassname),
|
||||
sprintf('Assertion failed that "%s" class exists', $namespacedClassname)
|
||||
);
|
||||
$this->markTestIncomplete(
|
||||
'Test of "InlineObject" model has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test attribute "name"
|
||||
*/
|
||||
public function testPropertyName()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'Test of "name" property in "InlineObject" model has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test attribute "status"
|
||||
*/
|
||||
public function testPropertyStatus()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'Test of "status" property in "InlineObject" model has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getOpenApiSchema static method
|
||||
* @covers ::getOpenApiSchema
|
||||
*/
|
||||
public function testGetOpenApiSchema()
|
||||
{
|
||||
$schemaArr = InlineObject::getOpenApiSchema();
|
||||
$this->assertIsArray($schemaArr);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user