Codeception / Codeception/AspectMock

Class Stripe\Exception\ExceptionInterface was not found

Open
#180 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
784
Forks
132
PR merge metrics
No merged PRs in 30d

Description

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?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.