0

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 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.