/** * Tests creating a service with a custom factory. */ public function testCustomFactory() { $injector = new Injector(array('service' => array('factory' => 'factory', 'constructor' => array(1, 2, 3)))); $factory = $this->getMock('SilverStripe\\Core\\Injector\\Factory'); $factory->expects($this->once())->method('create')->with($this->equalTo('service'), $this->equalTo(array(1, 2, 3)))->will($this->returnCallback(function ($args) { return new TestObject(); })); $injector->registerService($factory, 'factory'); $this->assertInstanceOf('TestObject', $injector->get('service')); }