我只是尝试运行一个简单的功能测试,但是代码测试未通过测试,说http代码为500.
我是php,wordpress和codeception的新手。试图看看为什么500代码,但看起来像我的localhost apache服务器没有收到请求。不确定为什么codeception将其视为500响应代码。
下面是我的简单测试。
<?php
namespace Tests\Functional;
class AddRequestCest {
/**
* It should store last operation result
* @test
*
*
*/
public function return_the_correct_result( \FunctionalTester $I) {
// $I->amOnPage( "/wp-json/calc/add/{$first}/{$second}" );
$I->amOnPage( "/" );
$I->seeResponseCodeIs( 200 );
$I->seeOptionInDatabase( [ 'option_name' => '_transient_last_operation' ] );
}
}
失败是
Functional Tests (1) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Modules: \Helper\Functional, Filesystem, WPDb, WordPress, WPLoader
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
AddRequestCest: Return_the_correct_result | 5,4
Signature: Tests\Functional\AddRequestCest:return_the_correct_result
Test: tests/functional/AddRequestCest.php:return_the_correct_result
Scenario --
I am on page "/"
[Cookie Jar] ["wordpress_test_cookie=WP+Cookie+check; path=/; httponly"]
[Request Headers] []
[Page] /
[Response] 500
[Request Cookies] {"wordpress_test_cookie":"WP Cookie check"}
[Response Headers] {"Content-type":"text/html; charset=UTF-8","Set-Cookie":["wordpress_test_cookie=WP Cookie check"]}
I see response code is 200
FAIL
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Time: 1.62 seconds, Memory: 30.00MB
There was 1 failure:
---------
1) AddRequestCest: Return_the_correct_result | 5,4
Test tests/functional/AddRequestCest.php:return_the_correct_result
Step See response code is 200
Fail Expected HTTP Status Code: 200 (OK). Actual Status Code: 500 (Internal Server Error)
Failed asserting that 500 matches expected 200.
Scenario Steps:
2. $I->seeResponseCodeIs(200) at tests/functional/AddRequestCest.php:18
1. $I->amOnPage("/") at tests/functional/AddRequestCest.php:16
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
functional.yml文件
# Codeception Test Suite Configuration
# Suite for WordPress functional tests.
# Emulate web requests and make the WordPress application process them.
class_name: FunctionalTester
modules:
enabled:
- \Helper\Functional
- Filesystem
- WPDb
- WordPress
- WPLoader
config:
WPDb:
dsn: 'mysql:host=127.0.0.1;dbname=wpTests'
user: 'root'
password: 'root'
dump: 'tests/_data/dump.sql'
populate: true
cleanup: true
url: 'http://localhost/wordpress'
urlReplacement: true
tablePrefix: 'wp_'
WordPress:
depends: WPDb
wpRootFolder: '/Applications/MAMP/htdocs/wordpress'
adminUsername: 'admin'
adminPassword: 'admin'
adminPath: '/wp-admin'
WPLoader:
loadOnly: true
wpRootFolder: "/Applications/MAMP/htdocs/wordpress"
dbName: "wpTests"
dbHost: "127.0.0.1"
dbUser: "root"
dbPassword: "root"
title: "HelloWorld"
plugins: ['rest-calculator/rest-calculator.php']
activatePlugins: ['rest-calculator/rest-calculator.php']