質問

I am developing a web app with Symfony2. My application connects to some external services, which I mocked using Ruby. This is a snippet of my ruby mock

#Bunch of stuff...

after do
    response['Content-type'] = 'application/json'
end

#Bunch of stuff...

get '/configure/set_result' do

    #Bunch of stuff...
    JSON.generate 'success' => true,
        "message" => "whatever"
end

In one of the functional tests I am doing I call this method

<?php

class MyControllerTest extends WebTestCase {

    protected function setUp() {
        $this->client = static::createClient();
    }


    public function testWhatever() {

        $this->callMyMock(22);

        //Unimportant stuff

    }

    private function callMyMock($result) {

        $crawler = $this->client->request('GET', "http://localhost:5995/configure/set_result?resultCode=$result");
    }
}

The problem is that in the log I get a lot of PHP warning (that actually slow down PHPUnit quite a lot. This is an example of the output:

WebApp.PHPUnitTests:
     [exec] PHPUnit 3.7.19 by Sebastian Bergmann.
     [exec]
     [exec] Configuration read from C:\Work\New Products Trunk\Software\WebApp\symfony2\app\phpunit.xml.dist
     [exec]
     [exec] PHP Warning:  Unexpected character in input:  '→' (ASCII=26) state=0 in C:\Work\New Products Trunk\Soft
endor\symfony\symfony\src\Symfony\Bridge\Twig\Extension\CodeExtension.php on line 140
     [exec] PHP Stack trace:
     [exec] PHP   1. {main}() C:\_Wallet\phpunit.phar:0
     [exec] PHP   2. PHPUnit_TextUI_Command::main() C:\_Wallet\phpunit.phar:527
     [exec] PHP   3. PHPUnit_TextUI_Command->run() phar://C:/_Wallet/phpunit.phar/PHPUnit/TextUI/Command.php:129
...
...
...
...

What am I doing wrong?

役に立ちましたか?

解決

This is a known bug when running from .phar files, because in this case the function that does "highlighting" does not get a filename, but the content of the phar, hence the unexpected input.

Some background: your test may be triggering an exception which gets handled by internal symfony ErrorHandler which displays nicely formatted stack traces, this formatting is what triggers this warning.

It has been fixed in this PR: https://github.com/symfony/symfony/pull/8721/files

And details are in this Issue: https://github.com/symfony/symfony/issues/7798

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top