PHPUnit calling external function as object I'm doing a unit testing with my CVRClient file using the code below.

//CvrapiTest.php

&lt;?php

namespace Drupal\cvr\test\Cvrapi;

use PHPUnit_Framework_TestCase;
use cvr\src\Cvrapi\CVRClient;

class CvrapiTest extends PHPUnit_Framework_TestCase {

public function testSearchOnlyVAT()
    {
        $result = \Cvrapi\CVRClient::request('29910251', 'dk', 'vat', 'Unit Testing');

        $this-&gt;assertTrue(property_exists($result, 'vat'));
        $this-&gt;assertTrue((int)$result-&gt;vat === 29910251);
    }


I have a CVRClient class under cvr/src/Cvrapi folder that queries data from an api.

I know that phpunit command is working fine but I'm getting the error below.


  Fatal error: Class 'cvr\src\Cvrapi\CVRClient' not found in
  /Applications/MAMP/htdocs/query/modules/custom/cvr/test/Cvrapi/CvrapiTest.php
  on line 17


NOTE: It's the \Cvrapi\CVRClient:: that causes the error. If I remove this line, I need to have a code to assign values to $result.
The problem is that your use declaration is incorrect, and is causing your call to the client to look in the wrong namespace. You probably need to change this:

use cvr\src\Cvrapi\CVRClient;


To this:

use Cvrapi\CVRClient;


And change this:

$result = \Cvrapi\CVRClient::request('29910251', 'dk', 'vat', 'Unit Testing');


To this:

$result = CVRClient::request('29910251', 'dk', 'vat', 'Unit Testing');