|
| 1 | +Feature: Exception |
| 2 | + |
| 3 | + Background: |
| 4 | + Given I have the following config |
| 5 | + """ |
| 6 | + <?xml version="1.0"?> |
| 7 | + <psalm totallyTyped="true"> |
| 8 | + <projectFiles> |
| 9 | + <directory name="."/> |
| 10 | + <ignoreFiles> <directory name="../../vendor"/> </ignoreFiles> |
| 11 | + </projectFiles> |
| 12 | + <plugins> |
| 13 | + <pluginClass class="Sfp\Psalm\PsrLogPlugin\Plugin"/> |
| 14 | + </plugins> |
| 15 | + </psalm> |
| 16 | + """ |
| 17 | + And I have the following code preamble |
| 18 | + """ |
| 19 | + <?php |
| 20 | + use Psr\Log\LoggerInterface; |
| 21 | + use Psr\Log\AbstractLogger; |
| 22 | +
|
| 23 | + /** |
| 24 | + * @psalm-suppress InvalidReturnType |
| 25 | + * @return LoggerInterface |
| 26 | + */ |
| 27 | + function impl_interface() {} |
| 28 | +
|
| 29 | + /** |
| 30 | + * @psalm-suppress InvalidReturnType |
| 31 | + * @return AbstractLogger |
| 32 | + */ |
| 33 | + function concrete_abstract() {} |
| 34 | +
|
| 35 | + """ |
| 36 | + |
| 37 | + Scenario: `exception` key is actually an Exception Object AS per LoggerInterface |
| 38 | + Given I have the following code |
| 39 | + """ |
| 40 | + impl_interface()->emergency("message", ['exception' => 'foo']); |
| 41 | + impl_interface()->alert("message", ['exception' => 'foo']); |
| 42 | + impl_interface()->critical("message", ['exception' => 'foo']); |
| 43 | + impl_interface()->error("message", ['exception' => 'foo']); |
| 44 | + impl_interface()->warning("message", ['exception' => 'foo']); |
| 45 | + impl_interface()->notice("message", ['exception' => 'foo']); |
| 46 | + impl_interface()->info("message", ['exception' => 'foo']); |
| 47 | + impl_interface()->debug("message", ['exception' => 'foo']); |
| 48 | + impl_interface()->emergency("message", ['exception' => new Error]); |
| 49 | + impl_interface()->alert("message", ['exception' => new Error]); |
| 50 | + impl_interface()->critical("message", ['exception' => new Error]); |
| 51 | + impl_interface()->error("message", ['exception' => new Error]); |
| 52 | + impl_interface()->warning("message", ['exception' => new Error]); |
| 53 | + impl_interface()->notice("message", ['exception' => new Error]); |
| 54 | + impl_interface()->info("message", ['exception' => new Error]); |
| 55 | + impl_interface()->debug("message", ['exception' => new Error]); |
| 56 | + """ |
| 57 | + When I run Psalm |
| 58 | + Then I see these errors |
| 59 | + | Type | Message | |
| 60 | + | InvalidArgument | Argument 2 of Psr\Log\LoggerInterface::emergency expects array{exception?: Exception}, array{exception: string(foo)} provided | |
| 61 | + | InvalidArgument | Argument 2 of Psr\Log\LoggerInterface::alert expects array{exception?: Exception}, array{exception: string(foo)} provided | |
| 62 | + | InvalidArgument | Argument 2 of Psr\Log\LoggerInterface::critical expects array{exception?: Exception}, array{exception: string(foo)} provided | |
| 63 | + | InvalidArgument | Argument 2 of Psr\Log\LoggerInterface::error expects array{exception?: Exception}, array{exception: string(foo)} provided | |
| 64 | + | InvalidArgument | Argument 2 of Psr\Log\LoggerInterface::warning expects array{exception?: Exception}, array{exception: string(foo)} provided | |
| 65 | + | InvalidArgument | Argument 2 of Psr\Log\LoggerInterface::notice expects array{exception?: Exception}, array{exception: string(foo)} provided | |
| 66 | + | InvalidArgument | Argument 2 of Psr\Log\LoggerInterface::info expects array{exception?: Exception}, array{exception: string(foo)} provided | |
| 67 | + | InvalidArgument | Argument 2 of Psr\Log\LoggerInterface::debug expects array{exception?: Exception}, array{exception: string(foo)} provided | |
| 68 | + | InvalidArgument | Argument 2 of Psr\Log\LoggerInterface::emergency expects array{exception?: Exception}, array{exception: Error} provided | |
| 69 | + | InvalidArgument | Argument 2 of Psr\Log\LoggerInterface::alert expects array{exception?: Exception}, array{exception: Error} provided | |
| 70 | + | InvalidArgument | Argument 2 of Psr\Log\LoggerInterface::critical expects array{exception?: Exception}, array{exception: Error} provided | |
| 71 | + | InvalidArgument | Argument 2 of Psr\Log\LoggerInterface::error expects array{exception?: Exception}, array{exception: Error} provided | |
| 72 | + | InvalidArgument | Argument 2 of Psr\Log\LoggerInterface::warning expects array{exception?: Exception}, array{exception: Error} provided | |
| 73 | + | InvalidArgument | Argument 2 of Psr\Log\LoggerInterface::notice expects array{exception?: Exception}, array{exception: Error} provided | |
| 74 | + | InvalidArgument | Argument 2 of Psr\Log\LoggerInterface::info expects array{exception?: Exception}, array{exception: Error} provided | |
| 75 | + | InvalidArgument | Argument 2 of Psr\Log\LoggerInterface::debug expects array{exception?: Exception}, array{exception: Error} provided | |
| 76 | + And I see no other errors |
| 77 | + |
| 78 | + Scenario: `exception` key is actually an Exception Object AS per AbstractLogger |
| 79 | + Given I have the following code |
| 80 | + """ |
| 81 | + concrete_abstract()->emergency("message", ['exception' => 'foo']); |
| 82 | + concrete_abstract()->alert("message", ['exception' => 'foo']); |
| 83 | + concrete_abstract()->critical("message", ['exception' => 'foo']); |
| 84 | + concrete_abstract()->error("message", ['exception' => 'foo']); |
| 85 | + concrete_abstract()->warning("message", ['exception' => 'foo']); |
| 86 | + concrete_abstract()->notice("message", ['exception' => 'foo']); |
| 87 | + concrete_abstract()->info("message", ['exception' => 'foo']); |
| 88 | + concrete_abstract()->debug("message", ['exception' => 'foo']); |
| 89 | + concrete_abstract()->emergency("message", ['exception' => new Error]); |
| 90 | + concrete_abstract()->alert("message", ['exception' => new Error]); |
| 91 | + concrete_abstract()->critical("message", ['exception' => new Error]); |
| 92 | + concrete_abstract()->error("message", ['exception' => new Error]); |
| 93 | + concrete_abstract()->warning("message", ['exception' => new Error]); |
| 94 | + concrete_abstract()->notice("message", ['exception' => new Error]); |
| 95 | + concrete_abstract()->info("message", ['exception' => new Error]); |
| 96 | + concrete_abstract()->debug("message", ['exception' => new Error]); |
| 97 | + """ |
| 98 | + When I run Psalm |
| 99 | + Then I see these errors |
| 100 | + | Type | Message | |
| 101 | + | InvalidArgument | Argument 2 of Psr\Log\AbstractLogger::emergency expects array{exception?: Exception}, array{exception: string(foo)} provided | |
| 102 | + | InvalidArgument | Argument 2 of Psr\Log\AbstractLogger::alert expects array{exception?: Exception}, array{exception: string(foo)} provided | |
| 103 | + | InvalidArgument | Argument 2 of Psr\Log\AbstractLogger::critical expects array{exception?: Exception}, array{exception: string(foo)} provided | |
| 104 | + | InvalidArgument | Argument 2 of Psr\Log\AbstractLogger::error expects array{exception?: Exception}, array{exception: string(foo)} provided | |
| 105 | + | InvalidArgument | Argument 2 of Psr\Log\AbstractLogger::warning expects array{exception?: Exception}, array{exception: string(foo)} provided | |
| 106 | + | InvalidArgument | Argument 2 of Psr\Log\AbstractLogger::notice expects array{exception?: Exception}, array{exception: string(foo)} provided | |
| 107 | + | InvalidArgument | Argument 2 of Psr\Log\AbstractLogger::info expects array{exception?: Exception}, array{exception: string(foo)} provided | |
| 108 | + | InvalidArgument | Argument 2 of Psr\Log\AbstractLogger::debug expects array{exception?: Exception}, array{exception: string(foo)} provided | |
| 109 | + | InvalidArgument | Argument 2 of Psr\Log\AbstractLogger::emergency expects array{exception?: Exception}, array{exception: Error} provided | |
| 110 | + | InvalidArgument | Argument 2 of Psr\Log\AbstractLogger::alert expects array{exception?: Exception}, array{exception: Error} provided | |
| 111 | + | InvalidArgument | Argument 2 of Psr\Log\AbstractLogger::critical expects array{exception?: Exception}, array{exception: Error} provided | |
| 112 | + | InvalidArgument | Argument 2 of Psr\Log\AbstractLogger::error expects array{exception?: Exception}, array{exception: Error} provided | |
| 113 | + | InvalidArgument | Argument 2 of Psr\Log\AbstractLogger::warning expects array{exception?: Exception}, array{exception: Error} provided | |
| 114 | + | InvalidArgument | Argument 2 of Psr\Log\AbstractLogger::notice expects array{exception?: Exception}, array{exception: Error} provided | |
| 115 | + | InvalidArgument | Argument 2 of Psr\Log\AbstractLogger::info expects array{exception?: Exception}, array{exception: Error} provided | |
| 116 | + | InvalidArgument | Argument 2 of Psr\Log\AbstractLogger::debug expects array{exception?: Exception}, array{exception: Error} provided | |
| 117 | + And I see no other errors |
0 commit comments