l0wskilled/api-platform-test
Composer 安装命令:
composer require l0wskilled/api-platform-test
包简介
Bundle to ease the test of Endpoints generated by ApiPlatform.
README 文档
README
Bundle to ease the test of Endpoints generated by ApiPlatform.
You may want to have a look at: https://github.com/epubli/api-platform-traits
Usage
If you want a simple CRUD Testing for your entity just extend the ApiPlatformTestCase and override the endpoint and the resource class
/** Endpoint to test (override in your testcase) */ protected const RESOURCE_URI = '/'; /** Entity class to test (override in your testcase) */ protected const RESOURCE_CLASS = '';
ORM only
Since v0.3.0 we only support ORM.
ORM Example Test class
class ExampleTest extends ApiPlatformTestCase { protected const RESOURCE_URI = '/api/example/'; protected const RESOURCE_CLASS = Example::class; protected function getTestEntity(): Example { $example = new Example(); $example->setLocale(static::$faker->countryCode()); $example->setStandard(false); $example->setTitle(static::$faker->country()); return $example; } }
With this setup common CRUD-Tests will be executed.
If you want to adjust the behaviour of some Test-Cases just override the default Test-Case
For e.g.
public function testReadAResourceCollection(): void { parent::testReadAResourceCollection(); $this->assertCollectionCount(3); } public function testReadAResource(): void { parent::testReadAResource(); $this->assertResourcePropertyCount(10); }
During the testing the entities get serialized by the symfony serializer. This can serialize attributes you don't want to compare, especially if you have circular references.
For this case you can provide a list of ignored attributes. These will be skipped during serialization.
protected function getIgnoredAttributes(): array { return ['children']; }
If you do not have all CRUD Operations available you can override the unsupported test with a route not available test to ensure this.
public function testCreateAResource(): void { $this->testThrowErrorWhenRouteIsForbidden(); parent::testCreateAResource(); }
统计信息
- 总下载量: 1.6k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-11-20