Codeception / Codeception/AspectMock

Class Stripe\Exception\ExceptionInterface was not found

未关闭
#180 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
PHP
星标
784
派生
132
PR 合并指标
30 天内没有已合并 PR

描述

In my tests, I am forcing Stripe to fail by giving it a bogus API key, so that I can test the error logging etc.

However, when I have Aspect Mock enabled, it seems that due to some internal reflection, Stripe's actual error message is being tampered with. Instead of seeing:

```
[Stripe\Exception\AuthenticationException] Invalid API Key provided: boguskey
```
which is what I see when AspectMock is totally removed from my project, instead, I get:

```
[InvalidArgumentException] Class Stripe\Exception\ExceptionInterface was not found in the /path/to/stripe/vendor/files
```

Here is the trace:

```
/work/vendor/goaop/parser-reflection/src/ReflectionEngine.php:152
/work/vendor/goaop/parser-reflection/src/ReflectionClass.php:44
/work/vendor/goaop/parser-reflection/src/ReflectionClass.php:68
/work/vendor/goaop/parser-reflection/src/Traits/ReflectionClassLikeTrait.php:974
/work/vendor/goaop/parser-reflection/src/Traits/ReflectionClassLikeTrait.php:323
/work/vendor/goaop/parser-reflection/src/Traits/ReflectionClassLikeTrait.php:322
/work/vendor/goaop/parser-reflection/src/Traits/ReflectionClassLikeTrait.php:971
/work/vendor/goaop/parser-reflection/src/Traits/ReflectionClassLikeTrait.php:323
/work/vendor/goaop/parser-reflection/src/Traits/ReflectionClassLikeTrait.php:309
/work/vendor/codeception/aspect-mock/src/AspectMock/Intercept/BeforeMockTransformer.php:31
/work/vendor/goaop/framework/src/Instrument/Transformer/CachingTransformer.php:121
/work/vendor/goaop/framework/src/Instrument/Transformer/CachingTransformer.php:78
/work/vendor/goaop/framework/src/Instrument/ClassLoading/SourceTransformingLoader.php:136
/work/vendor/goaop/framework/src/Instrument/ClassLoading/SourceTransformingLoader.php:103
/work/vendor/goaop/framework/src/Instrument/ClassLoading/AopComposerLoader.php:139
/work/vendor/goaop/framework/src/Instrument/ClassLoading/AopComposerLoader.php:139
/work/vendor/stripe/stripe-php/lib/ApiRequestor.php:182
/work/vendor/stripe/stripe-php/lib/ApiRequestor.php:142
/work/vendor/stripe/stripe-php/lib/ApiRequestor.php:429
/work/vendor/stripe/stripe-php/lib/ApiRequestor.php:113
/work/vendor/stripe/stripe-php/lib/ApiOperations/Request.php:63
/work/vendor/stripe/stripe-php/lib/ApiOperations/Create.php:25
/work/library/stripe_functions.php:266
/work/tests/unit/library/StripeFunctionsTest.php:680
/work/vendor/phpunit/phpunit/src/Framework/TestCase.php:1408
/work/vendor/phpunit/phpunit/src/Framework/TestCase.php:1028
/work/vendor/phpunit/phpunit/src/Framework/TestResult.php:691
/work/vendor/phpunit/phpunit/src/Framework/TestCase.php:756
/work/vendor/phpunit/phpunit/src/Framework/TestSuite.php:597
/work/vendor/codeception/phpunit-wrapper/src/Runner.php:117
/work/vendor/codeception/codeception/src/Codeception/SuiteManager.php:158
/work/vendor/codeception/codeception/src/Codeception/Codecept.php:193
/work/vendor/codeception/codeception/src/Codeception/Codecept.php:160
/work/vendor/codeception/codeception/src/Codeception/Command/Run.php:391
/work/vendor/symfony/console/Command/Command.php:255
/work/vendor/symfony/console/Application.php:1012
/work/vendor/symfony/console/Application.php:272
/work/vendor/symfony/console/Application.php:148
/work/vendor/codeception/codeception/src/Codeception/Application.php:107
/work/vendor/codeception/codeception/codecept:43
```

It seems that when Stripe hits my (intentional) error, it gets rerouted into the internals of `AspectMock` and gets lost.

This is the trace when AspectMock is disabled:

```
/work/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php:38
/work/vendor/stripe/stripe-php/lib/ApiRequestor.php:189
/work/vendor/stripe/stripe-php/lib/ApiRequestor.php:149
/work/vendor/stripe/stripe-php/lib/ApiRequestor.php:438
/work/vendor/stripe/stripe-php/lib/ApiRequestor.php:118
/work/vendor/stripe/stripe-php/lib/ApiOperations/Request.php:63
/work/vendor/stripe/stripe-php/lib/ApiOperations/Create.php:25
/work/library/stripe_functions.php:266
/work/tests/unit/library/StripeFunctionsTest.php:680
/work/vendor/phpunit/phpunit/src/Framework/TestCase.php:1408
/work/vendor/phpunit/phpunit/src/Framework/TestCase.php:1028
/work/vendor/phpunit/phpunit/src/Framework/TestResult.php:691
/work/vendor/phpunit/phpunit/src/Framework/TestCase.php:756
/work/vendor/phpunit/phpunit/src/Framework/TestSuite.php:597
/work/vendor/codeception/phpunit-wrapper/src/Runner.php:117
/work/vendor/codeception/codeception/src/Codeception/SuiteManager.php:158
/work/vendor/codeception/codeception/src/Codeception/Codecept.php:193
/work/vendor/codeception/codeception/src/Codeception/Codecept.php:160
/work/vendor/codeception/codeception/src/Codeception/Command/Run.php:391
/work/vendor/symfony/console/Command/Command.php:255
/work/vendor/symfony/console/Application.php:1012
/work/vendor/symfony/console/Application.php:272
/work/vendor/symfony/console/Application.php:148
/work/vendor/codeception/codeception/src/Codeception/Application.php:107
/work/vendor/codeception/codeception/codecept:43
```

You can see it goes straight to `/work/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php:38`.

I should say that when using my correct Stripe API key (and no exceptions are thrown), my code connects fine to Stripe and does what it is supposed to on their platform.

I am using PHP-Unit 8.5, Codeception 3.1.2, Aspect Mock 3.1.0. Will upgrading to the latest versions of PHPUnit/CodeCeption make any difference? Suggestions?

贡献指南

这个仓库没有索引到贡献指南

调研方向

在启用 AspectMock 的情况下,复现 tests/unit/library/StripeFunctionsTest.php:680 中的 bogus-key 用例,然后跟踪经过 goaop/parser-reflection/src/ReflectionEngine.php 和 codeception/aspect-mock/src/AspectMock/Intercept/BeforeMockTransformer.php 的流程。将经过 stripe/stripe-php/lib/ApiRequestor.php 的失败路径与禁用 AspectMock 时的 trace 进行比较。完成的标准是:有意触发的 Stripe 失败能够到达 ApiErrorException,并保留 AuthenticationException 的消息,而不是报告缺少 Stripe exception interface。

由索引模型根据 Issue 内容生成。

评估

技术栈
php
领域
testing-qa
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。