annotated-container icon indicating copy to clipboard operation
annotated-container copied to clipboard

Create test for container factory preparing an interface and having all implementations invoke method

Open cspray opened this issue 2 years ago • 1 comments

We want to support being able to specify an interface method as a target for #[ServicePrepare] and all implementations of that interface have the appropriate method invoked. At least in the php-di container (and possibly others) this functionality is not supported.

A new test-case should be implemented in the ContainerFactoryTestCase to accommodate this use-case. Specifically, the following should be possible:

<?php

namespace Psr\Log {

    interface LoggerAwareInterface {

        #[ServicePrepare]
        public function setLogger(LoggerInterface $logger) : void;

    }

}

class MyClass implements LoggerAwareInterface {


    public function setLogger(LoggerInterface $logger) : void {
        // this is called automatically on object creation, passing in the LoggerInterface
        // configured for this container
    }


}

cspray avatar May 23 '23 14:05 cspray

This test already exists and is passing for the php-di container. Need to dig further into what's happening here.

cspray avatar Jun 01 '23 21:06 cspray

I don't think this is actually a problem anymore. Closing this.

cspray avatar May 12 '24 13:05 cspray