2
當試圖運行任何測試,我得到以下錯誤:Codeception例外:json_encode():類型不受支持
json_encode():類型不受支持,編碼爲空
我使用的是2.0版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
向我們展示您的測試用例代碼 – Unnawut
感謝@Unnawut,添加了測試代碼。 – Adamski
你確定你需要'$ I-> haveHttpHeader('Content-Type','application/x-www-form-urlencoded');'?也許嘗試刪除該行。國際海事組織,做一個簡單的'GET'不應該需要,它可能會影響你的代碼是如何編碼/解碼JSON數據。 – Unnawut