I only get acquainted with the compositor and unit tests. Installed unit tests through the composer. This is what a json file looks like:

{ "require": { "symfony/var-dumper": "dev-master", "phpunit/phpunit": "^7.4" } } 

When I tried to create a class inherited from PHPUnit_Framework_TestCase, I received a fatal error - that such a class was not found ..

On ofts. PHPUnit site, I saw the following record \ PHPUnit \ Framework \ TestCase - which helped:

 class AppTest extends \PHPUnit\Framework\TestCase {...} 

As I understand it, is it related to the psr-0 and psr-4 standards? How is this configured for the composer? In which cases can one type of record be used, in which - the second (through the underscore together of the backslash)? What are the advantages of one and the second?

I also wanted to understand whether it is possible to change the location of the vendor folder of the composer, how to do it, and what is the risk?

1 answer 1

As you correctly answered, there are two standards for autoloading in php psr-0 and psr-4 . Psr-4 is the updated improved psr-0. One of the important differences is loading via _ for example:

  • The file located in /src/classes/Test.php should be called Src_Classes_Test

Such autoloading is found for the outdated framework zend framework 1. It is configured in the composer:

 "autoload": { "psr-0": { "Zend_": "library/" } }, 

For psr-4 example: - The file located in /src/classes/Test.php should be called Src / Classes / Test

Configured:

 "autoload": { "psr-4": { "": "src/" } }, 

Do not forget that for the standard psr-2 for long class names should be used:

 use \PHPUnit\Framework\TestCase as TestCase; class AppTest extends TestCase {} 

Vendor can be changed, but usually changed if necessary: https://getcomposer.org/doc/06-config.md#vendor-dir

 "config": { "vendor-dir": "libs" }