Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Invalid UTF-8 data in data provider triggers PHP warnings in JSON logger #362

Closed
ezzatron opened this Issue Oct 2, 2011 · 0 comments

Comments

Projects
None yet
2 participants

ezzatron commented Oct 2, 2011

If you have JSON logging active, and a test like so:

<?php

class UTF8LoggingTest extends PHPUnit_Framework_TestCase {

  public function UTF8Data() {
    return array(array(chr(128)));
  }

  /**
   * @dataProvider UTF8Data
   */
  public function testUTF8Logging($value) {
    $this->assertTrue(true);
  }

}

It will produce the following output:

PHPUnit 3.5.15 by Sebastian Bergmann.

PHP Warning:  json_encode(): Invalid UTF-8 sequence in argument in /usr/share/php/PHPUnit/Util/Log/JSON.php on line 238
PHP Stack trace:
PHP   1. {main}() /usr/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:49
PHP   3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:129
PHP   4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:188
PHP   5. PHPUnit_Framework_TestSuite->run() /usr/share/php/PHPUnit/TextUI/TestRunner.php:305
PHP   6. PHPUnit_Framework_TestSuite->run() /usr/share/php/PHPUnit/Framework/TestSuite.php:693
PHP   7. PHPUnit_Framework_TestSuite->runTest() /usr/share/php/PHPUnit/Framework/TestSuite.php:733
PHP   8. PHPUnit_Framework_TestCase->run() /usr/share/php/PHPUnit/Framework/TestSuite.php:757
PHP   9. PHPUnit_Framework_TestResult->run() /usr/share/php/PHPUnit/Framework/TestCase.php:576
PHP  10. PHPUnit_Framework_TestResult->startTest() /usr/share/php/PHPUnit/Framework/TestResult.php:632
PHP  11. PHPUnit_Util_Log_JSON->startTest() /usr/share/php/PHPUnit/Framework/TestResult.php:381
PHP  12. PHPUnit_Util_Log_JSON->write() /usr/share/php/PHPUnit/Util/Log/JSON.php:196
PHP  13. json_encode() /usr/share/php/PHPUnit/Util/Log/JSON.php:238
.PHP Warning:  json_encode(): Invalid UTF-8 sequence in argument in /usr/share/php/PHPUnit/Util/Log/JSON.php on line 238
PHP Stack trace:
PHP   1. {main}() /usr/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:49
PHP   3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:129
PHP   4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:188
PHP   5. PHPUnit_Framework_TestSuite->run() /usr/share/php/PHPUnit/TextUI/TestRunner.php:305
PHP   6. PHPUnit_Framework_TestSuite->run() /usr/share/php/PHPUnit/Framework/TestSuite.php:693
PHP   7. PHPUnit_Framework_TestSuite->runTest() /usr/share/php/PHPUnit/Framework/TestSuite.php:733
PHP   8. PHPUnit_Framework_TestCase->run() /usr/share/php/PHPUnit/Framework/TestSuite.php:757
PHP   9. PHPUnit_Framework_TestResult->run() /usr/share/php/PHPUnit/Framework/TestCase.php:576
PHP  10. PHPUnit_Framework_TestResult->endTest() /usr/share/php/PHPUnit/Framework/TestResult.php:734
PHP  11. PHPUnit_Util_Log_JSON->endTest() /usr/share/php/PHPUnit/Framework/TestResult.php:394
PHP  12. PHPUnit_Util_Log_JSON->writeCase() /usr/share/php/PHPUnit/Util/Log/JSON.php:208
PHP  13. PHPUnit_Util_Log_JSON->write() /usr/share/php/PHPUnit/Util/Log/JSON.php:230
PHP  14. json_encode() /usr/share/php/PHPUnit/Util/Log/JSON.php:238


Time: 0 seconds, Memory: 5.75Mb

OK (1 test, 1 assertion)

@greglamb greglamb pushed a commit to greglamb/phpunit that referenced this issue Apr 19, 2013

@sebastianbergmann sebastianbergmann Closes issue #362. 013ab3c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment