1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | require __DIR__ . '/xdebug-filter.php'; |
||
6 | |||
7 | use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractTest; |
||
0 ignored issues
–
show
|
|||
8 | use Symfony\Component\Filesystem\Filesystem; |
||
9 | |||
10 | /** |
||
11 | * Empty out the var path of everything but the .gitignore file |
||
12 | * |
||
13 | * Will reinstate an existing .gitignore or default to a standard one |
||
14 | * |
||
15 | * Set error handler to convert everythign to Exceptions. PHPUnit is supposed to do this but is not reliable |
||
16 | * |
||
17 | * @throws ReflectionException |
||
18 | */ |
||
19 | (static function () { |
||
20 | $filesystem = new Filesystem(); |
||
21 | if (!is_dir(AbstractTest::VAR_PATH)) { |
||
22 | $filesystem->mkdir(AbstractTest::VAR_PATH); |
||
23 | } |
||
24 | $gitIgnorePath = AbstractTest::VAR_PATH . '/.gitignore'; |
||
25 | if ($filesystem->exists($gitIgnorePath)) { |
||
26 | $gitIgnore = file_get_contents(AbstractTest::VAR_PATH . '/.gitignore'); |
||
27 | } else { |
||
28 | $gitIgnore = "*\n!.gitignore\n"; |
||
29 | } |
||
30 | $filesystem->remove(AbstractTest::VAR_PATH); |
||
31 | $filesystem->mkdir(AbstractTest::VAR_PATH); |
||
32 | file_put_contents(AbstractTest::VAR_PATH . '/.gitignore', $gitIgnore); |
||
33 | |||
34 | set_error_handler(static function ($errno, $errstr, $errfile, $errline) { |
||
35 | $type = 'ERROR'; |
||
36 | switch ($errno) { |
||
37 | case E_USER_NOTICE: |
||
38 | $type = 'NOTICE'; |
||
39 | break; |
||
40 | case E_USER_WARNING: |
||
41 | $type = 'WARNING'; |
||
42 | break; |
||
43 | case E_USER_DEPRECATED: |
||
44 | $type = 'DEPRECATED'; |
||
45 | if (false !== strpos($errstr, 'Doctrine\Common\ClassLoader is deprecated')) { |
||
46 | return true; |
||
47 | } |
||
48 | break; |
||
49 | } |
||
50 | throw new ErrorException("$type\n$errstr\non line $errline\nin file $errfile\n"); |
||
51 | }); |
||
52 | })(); |
||
53 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: