Silex phpunit不匹配路由

Silex phpunit不匹配路由,phpunit,silex,Phpunit,Silex,我正试图为我的Silex应用程序编写一些测试,但遇到了一个问题 我有以下phpunit.xml文件 <?xml version="1.0" encoding="UTF-8"?> <phpunit bootstrap="./bootstrap.php" backupGlobals="false" backupStaticAttributes="false" colors="true" convertErrorsToExcepti

我正试图为我的Silex应用程序编写一些测试,但遇到了一个问题

我有以下phpunit.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<phpunit 
     bootstrap="./bootstrap.php"
     backupGlobals="false"
     backupStaticAttributes="false"
     colors="true"
     convertErrorsToExceptions="true"
     convertNoticesToExceptions="true"
     convertWarningsToExceptions="true"
     processIsolation="false"
     stopOnFailure="false"
     syntaxCheck="false"
>
    <testsuites>
        <testsuite name="Management Test Suite">
            <directory>./</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist>
            <directory>../src/</directory>
        </whitelist>
    </filter>
</phpunit>
我写测试的方式是否有明显的问题


干杯

我遇到了同样的问题。我所要做的(尽管我不喜欢这个解决方案)就是使用
require
include
而不是
require\u once
include\u once

路线/包裹/搜索的代码在哪里你考虑过使用Behat吗?你有没有想过这个问题?遇到同样的问题。如果项目中有
包含一次
要求一次
删除
\u一次
!PHPunit不喜欢包含一次或要求一次@我怀疑我也有同样的问题,在我读到你的评论之前无法修复它!这应该是我所接受的答案!
<?php

use Symfony\Component\HttpKernel\Client;

function getJSONResponse($app, Client $client, $url, $params = array())
{
    $params['test_key'] = $app['test_key'];
    $client->request('GET', $url, $params);
    $response = $client->getResponse();
    $data = json_decode($response->getContent(), true);
    return $data;
}
<?php

require_once $_SERVER['frog_docroot'] . '/www/vendor/autoload.php';

class DefaultTest extends Silex\WebTestCase
{
    public function createApplication()
    {
        return require $_SERVER['frog_docroot'] . '/www/src/app.php';
    }

    public function testInvalidUrlThrowsException()
    {
        $client = $this->createClient();
        $data = getJSONResponse($this->app, $client, '/some/url/that/does/not/exist');
        $this->assertContains('No route found for "GET /some/url/that/does/not/exist"', $data['message']);
    }
}
<?php

require_once $_SERVER['frog_docroot'] . '/www/vendor/autoload.php';

class AnotherTest extends Silex\WebTestCase
{
    public function createApplication()
    {
        return require $_SERVER['frog_docroot'] . '/www/src/app.php';
    }

    public function testSearchReturnsResults()
    {
        $client = $this->createClient();
        $data = getJSONResponse($this->app, $client, '/packages/search', array(
            'search' => 'something',
            'offset' => 0,
            'limit' => 10,
        ));

        $this->assertSame(array(
            'data' => array(
                '1' => 'Some Package',
            ),
            'offset' => 0,
            'limit' => 10,
        ), $data);
    }
}
There was 1 failure:

1) AnotherTest::testSearchReturnsResults
Failed asserting that Array (
    'message' => 'No route found for "GET /packages/search"'
    'code' => 0
) is identical to Array (
    'data' => Array (
        '1' => 'Some Package'
    )
    'offset' => 0
    'limit' => 10
    'more' => false
).