Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT Fix unit test #551

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
}