TestModule
in Module/
directory and bind it. This is the example.test
context. Then use that context test-app
.test-app
means TestModule
override AppModule
bindings.
prod-html-app
menas ProdModule
(in BEAR module) override HtmlModile
which override AppModule
.
TestModule
for only one-time mock binding, This is the great way.
$_SEESION
or static call all around against code style guide, You need to refactor it for mocking. - -- this is not great.
AppInjector
.
AppInjector
is the Swiss army knife in a BEAR.Sunday application testing. You can fetch any objects through interface with fake object by customized context. Very powerful.
ysato:MyVendor.Ticket ysato$ php bin/app.php post '/tickets?title=run'
PHP Notice: Undefined property: stdClass::$ticket in /Users/ysato/PhpStormProjects/MyVendor.Ticket/vendor/bear/resource/src/JsonSchema/Interceptor/JsonSchemaInterceptor.php on line 114
Notice: Undefined property: stdClass::$ticket in /Users/ysato/PhpStormProjects/MyVendor.Ticket/vendor/bear/resource/src/JsonSchema/Interceptor/JsonSchemaInterceptor.php on line 114
503 Service Unavailable
content-type: application/vnd.error+json
{
"message": "Service Unavailable",
"logref": "f52d88ce",
"request": "post app://self/tickets?title=run",
"exceptions": "BEAR\\Package\\Exception\\LocationHeaderRequestException(app://self/ticket?id=c642f957-908c-4584-9d6f-191587e522e7)",
"file": "/Users/ysato/PhpStormProjects/MyVendor.Ticket/vendor/bear/package/src/Provide/Representation/CreatedResourceRenderer.php(49)"
}
@koriym
チュートリアル1において、こちらの環境で起きたエラーやドキュメントと異なる動作になっていた箇所を記載します。
https://github.com/bearsunday/bearsunday.github.io/blame/master/manuals/1.0/ja/tutorial.md#L70
期待する結果
200 OK
Content-Type: application/hal+json
{
"weekday": "Mon",
"_links": {
"self": {
"href": "/weekday?year=2001&month=1&day=1"
}
}
}
実際の結果
200 OK
{
"weekday": "Mon",
"_links": {
"self": {
"href": "/weekday?year=2001&month=1&day=1"
}
}
}
https://github.com/bearsunday/bearsunday.github.io/blame/master/manuals/1.0/ja/tutorial.md#L99
期待する結果
HTTP/1.1 200 OK
Host: 127.0.0.1:8080
Date: Fri, 01 Sep 2017 09:31:13 +0200
Connection: close
X-Powered-By: PHP/7.1.8
content-type: application/hal+json
{
"weekday": "Mon",
"_links": {
"self": {
"href": "/weekday/2001/1/1"
}
}
}
実際の結果
HTTP/1.1 200 OK
Host: 127.0.0.1:8080
Date: Thu, 25 Jul 2019 01:43:41 GMT
Connection: close
X-Powered-By: PHP/7.2.19
Content-type: text/html; charset=UTF-8
{
"weekday": "Mon",
"_links": {
"self": {
"href": "/weekday?year=2001&month=1&day=1"
}
}
}
https://github.com/bearsunday/bearsunday.github.io/blame/master/manuals/1.0/ja/tutorial.md#L695
期待する結果
200 OK
content-type: text/html; charset=utf-8
<!doctype html>
...
実際の結果
200 OK
<!doctype html>
...
https://github.com/bearsunday/bearsunday.github.io/blame/master/manuals/1.0/ja/tutorial.md#L939
何回かリクエストしてLast-Modifiedの日付が変わらないことを確認しましょう。
とあるが変更される
https://github.com/bearsunday/bearsunday.github.io/blame/master/manuals/1.0/ja/tutorial.md#L972
期待する結果
HTTP/1.1 204 No Content
...
実際の結果
ysato:MyVendor.Weekday ysato$ curl -i http://127.0.0.1:8081/todos -X PUT -d "id=1&todo=think"
HTTP/1.1 200 OK
Host: 127.0.0.1:8081
Date: Thu, 25 Jul 2019 06:22:23 GMT
Connection: close
X-Powered-By: PHP/7.2.19
Content-type: text/html; charset=UTF-8
<br />
<b>Fatal error</b>: Uncaught TypeError: Argument 1 passed to MyVendor\Weekday\Resource\App\Todos_lglGOJA::onGet() must be of the type integer, string given, called in /Users/ysato/PhpStormProjects/MyVendor.Weekday/vendor/bear/query-repository/src/RefreshSameCommand.php on line 40 and defined in /Users/ysato/PhpStormProjects/MyVendor.Weekday/var/tmp/hal-api-app/di/MyVendor_Weekday_Resource_App_Todos_lglGOJA.php:23
Stack trace:
#0 /Users/ysato/PhpStormProjects/MyVendor.Weekday/vendor/bear/query-repository/src/RefreshSameCommand.php(40): MyVendor\Weekday\Resource\App\Todos_lglGOJA->onGet('1')
#1 /Users/ysato/PhpStormProjects/MyVendor.Weekday/vendor/bear/query-repository/src/CommandInterceptor.php(48): BEAR\QueryRepository\RefreshSameCommand->command(NULL, Object(MyVendor\Weekday\Resource\App\Todos_lglGOJA))
#2 /Users/ysato/PhpStormProjects/MyVendor.Weekday/vendor/ray/aop/src/ReflectiveMethodInvocation.php(109): BEAR\QueryRepository\CommandInterceptor->invoke(Object(Ray\Aop\ReflectiveMethodInvocation))
#3 /Users/ysato/PhpStormProjec in <b>/Users/ysato/PhpStormProjects/MyVendor.Weekday/var/tmp/hal-api-app/di/MyVendor_Weekday_Resource_App_Todos_lglGOJA.php</b> on line <b>23</b><br />
@koriym
チュートリアルを実施する中で気付いた点を2つPR提出しました。
お手空きの時に確認お願いします!