-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aaron Carlino
committed
Jan 13, 2022
1 parent
9d71588
commit 6050e9d
Showing
11 changed files
with
412 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
|
||
namespace SilverStripe\GraphQL\Tests\Fake\Extensions; | ||
|
||
use SilverStripe\ORM\DataExtension; | ||
|
||
class FakeExtension1 extends DataExtension | ||
{ | ||
|
||
} |
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,11 @@ | ||
<?php | ||
|
||
|
||
namespace SilverStripe\GraphQL\Tests\Fake\Extensions; | ||
|
||
use SilverStripe\ORM\DataExtension; | ||
|
||
class FakeExtension2 extends DataExtension | ||
{ | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
|
||
namespace SilverStripe\GraphQL\Tests\Schema\BulkLoader; | ||
|
||
|
||
use Fake\FakeBulkLoader; | ||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\GraphQL\Schema\BulkLoader\AbstractBulkLoader; | ||
use SilverStripe\GraphQL\Schema\BulkLoader\BulkLoaderSet; | ||
use SilverStripe\GraphQL\Schema\BulkLoader\Collection; | ||
|
||
class BulkLoaderSetTest extends SapphireTest | ||
{ | ||
public function testApplyConfig() | ||
{ | ||
$set = new BulkLoaderSet(); | ||
$set->applyConfig([ | ||
'fake' => [ | ||
'include' => [], | ||
] | ||
]); | ||
|
||
foreach ($set->getLoaders() as $loader) { | ||
$this->assertInstanceOf(AbstractBulkLoader::class, $loader); | ||
} | ||
} | ||
|
||
public function testInvalidLoader() | ||
{ | ||
$this->expectExceptionMessage('Loader "fail" does not exist'); | ||
$set = new BulkLoaderSet(); | ||
$set->applyConfig([ | ||
'fail' => [ | ||
'include' => [], | ||
] | ||
]); | ||
|
||
} | ||
|
||
public function testProcess() | ||
{ | ||
$set = new BulkLoaderSet([ | ||
new FakeBulkLoader(['one' => 'one', 'two' => 'two']), | ||
new FakeBulkLoader(['three' => 'three', 'four' => 'four']), | ||
], new Collection()); | ||
$result = $set->process(); | ||
$this->assertEquals(['three', 'four'], $result->getClasses()); | ||
} | ||
|
||
public function testInitialCollection() | ||
{ | ||
$set = new BulkLoaderSet([ | ||
new FakeBulkLoader(), | ||
new FakeBulkLoader(), | ||
], new Collection(['foo' => 'foo', 'bar' => 'bar'])); | ||
$result = $set->process(); | ||
$this->assertEquals(['foo', 'bar'], $result->getClasses()); | ||
} | ||
} |
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,66 @@ | ||
<?php | ||
|
||
|
||
namespace SilverStripe\GraphQL\Tests\Schema\BulkLoader; | ||
|
||
|
||
use SilverStripe\Core\Manifest\ModuleLoader; | ||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\GraphQL\Schema\BulkLoader\Collection; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\A1; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\B1; | ||
|
||
class CollectionTest extends SapphireTest | ||
{ | ||
public function testCollection() | ||
{ | ||
$collection = new Collection([ | ||
'class1' => 'file1', | ||
'class2' => 'file2', | ||
'class3' => 'file3', | ||
'class4' => 'file4', | ||
]); | ||
|
||
$collection->removeClass('class2') | ||
->removeFile('file3'); | ||
|
||
$this->assertEquals( | ||
['class1', 'class4'], | ||
$collection->getClasses() | ||
); | ||
|
||
$this->assertEquals( | ||
['file1', 'file4'], | ||
$collection->getFiles() | ||
); | ||
|
||
$this->assertEquals( | ||
[ | ||
'class1' => 'file1', | ||
'class4' => 'file4', | ||
], | ||
$collection->getManifest() | ||
); | ||
|
||
} | ||
|
||
public function testCreateFromClassList() | ||
{ | ||
$collection = Collection::createFromClassList([ | ||
A1::class, | ||
B1::class, | ||
]); | ||
$mod = ModuleLoader::inst()->getManifest()->getModule('silverstripe/graphql'); | ||
$path = $mod->getPath(); | ||
$this->assertEquals( | ||
[ | ||
A1::class => $path . '/tests/Fake/Inheritance/A1.php', | ||
B1::class => $path . '/tests/Fake/Inheritance/B1.php', | ||
], | ||
$collection->getManifest() | ||
); | ||
|
||
} | ||
|
||
|
||
} |
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,78 @@ | ||
<?php | ||
|
||
|
||
namespace SilverStripe\GraphQL\Tests\Schema\BulkLoader; | ||
|
||
|
||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\GraphQL\Schema\BulkLoader\Collection; | ||
use SilverStripe\GraphQL\Schema\BulkLoader\ExtensionLoader; | ||
use SilverStripe\GraphQL\Tests\Fake\Extensions\FakeExtension1; | ||
use SilverStripe\GraphQL\Tests\Fake\Extensions\FakeExtension2; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\A; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\A1; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\A1a; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\A2; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\B; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\B1; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\B1a; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\B2; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\C; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\C1; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\C2; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\C2a; | ||
|
||
class ExtensionLoaderTest extends SapphireTest | ||
{ | ||
public function testExtensionLoader() | ||
{ | ||
A1::add_extension(FakeExtension1::class); | ||
A2::add_extension(FakeExtension1::class); | ||
|
||
B1::add_extension(FakeExtension2::class); | ||
B2::add_extension(FakeExtension2::class); | ||
|
||
C1::add_extension(FakeExtension1::class); | ||
C1::add_extension(FakeExtension2::class); | ||
|
||
$collection = Collection::createFromClassList([ | ||
A::class, | ||
A1::class, | ||
A2::class, | ||
A1a::class, | ||
B::class, | ||
B1::class, | ||
B2::class, | ||
B1a::class, | ||
C::class, | ||
C1::class, | ||
C2::class, | ||
C2a::class, | ||
]); | ||
|
||
$loader = new ExtensionLoader( | ||
[FakeExtension1::class], | ||
[FakeExtension2::class] | ||
); | ||
|
||
$result = $loader->collect($collection)->getClasses(); | ||
$this->assertEquals([ | ||
A1::class, | ||
A2::class, | ||
A1a::class, | ||
], $result); | ||
|
||
$loader = new ExtensionLoader( | ||
[FakeExtension2::class] | ||
); | ||
|
||
$result = $loader->collect($collection)->getClasses(); | ||
$this->assertEquals([ | ||
B1::class, | ||
B2::class, | ||
B1a::class, | ||
C1::class, | ||
], $result); | ||
|
||
} | ||
} |
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,62 @@ | ||
<?php | ||
|
||
|
||
namespace SilverStripe\GraphQL\Tests\Schema\BulkLoader; | ||
|
||
|
||
use SilverStripe\Core\Manifest\ModuleLoader; | ||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\GraphQL\Schema\BulkLoader\Collection; | ||
use SilverStripe\GraphQL\Schema\BulkLoader\FilepathLoader; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\A; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\A1; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\A1a; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\A2; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\B; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\B1; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\B1a; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\B2; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\C; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\C1; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\C2; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\C2a; | ||
|
||
class FilepathLoaderTest extends SapphireTest | ||
{ | ||
public function testFilepathLoader() | ||
{ | ||
$path = ModuleLoader::inst() | ||
->getManifest() | ||
->getModule('silverstripe/graphql') | ||
->getRelativePath(); | ||
|
||
$collection = Collection::createFromClassList([ | ||
A::class, | ||
A1::class, | ||
A2::class, | ||
A1a::class, | ||
B::class, | ||
B1::class, | ||
B2::class, | ||
B1a::class, | ||
C::class, | ||
C1::class, | ||
C2::class, | ||
C2a::class, | ||
]); | ||
|
||
$loader = new FilepathLoader( | ||
[$path . '/tests/Fake/Inheritance/B*.php'], | ||
[$path . '/tests/Fake/Inheritance/*a.php'] | ||
); | ||
|
||
$result = $loader->collect($collection)->getClasses(); | ||
|
||
$this->assertEquals([ | ||
B::class, | ||
B1::class, | ||
B2::class, | ||
], $result); | ||
|
||
} | ||
} |
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,58 @@ | ||
<?php | ||
|
||
|
||
namespace SilverStripe\GraphQL\Tests\Schema\BulkLoader; | ||
|
||
|
||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\GraphQL\Schema\BulkLoader\Collection; | ||
use SilverStripe\GraphQL\Schema\BulkLoader\InheritanceLoader; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\A; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\A1; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\A1a; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\A2; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\B; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\B1; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\B1a; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\B2; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\C; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\C1; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\C2; | ||
use SilverStripe\GraphQL\Tests\Fake\Inheritance\C2a; | ||
|
||
class InheritanceLoaderTest extends SapphireTest | ||
{ | ||
public function testInheritanceLoader() | ||
{ | ||
$collection = Collection::createFromClassList([ | ||
A::class, | ||
A1::class, | ||
A2::class, | ||
A1a::class, | ||
B::class, | ||
B1::class, | ||
B2::class, | ||
B1a::class, | ||
C::class, | ||
C1::class, | ||
C2::class, | ||
C2a::class, | ||
]); | ||
|
||
$loader = new InheritanceLoader( | ||
[A1::class, B1::class, C::class], | ||
[C2::class] | ||
); | ||
|
||
$result = $loader->collect($collection)->getClasses(); | ||
|
||
$this->assertEquals([ | ||
A1::class, | ||
A1a::class, | ||
B1::class, | ||
B1a::class, | ||
C::class, | ||
C1::class, | ||
], $result); | ||
} | ||
} |
Oops, something went wrong.