-
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.
Allow loading types with autoloading
- Loading branch information
1 parent
256da31
commit bf3f749
Showing
5 changed files
with
112 additions
and
24 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
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
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
File renamed without changes.
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,59 @@ | ||
<?php | ||
|
||
namespace TheCodingMachine\GraphQLite\Utils\Namespaces; | ||
|
||
use Mouf\Composer\ClassNameMapper; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Cache\Adapter\ArrayAdapter; | ||
use Symfony\Component\Cache\Psr16Cache; | ||
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, bool $autoload): void | ||
{ | ||
$ns = new NS( | ||
namespace: $namespace, | ||
cache: new Psr16Cache(new ArrayAdapter()), | ||
classNameMapper: ClassNameMapper::createFromComposerFile(null, null, true), | ||
globTTL: null, | ||
recursive: true, | ||
autoload: $autoload, | ||
); | ||
|
||
self::assertSame($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', | ||
true, | ||
]; | ||
|
||
// The class should be ignored. | ||
yield 'incorrect namespace class without autoload' => [ | ||
[], | ||
'TheCodingMachine\GraphQLite\Fixtures\BadNamespace', | ||
false, | ||
]; | ||
} | ||
} |