everycheck / test-api-rest-bundle
此包已被废弃且不再维护。未建议替代包。
允许您轻松测试 REST API
1.4.0
2022-01-20 15:12 UTC
Requires
- coduo/php-matcher: ^3.0
- jms/serializer-bundle: ^1.0|^2.0
- phpunit/phpunit: ^6.0|^7.0
- symfony/phpunit-bridge: ^3.0
Requires (Dev)
- doctrine/doctrine-bundle: ^1.11
- doctrine/orm: ^2.6
- guzzlehttp/guzzle: ^6.3
- ramsey/uuid-doctrine: ^1.5
- sensio/distribution-bundle: ^5.0
- sensio/framework-extra-bundle: ^5.0.0
- symfony/monolog-bundle: ^3.1
- symfony/polyfill-apcu: ^1.0
- symfony/swiftmailer-bundle: ^3.2
- symfony/symfony: 3.4.*
- symfony/web-server-bundle: ^3.4
This package is auto-updated.
Last update: 2022-10-30 20:38:45 UTC
README
关于
TestApiRestBundle 允许您深入测试您的 Symfony REST API。它通过 PHPUnit 和单元、场景和数据库测试来检查您应用程序的有效性,并确保其在整个时间段内保持健壮。
目录
安装
您可以使用 composer 安装,假设它已全局安装
composer require --dev everycheck\test-api-rest-bundle
配置
配置包含您在测试中要发送的请求数据负载及其预期响应的目录的相对路径。路径来自 AcmeBundle\tests\AcmeBundle。
test_api_rest: directory: payloads: path/to/payloads responses: path/to/responses
因此,这里的目录真实路径是
AcmeBundle\tests\AcmeBundle\path\to\payloads AcmeBundle\tests\AcmeBundle\path\to\responses
用法
高级用法
测试文件夹结构
要测试您的其中一个包,只需复制该包的结构,并按照以下结构添加一些目录
.
├── tests # The basic Symfony test directory
│ ├── AcmeFooBundle # Name of your bundle
│ │ ├── Controller
│ │ │ ├── FooControllerTest.php # Controller your want to test
│ │ │ └── ...
│ │ │
│ │ ├── DataFixtures
│ │ │ └── ORM
│ │ │ ├─ LoadAcmeFooFixtures.php # Fixtures dedicated to one controller
| | | └── ...
│ │ │
│ │ ├── Payloads
│ │ │ └── ... # File posted to your API
│ │ │
│ │ ├── Resources
│ │ │ └── config
│ │ │ ├── foo.yaml # All the tests for a specific controller, set as a YAML file
│ │ │ └── ...
│ │ │
│ │ └── Responses # All the expected responses coming from the endpoints of your API when testing it
│ │ └── Expected
│ │ └── ...
│ └──
└──
启动测试
以下是在测试包时需要执行的命令
composer install
./Tests/sampleProject/app/console d:d:d --force
./Tests/sampleProject/app/console d:d:c
./Tests/sampleProject/app/console d:s:c
./Tests/sampleProject/app/console s:start --docroot=./Tests/sampleProject/public
php ./Tests/sampleProject/tests/DemoBundle/DataFixtures/LoadDemoFixture.php localhost:portYouAreListening "[debug]"
php ./Tests/sampleProject/tests/PatternBundle/DataFixtures/LoadPatternFixture.php localhost:portYouAreListening "[debug]"
./Tests/sampleProject/app/console s:stop
./vendor/bin/phpunit