我在symfony2中运行phpunit,并且看到每个日志条目输出到stdout。
我已从所有config.yml文件中删除了所有monolog处理程序和其他配置条目,因此假设它是symfony-phpunit网桥的默认设置或其他内容。
这是我的phpunit.xml.dist:
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://phpunit.de/manual/4.1/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="app/autoload.php"
>
<php>
<ini name="error_reporting" value="-1" />
</php>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<php>
<server name="KERNEL_DIR" value="app/" />
</php>
<listeners>
<listener class="\Mockery\Adapter\Phpunit\TestListener"
file="Mockery/Adapter/Phpunit/TestListener.php">
</listener>
</listeners>
<filter>
<whitelist>
<directory>src</directory>
<exclude>
<directory>src/*Bundle/Resources</directory>
<directory>src/*/*Bundle/Resources</directory>
<directory>src/*/Bundle/*Bundle/Resources</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
有关删除此输出的任何想法?
ETA,测试使用实例化的monolog实例,如下所示:
/**
* @return Logger
*/
protected function getLogger() {
$logger = new Logger('test');
$logger->pushHandler(new DebugHandler);
return $logger;
}
(删除debugHandler无效)。
它的行为类似于有一个输出到stdout的处理程序,但事实并非如此。以下是我运行phpunit时的一些输出:
Matthews-iMac:api matt$ phpunit ./tests/ONC/Test/Partridge/Import/Importer/ImportStaticTest.php
PHPUnit 5.2.1 by Sebastian Bergmann and contributors.
E..[2016-03-31 12:37:27] test.DEBUG: [PARSE] Could not parse data String could not be parsed as XML <oxip version="7.1" created="2016-02-20 12:05:53" lastMsgId="" requestTime="0.0584"> <response request="getCategories" code="001" message="success" debug="" provider="GENERIC"> <disclaimer></disclaimer> <category id="16" displayOrder="-788" name="Football" category="FOOTBALL"/ <category id="34" displayOrder="-777" name="Tennis" category="TENNIS"/> <category id="23" displayOrder="230" name="Motor Bikes" category="MOTOR_BIKES"/> <category id="36" displayOrder="360" name="Volleyball" category="VOLLEYBALL"/> </responseBROKEN> </oxip> [] []
.[2016-03-31 12:37:27] test.ERROR: [MAPPING] Could not map parsed response to stdClass | feed: CORAL_OPENBET, domain: ONC\Partridge\Entity\Category1, current key with cast: category, current key without cast: category, current result: array ( 'id' => '16', 'displayOrder' => '-788', 'name' => 'Football', 'categoryBELL' => 'FOOTBALL', ), mappings: array ( 'name' => 'name', 'category' => 'canonicalised_name', '(int)displayOrder' => 'display_order', ), Request: http://xmlfeeds.coral.co.uk/oxi/pub?template=getCategories [] []
答案 0 :(得分:1)
您可以使用带有虚拟回调的setOutputCallback
方法在测试用例中将stdout抑制到控制台。例如:
public function testDlRegisteredUserWithoutPointAction()
{
// Suppress StreamedResponse output to console
$this->setOutputCallback(function() {});
....
}
Here更多文档。
希望这个帮助
答案 1 :(得分:0)
虚假警报,它是我自己制作的独白实例,而不是symfony管理的实例。咄