Skip to content

Commit

Permalink
#20 added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-andreyev committed Jun 10, 2020
1 parent 5e5580f commit 94513e5
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 7 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"myclabs/php-enum": "^1.0",
"phpunit/phpunit": "^7.5",
"phpbench/phpbench": "^0.16.9",
"vimeo/psalm": "^3.5"
"vimeo/psalm": "^3.5",
"symfony/error-handler": "^5.1"
},
"autoload": {
"psr-4": {
Expand Down
9 changes: 3 additions & 6 deletions src/StaticConstructorLoader/DebugStaticConstructorLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ public function findFile($class)
$path = $this->classLoader->findFile($class);

if (
class_exists(\Symfony\Component\ErrorHandler\DebugClassLoader::class, false)
|| class_exists(\Symfony\Component\Debug\DebugClassLoader::class, false)
class_exists('Symfony\Component\ErrorHandler\DebugClassLoader', false)
|| class_exists('Symfony\Component\Debug\DebugClassLoader', false)
) {
return $this->handleDebugClassLoader($class, $path);
}
Expand All @@ -164,10 +164,7 @@ private function handleDebugClassLoader($class, $path)
&& is_file($path)
&& \in_array(
$debugClassLoader['class'] ?? null,
[
\Symfony\Component\Debug\DebugClassLoader::class,
\Symfony\Component\ErrorHandler\DebugClassLoader::class
],
['Symfony\Component\Debug\DebugClassLoader', 'Symfony\Component\ErrorHandler\DebugClassLoader'],
true
)
) {
Expand Down
57 changes: 57 additions & 0 deletions tests/StaticConstructorLoader/DebugStaticConstructorLoaderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php declare(strict_types=1);

namespace Dbalabka\Enumeration\Tests\StaticConstructorLoader;

use Dbalabka\StaticConstructorLoader\DebugStaticConstructorLoader;
use Dbalabka\StaticConstructorLoader\StaticConstructorLoader;
use Dbalabka\StaticConstructorLoader\Tests\Fixtures\ChildOfAbstractEnumeration;
use PHPUnit\Framework\TestCase;
use Symfony\Component\ErrorHandler\DebugClassLoader;

class DebugStaticConstructorLoaderTest extends TestCase
{
/** @var callable */
private $defaultLoader;

protected function setUp()
{
$this->defaultLoader = \spl_autoload_functions()[0];
}

protected function tearDown()
{
DebugClassLoader::disable();
}

/**
* @runInSeparateProcess
*/
public function testClassLoadWithDefaultStaticConstrcutorLoader()
{
new StaticConstructorLoader($this->defaultLoader[0]);
$x = ChildOfAbstractEnumeration::$instance;
$this->assertInstanceOf(ChildOfAbstractEnumeration::class, $x);
}

/**
* @runInSeparateProcess
*/
public function testClassLoadWithDefaultStaticConstrcutorLoaderAndSymfonyDebugLoader()
{
new StaticConstructorLoader($this->defaultLoader[0]);
(new DebugClassLoader($this->defaultLoader))::enable();
$x = ChildOfAbstractEnumeration::$instance;
$this->assertNull($x);
}

/**
* @runInSeparateProcess
*/
public function testClassLoadWithDebugStaticConstrcutorLoaderAndSymfonyDebugLoader()
{
new DebugStaticConstructorLoader($this->defaultLoader[0]);
(new DebugClassLoader($this->defaultLoader))::enable();
$x = ChildOfAbstractEnumeration::$instance;
$this->assertInstanceOf(ChildOfAbstractEnumeration::class, $x);
}
}

0 comments on commit 94513e5

Please sign in to comment.