phpphpunitsilverstripesilverstripe-4

Silverstripe Test not Injecting config for Element


For some reason my test isn't injecting MockFormElement::$controller_class

My Test:

class NestedElementForms extends FunctionalTest {
    protected static $fixture_file = 'NestedElementFormsFixture.yml';

    /**
     * @test
     */
    public function submitFormOnElement() {
        $this->assertEquals(MockFormElementController::class, MockFormElement::config()->controller_class, 'Injection failed');
    }
}

My Mock Element:

class MockFormElement extends BaseElement implements TestOnly
{   
    private static $controller_class = MockFormElementController::class;
}

class MockFormElementController extends ElementController implements TestOnly
{

}

I've tried dev/build and clearing the silverstripe cache with rm -rf /tmp/silverstripe-... with no luck. It keeps it default value 'DNADesign\Elemental\Controllers\ElementController'


Solution

  • To use test only data objects in a test one needs to explicitly include them in the $extra_dataobjects config of that test