Skip to content
Advertisement

Namespace that seems it doesn’t exist is working but why?

I have this exercice folder that gave me instructions on how to install the web application:

So this folder contains a .sh file that installs the necessary things:

npm install
curl -o phpunit -L https://phar.phpunit.de/phpunit-7.phar
chmod +x phpunit
./phpunit --version

So basically this adds a file called phpunit inside root folder. So by far I kind of understand what’s going on, so this installs node dependencies and also installs phpunit (I think so), but this project has a test example unit:

<?php

declare(strict_types=1);

use PHPUnitFrameworkTestCase;

final class HelloWorldTest extends TestCase
{
  public function testWhenGetDataFromHelloWorld(): void
  {
    $this->assertEquals('Hello World', 'Hello World');
  }
}

At this point is where I don’t get how is use PHPUnitFrameworkTestCase; working, since I don’t have any folder called PHPUnit, I get that use is something like importing a class, but still, how is this working (when I run the test it does not give me any kind of error)?, also, it appears that vscode detects the import as an error because it seems that it doesn’t exist.

My file tree is as follows:

enter image description here

Can someone explain me, please?

Advertisement

Answer

This is because all the dependencies are in the phpunit-7.phar file, which was named phpunit by that script.

“The easiest way to obtain PHPUnit is to download a PHP Archive (PHAR) that has all required (as well as some optional) dependencies of PHPUnit bundled in a single file.”

PHPUnit – Installing PHPUnit – PHP Archive (PHAR)

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement