php - Symfony 单元测试
问题描述
以下是我的目录结构:
|-vendor
|---bin
|---phpunit
|---autoload.php
|---psr
|---sebastian
|---phar-io
|---composer
|---symfony
|-.htaccess
|-composer.lock
|-includes
|---application_top.php
|-routes
|---routes.php
|-modules
|---Controllers
|----CheckoutGatewayController.php
|-tests
|---Controllers
|----tests_common_includes.php
|-composer.phar
我正在尝试./vendor/bin/simple-phpunit --bootstrap tests/tests_common_includes.php tests/Controllers/CheckoutGatewayTests.php
从我的基本目录运行,但它给了我错误Class 'tests/Controllers/CheckoutGatewayTests' could not be found in 'tests/Controllers/CheckoutGatewayTests.php'.
如果我尝试./vendor/bin/phpunit --bootstrap tests/tests_common_includes.php tests/Controllers/CheckoutGatewayTests.php
然后我得到错误Unable to guess the Kernel directory
。我试图查找 symfony 的文档:它建议使用-c app
选项或更改phpunit.dist.xml
文件。但我的目录中没有这些。没有 xml 文件,也没有 app 文件夹。
如何执行我的测试?我的测试文件CheckoutGatewayTests.php
如下所示:
<?php
use \Controllers\CheckoutGatewayController;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class CheckoutGatewayTests extends WebTestCase {
public function testChargebackCallback() {
$client = static::createClient();
$client->request('GET', '/post/hello-world');
}
}
编辑:我的 composer.json 文件
{
"require": {
"guzzlehttp/guzzle": "~6.0",
"psr/log": "^1.0",
"zircote/swagger-php": "^2.0",
"sentry/sentry": "^1.8",
"aws/aws-sdk-php": "^3.52",
"league/flysystem-aws-s3-v3": "~1.0",
"symfony/routing": "^3.4",
"symfony/http-kernel": "^3.4",
"symfony/dependency-injection": "^3.4",
"symfony/framework-bundle": "^3.4",
"prbdias/mbway-php": "0.1"
},
"require-dev": {
"phpunit/phpunit": "^6"
},
"config": {
"optimize-autoloader": true
},
"autoload": {
"psr-4": {
"": ["modules/", "tests/","routes/"]
}
}
}
解决方案
推荐阅读
- r - R中的异常处理-下载正确的数据时返回
- php - 我无法将 data_type 从 TINYTEXT 更改为 DATE&/DATETIME
- reactjs - 如何使用钩子将对象数组推入状态
- react-native - 在 Parent 中传递两个函数
- mysql - MySQL - 选择具有字段值 > 10 且不按此字段排序的第一行的查询
- python - 如何使用蓝牙将数据从 Android/iOS 应用程序发送到在树莓派上运行的 python 脚本?
- bluetooth - 我可以使用蓝牙 4.0 设备知道蓝牙 5.1 信标的位置吗?
- graphql - 在 GraphQL 中,您可以更改别名中的输出结构吗?
- docker - 如何在 docker-compose 中使用 docker 容器选项
- reactjs - 蚂蚁设计
创建表单的静态数组