首页 > 解决方案 > 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/"]
            }
        }

    }

标签: phpsymfonyphpunit

解决方案


推荐阅读