尝试运行任何测试时,我收到以下错误:
json_encode():type不受支持,编码为null
我正在使用v 2.0.1
测试代码:
$I = new ApiTester($scenario);
$I->wantTo('get a list of all users');
$I->haveHttpHeader('Content-Type','application/x-www-form-urlencoded');
$I->sendGET('users'); // <-- error happens here
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContains('{ result: ok}');
以下示例输出:
Trying to get a list of all users (GetUsersCept) Scenario
I have http header "Content-Type","application/x-www-form-urlencoded"
I send get "users"
[Request] GET http://api.myapp.com/users
ERROR
[ErrorException]
json_encode(): type is unsupported, encoded as null
Exception trace: () at /app-dir/vendor/phpunit/phpunit/src/Util/Log/JSON.php:280
Codeception\Subscriber\ErrorHandler->errorHandler() at n/a:n/a json_encode() at /app-dir/vendor/phpunit/phpunit/src/Util/Log/JSON.php:280
PHPUnit_Util_Log_JSON->write() at /app-dir/vendor/phpunit/phpunit/src/Util/Log/JSON.php:266
PHPUnit_Util_Log_JSON->writeCase() at /app-dir/vendor/phpunit/phpunit/src/Util/Log/JSON.php:94
PHPUnit_Util_Log_JSON->addError() at /app-dir/vendor/phpunit/phpunit/src/Framework/TestResult.php:275
PHPUnit_Framework_TestResult->addError() at /app-dir/vendor/phpunit/phpunit/src/Framework/TestResult.php:760
PHPUnit_Framework_TestResult->run() at /app-dir/vendor/phpunit/phpunit/src/Framework/TestCase.php:753
PHPUnit_Framework_TestCase->run() at /app-dir/vendor/phpunit/phpunit/src/Framework/TestSuite.php:675
PHPUnit_Framework_TestSuite->run() at /app-dir/vendor/codeception/codeception/src/Codeception/PHPUnit/Runner.php:100
Codeception\PHPUnit\Runner->doEnhancedRun() at /app-dir/vendor/codeception/codeception/src/Codeception/SuiteManager.php:153
Codeception\SuiteManager->run() at /app-dir/vendor/codeception/codeception/src/Codeception/Codecept.php:167
Codeception\Codecept->runSuite() at /app-dir/vendor/codeception/codeception/src/Codeception/Codecept.php:150
Codeception\Codecept->run() at /app-dir/vendor/codeception/codeception/src/Codeception/Command/Run.php:198
Codeception\Command\Run->runSuites() at /app-dir/vendor/codeception/codeception/src/Codeception/Command/Run.php:149
Codeception\Command\Run->execute() at /app-dir/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:252
Symfony\Component\Console\Command\Command->run() at /app-dir/vendor/symfony/console/Symfony/Component/Console/Application.php:887
Symfony\Component\Console\Application->doRunCommand() at /app-dir/vendor/symfony/console/Symfony/Component/Console/Application.php:193
Symfony\Component\Console\Application->doRun() at /app-dir/vendor/symfony/console/Symfony/Component/Console/Application.php:124
Symfony\Component\Console\Application->run() at /app-dir/vendor/codeception/codeception/codecept:27
我还得到了Laravel默认欢迎页面的简单验收测试错误:
$I = new AcceptanceTester($scenario);
$I->wantTo('see the Laravel welcome page');
$I->amOnPage('/');
$I->shouldSee('You have arrived.');
Acceptance Tests (1) ---------------------------------------------------------------------------------------------------------------
Modules: PhpBrowser, AcceptanceHelper
------------------------------------------------------------------------------------------------------------------------------------
Trying to see the Laravel welcome page (HomeTestCept)
Scenario:
* I am on page "/"
ERROR
[ErrorException]
json_encode(): type is unsupported, encoded as null
答案 0 :(得分:0)
原来这个问题是时区没有在php.ini中设置。我将相关的行添加到/etc/php.ini中,现在可以使用了。
示例/etc/php.ini:(PHP 5.4.19)
date.timezone = "Europe/London"
error_reporting = E_ALL
display_errors = On
html_errors = On
zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so
extension=mcrypt.so
有关详细信息,请参阅https://github.com/Codeception/Codeception/issues/1165。