Skip to content

Commit

Permalink
Merge pull request #551 from creative-commoners/pulls/4.3/config-locator
Browse files Browse the repository at this point in the history
MNT Fix unit test
  • Loading branch information
GuySartorelli authored Aug 27, 2023
2 parents d4a2e36 + de8d463 commit 868bf6a
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions tests/Schema/DataObject/InheritanceBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use SilverStripe\GraphQL\Tests\Fake\Inheritance\MySubclass;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Injector\SilverStripeServiceConfigurationLocator;

class InheritanceBuilderTest extends SapphireTest
{
Expand Down Expand Up @@ -323,24 +324,35 @@ private function assertFields(array $fields, Type $type)

public function testFillAncestryInjectorSubclass()
{
Config::modify()->merge(Injector::class, MyOrig::class, ['class' => MySubclass::class]);
$obj = MyOrig::create();
$this->assertSame(MySubclass::class, get_class($obj));
$schema = new TestSchema();
$schema->applyConfig([
'models' => [
MyOrig::class => [
'fields' => [
'MyField' => true,
'MySubclassField' => true,
// Update configLocator of the Injector inst() in order to clear the cache in
// SilverStripeServiceConfigurationLocator() which has no API to clear the cache.
// This is done to fix bleed over from the unit test UsedOnTableTest::getUsage()
// which will cache the config for MyOrig::class as that test will automatically
// cache config for most DataObjects
Injector::inst()->setConfigLocator(new SilverStripeServiceConfigurationLocator());
try {
Config::modify()->set(Injector::class, MyOrig::class, ['class' => MySubclass::class]);
$obj = MyOrig::create();
$this->assertSame(MySubclass::class, get_class($obj));
$schema = new TestSchema();
$schema->applyConfig([
'models' => [
MyOrig::class => [
'fields' => [
'MyField' => true,
'MySubclassField' => true,
],
],
],
]
]);
$schema->createStoreableSchema();
$modelType = $schema->getModelByClassName(MySubclass::class);
$builder = new InheritanceBuilder($schema);
$builder->fillAncestry($modelType);
$this->assertFields(['id', 'MyField', 'MySubclassField'], $modelType);
]
]);
$schema->createStoreableSchema();
$modelType = $schema->getModelByClassName(MySubclass::class);
$builder = new InheritanceBuilder($schema);
$builder->fillAncestry($modelType);
$this->assertFields(['id', 'MyField', 'MySubclassField'], $modelType);
} finally {
// reset the cache again to prevent bleed over into any other tests
Injector::inst()->setConfigLocator(new SilverStripeServiceConfigurationLocator());
}
}
}

0 comments on commit 868bf6a

Please sign in to comment.