Codeception / Codeception/AspectMock

Parent class not found by locator

Open
#117 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
784
Forks
132
PR merge metrics
No merged PRs in 30d

Description

When using custom autoloader and try to get an instance of a class which has parent or implements an interface form the same custom namespace I have an error "PHP Fatal error: Uncaught InvalidArgumentException: Class [parent class name] was not found by locator in /workspace/projects/test/vendor/goaop/parser-reflection/src/ReflectionEngine.php:112".

I have very simple setup:

<?php

require_once __DIR__ . '/vendor/autoload.php';

$kernel = AspectMock\Kernel::getInstance();
$kernel->init([
    'debug' => true,
    'includePaths' => [__DIR__. '/lib'],
]);
$kernel->loadFile(__DIR__ . '/autoload.php'); // custom autoloader

$b = new \lib\B();

Class \lib\B:

namespace lib;

class B extends A {}

Class \lib\A:

namespace lib;

class A
{
    public function getName()
    {
        return static::class;
    }
}

Class B is loaded via my custom autoloader, but then the locator tries to load parent class A via composer autoloader and returns this error. Is this a bug, or I'm doing something wrong?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction using AspectMock\Kernel::init and loadFile in the custom autoload.php, then inspect vendor/goaop/parser-reflection/src/ReflectionEngine.php at line 112. Reproduce the failure with lib\B extending lib\A and trace how the locator handles the parent class. Done means the setup no longer reports the parent class as missing, with a regression test covering the custom namespace autoloader.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.