Add failing test to show that overloaded extensions are broken in Extensible

This commit is contained in:
Robbie Averill 2018-10-09 12:35:32 +02:00
parent d1281a571a
commit 55e79ffdfd
3 changed files with 46 additions and 2 deletions

View File

@ -21,12 +21,13 @@ use SilverStripe\Core\Tests\Injector\InjectorTest\NeedsBothCirculars;
use SilverStripe\Core\Tests\Injector\InjectorTest\NewRequirementsBackend;
use SilverStripe\Core\Tests\Injector\InjectorTest\OriginalRequirementsBackend;
use SilverStripe\Core\Tests\Injector\InjectorTest\OtherTestObject;
use SilverStripe\Core\Tests\Injector\InjectorTest\SomeCustomisedExtension;
use SilverStripe\Core\Tests\Injector\InjectorTest\SomeExtension;
use SilverStripe\Core\Tests\Injector\InjectorTest\TestObject;
use SilverStripe\Core\Tests\Injector\InjectorTest\TestSetterInjections;
use SilverStripe\Core\Tests\Injector\InjectorTest\TestStaticInjections;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Dev\TestOnly;
use stdClass;
use SilverStripe\Security\Member;
define('TEST_SERVICES', __DIR__ . '/AopProxyServiceTest');
@ -1047,4 +1048,23 @@ class InjectorTest extends SapphireTest
Injector::unnest();
$this->nestingLevel--;
}
/**
* Tests that overloaded extensions work, see {@link Extensible::getExtensionInstance()}
*/
public function testExtendedExtensions()
{
Config::modify()
->set(Injector::class, SomeExtension::class, [
'class' => SomeCustomisedExtension::class,
])
->merge(Member::class, 'extensions', [
SomeExtension::class,
]);
/** @var Member|SomeExtension $member */
$member = new Member();
$this->assertTrue($member->hasExtension(SomeExtension::class));
$this->assertSame('bar', $member->someMethod());
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace SilverStripe\Core\Tests\Injector\InjectorTest;
class SomeCustomisedExtension extends SomeExtension
{
public function someMethod()
{
return 'bar';
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace SilverStripe\Core\Tests\Injector\InjectorTest;
use SilverStripe\ORM\DataExtension;
class SomeExtension extends DataExtension
{
public function someMethod()
{
return 'foo';
}
}