Skip to content

Commit 94513e5

Browse files
committed
#20 added tests
1 parent 5e5580f commit 94513e5

File tree

3 files changed

+62
-7
lines changed

3 files changed

+62
-7
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"myclabs/php-enum": "^1.0",
1717
"phpunit/phpunit": "^7.5",
1818
"phpbench/phpbench": "^0.16.9",
19-
"vimeo/psalm": "^3.5"
19+
"vimeo/psalm": "^3.5",
20+
"symfony/error-handler": "^5.1"
2021
},
2122
"autoload": {
2223
"psr-4": {

src/StaticConstructorLoader/DebugStaticConstructorLoader.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ public function findFile($class)
146146
$path = $this->classLoader->findFile($class);
147147

148148
if (
149-
class_exists(\Symfony\Component\ErrorHandler\DebugClassLoader::class, false)
150-
|| class_exists(\Symfony\Component\Debug\DebugClassLoader::class, false)
149+
class_exists('Symfony\Component\ErrorHandler\DebugClassLoader', false)
150+
|| class_exists('Symfony\Component\Debug\DebugClassLoader', false)
151151
) {
152152
return $this->handleDebugClassLoader($class, $path);
153153
}
@@ -164,10 +164,7 @@ private function handleDebugClassLoader($class, $path)
164164
&& is_file($path)
165165
&& \in_array(
166166
$debugClassLoader['class'] ?? null,
167-
[
168-
\Symfony\Component\Debug\DebugClassLoader::class,
169-
\Symfony\Component\ErrorHandler\DebugClassLoader::class
170-
],
167+
['Symfony\Component\Debug\DebugClassLoader', 'Symfony\Component\ErrorHandler\DebugClassLoader'],
171168
true
172169
)
173170
) {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Dbalabka\Enumeration\Tests\StaticConstructorLoader;
4+
5+
use Dbalabka\StaticConstructorLoader\DebugStaticConstructorLoader;
6+
use Dbalabka\StaticConstructorLoader\StaticConstructorLoader;
7+
use Dbalabka\StaticConstructorLoader\Tests\Fixtures\ChildOfAbstractEnumeration;
8+
use PHPUnit\Framework\TestCase;
9+
use Symfony\Component\ErrorHandler\DebugClassLoader;
10+
11+
class DebugStaticConstructorLoaderTest extends TestCase
12+
{
13+
/** @var callable */
14+
private $defaultLoader;
15+
16+
protected function setUp()
17+
{
18+
$this->defaultLoader = \spl_autoload_functions()[0];
19+
}
20+
21+
protected function tearDown()
22+
{
23+
DebugClassLoader::disable();
24+
}
25+
26+
/**
27+
* @runInSeparateProcess
28+
*/
29+
public function testClassLoadWithDefaultStaticConstrcutorLoader()
30+
{
31+
new StaticConstructorLoader($this->defaultLoader[0]);
32+
$x = ChildOfAbstractEnumeration::$instance;
33+
$this->assertInstanceOf(ChildOfAbstractEnumeration::class, $x);
34+
}
35+
36+
/**
37+
* @runInSeparateProcess
38+
*/
39+
public function testClassLoadWithDefaultStaticConstrcutorLoaderAndSymfonyDebugLoader()
40+
{
41+
new StaticConstructorLoader($this->defaultLoader[0]);
42+
(new DebugClassLoader($this->defaultLoader))::enable();
43+
$x = ChildOfAbstractEnumeration::$instance;
44+
$this->assertNull($x);
45+
}
46+
47+
/**
48+
* @runInSeparateProcess
49+
*/
50+
public function testClassLoadWithDebugStaticConstrcutorLoaderAndSymfonyDebugLoader()
51+
{
52+
new DebugStaticConstructorLoader($this->defaultLoader[0]);
53+
(new DebugClassLoader($this->defaultLoader))::enable();
54+
$x = ChildOfAbstractEnumeration::$instance;
55+
$this->assertInstanceOf(ChildOfAbstractEnumeration::class, $x);
56+
}
57+
}

0 commit comments

Comments
 (0)