everycheck/test-api-rest-bundle

此包已被废弃且不再维护。未建议替代包。

允许您轻松测试 REST API

安装: 962

依赖: 1

建议者: 0

安全: 0

星标: 0

关注者: 3

分支: 4

开放问题: 3

类型:symfony-bundle


README

Build Status

关于

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