-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: check that incorrect classes don't trigger autoloading errors
Thanks @oprypkhantc
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace TheCodingMachine\GraphQLite\Fixtures\BadNamespace\None; | ||
|
||
class BadlyNamespacedClass | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
class ClassWithoutNamespace | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace TheCodingMachine\GraphQLite\Utils; | ||
|
||
use Kcs\ClassFinder\Finder\ComposerFinder; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Cache\Adapter\ArrayAdapter; | ||
use Symfony\Component\Cache\Psr16Cache; | ||
use TheCodingMachine\GraphQLite\Utils\Namespaces\NS; | ||
use TheCodingMachine\GraphQLite\Fixtures\Types\AbstractFooType; | ||
use TheCodingMachine\GraphQLite\Fixtures\Types\FooExtendType; | ||
use TheCodingMachine\GraphQLite\Fixtures\Types\FooType; | ||
use TheCodingMachine\GraphQLite\Fixtures\Types\GetterSetterType; | ||
use TheCodingMachine\GraphQLite\Fixtures\Types\MagicGetterSetterType; | ||
use TheCodingMachine\GraphQLite\Fixtures\Types\NoTypeAnnotation; | ||
use TheCodingMachine\GraphQLite\Fixtures\Types\TestFactory; | ||
|
||
class NsTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider loadsClassListProvider | ||
*/ | ||
public function testLoadsClassList(array $expectedClasses, string $namespace): void | ||
{ | ||
$ns = new NS( | ||
namespace: $namespace, | ||
cache: new Psr16Cache(new ArrayAdapter()), | ||
finder: new ComposerFinder(), | ||
globTTL: null | ||
); | ||
|
||
self::assertEqualsCanonicalizing($expectedClasses, array_keys($ns->getClassList())); | ||
} | ||
|
||
public static function loadsClassListProvider(): iterable | ||
{ | ||
yield 'autoload' => [ | ||
[ | ||
TestFactory::class, | ||
GetterSetterType::class, | ||
FooType::class, | ||
MagicGetterSetterType::class, | ||
FooExtendType::class, | ||
NoTypeAnnotation::class, | ||
AbstractFooType::class, | ||
], | ||
'TheCodingMachine\GraphQLite\Fixtures\Types', | ||
]; | ||
|
||
// The class should be ignored. | ||
yield 'incorrect namespace class without autoload' => [ | ||
[], | ||
'TheCodingMachine\GraphQLite\Fixtures\BadNamespace', | ||
]; | ||
} | ||
} |