In CoreClassReflection.php Class Does Not Exist While Using Infection

42 Views Asked by At

I try to use Infection to evaluate my testcase using php, I have 2 file (Displayuser.php, displayuserTest.php)

for the first file Displayuser.php the code like this, this file under func folder

<?php
namespace func;
include 'config.php';
class Displayuser 
{
public function add($num1, $num2) {
        return $num1 + $num2;
    }
}
?>

and the second file displayuserTest.php

<?php
include 'config.php';
include 'func/Displayuser.php';
use func\Displayuser;
class DisplayuserTest extends PHPUnit\Framework\TestCase
{
public function testAdd()
   {
    $dispUser = new func\Displayuser;
    $result = $dispUser->add(1,2);
    $this->assertEquals(3,$result);
   }
}
?>

if I use PHPUnit to test with this command "./vendor/bin/phpunit --testdox" it doesnt matter, no error comes up, but when I use infection command like "infection --filter=Displayuser.php" there is error message

**Processing source code files: 0/1 In CoreClassReflection.php line 55:

Class "func\Displayuser" does not exist
** why it happen, any master can help me. Thanks

I have create func namespace at Displayuser.php, and actually $dispUser->add can be called but I still get that error.

1

There are 1 best solutions below

0
arasyid tutorial On

Actually this problem comes when I changed the folder from function to func, the solution that I do

  1. I have to ensure the autoloading configuration in composer.json to something like this
    {
        "autoload": {
            "psr-4": {
                "Func\\": "func"
            }
        }
    }
  1. Clear Autoload Cache by this command composer dump-autoload

and the error message has gone