Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

戻り値の型宣言でnullable な型を渡すことが出来なくなっている #44

Closed
mstysk opened this issue Feb 21, 2023 · 2 comments · Fixed by #45
Closed

Comments

@mstysk
Copy link
Contributor

mstysk commented Feb 21, 2023

Bug Report

戻り値の型宣言でnullable な型を渡すことが出来なくなっている

How to reproduce

テストコードの TotoEntityInterface::getItem の返り値を nullable にすると再現します。

  • Ray.MediaQuery: 0.10.0
  • PHP: 8.1.14
Ray.MediaQuery on  HEAD (ef3dda2) via 🐘 v8.1.14
❯ git diff
error: cannot run delta: No such file or directory
diff --git a/tests/Fake/Queries/TodoEntityInterface.php b/tests/Fake/Queries/TodoEntityInterface.php
index 23a5bf3..1f5e349 100644
--- a/tests/Fake/Queries/TodoEntityInterface.php
+++ b/tests/Fake/Queries/TodoEntityInterface.php
@@ -10,7 +10,7 @@
 interface TodoEntityInterface
 {
     #[DbQuery('todo_item')]
-    public function getItem(string $id): Todo;
+    public function getItem(string $id): ?Todo;

     #[DbQuery('todo_list')]
     /**

Ray.MediaQuery on  HEAD (ef3dda2) via 🐘 v8.1.14
❯ ./vendor/bin/phpunit
PHPUnit 9.6.3 by Sebastian Bergmann and contributors.

......E.............................................              52 / 52 (100%)

Time: 00:01.916, Memory: 32.00 MB

There was 1 error:

1) Ray\MediaQuery\DbQueryModuleTest::testEntity
TypeError: Ray\MediaQuery\Queries\TodoEntityInterfaceNull_1464564696::getItem(): Return value must be of type ?Ray\MediaQuery\Entity\Todo, array returned

/pato/to/Ray.MediaQuery/tests/tmp/Ray_MediaQuery_Queries_TodoEntityInterfaceNull_1464564696.php:15
/path/to/Ray.MediaQuery/tests/DbQueryModuleTest.php:144

ERRORS!
Tests: 52, Assertions: 78, Errors: 1.
koriym added a commit that referenced this issue Feb 21, 2023
@koriym
Copy link
Member

koriym commented Feb 21, 2023

@mstysk 確認して原因究明できました。 "?Todo"をclass_exsitsして存在しないので、エンティティではなくarrayを返してエラーになっていました。

@koriym
Copy link
Member

koriym commented Feb 21, 2023

@mstysk 報告ありがとうございました! #45 で修正予定です!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants