Function parameters initialized with a class constant throw an exception
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 30/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- php
- Domain
- testing-qa
Research direction
Start by running tests/AspectMockTest.php with the bootstrap and UserModel.php example from the issue. Trace the failure through BeforeMockTransformer.php and the goaop parser-reflection stack, especially NodeExpressionResolver and ReflectionEngine. Done means the testDouble example runs without the PDO locator exception while preserving the class-constant default parameter.
Written by the indexing model from the issue text.
Description
Hello,
In the following code :
<?php
// test/bootstrap.php
require __DIR__ . '/../vendor/autoload.php'; // composer autoload
$kernel = \AspectMock\Kernel::getInstance();
$kernel->init([
'debug' => true,
'includePaths' => [
__DIR__ . '/../src',
'excludePaths' => [
__DIR__ . '/../tests'
]
]
]);
?>
<?php
// src/UserModel.php
namespace AM\Demo;
class UserModel {
public function save()
{
return("Save is not mocking\n");
}
public function get($id, $type = \PDO::FETCH_ASSOC)
{
}
}
?>
<?php
// tests/AspectMockTest.php
use AspectMock\Test as test;
use AM\Demo\UserModel;
class AspectMockTest extends \PHPUnit_Framework_TestCase
{
public function testDouble()
{
$mock = test::double('AM\Demo\UserModel', ['save' => "save is mocking"]);
}
protected function tearDown()
{
test::clean(); // remove all registered test doubles
}
}
when we launch the test we get the following exception :
PHPUnit 5.7.3 by Sebastian Bergmann and contributors.
Starting test 'AspectMockTest::testDouble'.
E 1 / 1 (100%)
Time: 1.6 seconds, Memory: 24.75MB
There was 1 error:
1) AspectMockTest::testDouble
InvalidArgumentException: Class PDO was not found by locator
/testgo/vendor/goaop/parser-reflection/src/ReflectionEngine.php:112
/testgo/vendor/goaop/parser-reflection/src/ReflectionEngine.php:127
/testgo/vendor/goaop/parser-reflection/src/ReflectionClass.php:45
/testgo/vendor/goaop/parser-reflection/src/ValueResolver/NodeExpressionResolver.php:301
/testgo/vendor/goaop/parser-reflection/src/ValueResolver/NodeExpressionResolver.php:259
/testgo/vendor/goaop/parser-reflection/src/ValueResolver/NodeExpressionResolver.php:118
/testgo/vendor/goaop/parser-reflection/src/ValueResolver/NodeExpressionResolver.php:99
/testgo/vendor/goaop/parser-reflection/src/ReflectionParameter.php:99
/testgo/vendor/goaop/parser-reflection/src/Traits/ReflectionFunctionLikeTrait.php:164
/testgo/vendor/codeception/aspect-mock/src/AspectMock/Intercept/BeforeMockTransformer.php:56
/testgo/vendor/goaop/framework/src/Instrument/Transformer/CachingTransformer.php:124
/testgo/vendor/goaop/framework/src/Instrument/Transformer/CachingTransformer.php:83
/testgo/vendor/goaop/framework/src/Instrument/ClassLoading/SourceTransformingLoader.php:134
/testgo/vendor/goaop/framework/src/Instrument/ClassLoading/SourceTransformingLoader.php:101
/testgo/vendor/goaop/framework/src/Instrument/ClassLoading/AopComposerLoader.php:136
/testgo/vendor/goaop/framework/src/Instrument/ClassLoading/AopComposerLoader.php:136
/testgo/vendor/codeception/aspect-mock/src/AspectMock/Test.php:97
/testgo/tests/AspectMockOrmTest.php:53
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
Do you have any solution or fix to help us please ?
- Dominant language
- PHP
- Stars
- 784
- Forks
- 130
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Codeception/AspectMock
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
Codeception/AspectMock#208 · 2 comments · 5 reactions ·
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
Codeception/AspectMock#206 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
Codeception/AspectMock#203 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 35/100
Codeception/AspectMock#202 · 5 comments · 2 reactions ·
-
Difficulty 3/5 1-2 days Newbie friendliness 42/100
Codeception/AspectMock#201 · 1 comment ·
All issues in Codeception/AspectMock
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
taskforcesh/bullmq#5238 ·
Maintainers usually reply within 1 day
-
[Bug] v-change-database-password reports success but doesn't change the password when MySQL validate_password rejects itPossibly taken @bfs2021 claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Automattic/jetpack#55517 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
area/import type/enhancement when/later
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day