public function testBindsModuleSingletonProviderMethod() { $bindingMock = $this->getMockBuilder('Octahedron\\Pulp\\Binding\\Binding')->disableOriginalConstructor()->setMethods(['toProvider', 'in'])->getMock(); $bindingMock->expects($this->once())->method('toProvider')->with($this->isInstanceOf('Octahedron\\Pulp\\Provider\\ProviderMethod'))->will($this->returnValue($bindingMock)); $bindingMock->expects($this->once())->method('in')->with($this->identicalTo(Scopes::singleton())); $binderStub = $this->getMockBuilder('Octahedron\\Pulp\\Binding\\Binder')->setConstructorArgs([new AnnotationReader()])->setMethods(['bind'])->getMock(); $binderStub->expects($this->once())->method('bind')->will($this->returnValue($bindingMock)); $binderStub->install(new TestSingletonModule($binderStub)); }
protected function getProviderMethods(Module $module) { $reflectedClass = new \ReflectionClass($module); foreach ($reflectedClass->getMethods() as $reflectedMethod) { $provides = $this->annotationReader->getMethodAnnotation($reflectedMethod, Provides::CLASS); if ($provides) { $binding = $this->bind($provides->value)->toProvider(new ProviderMethod($module, $reflectedMethod->getName())); if ($this->annotationReader->getMethodAnnotation($reflectedMethod, Singleton::CLASS)) { $binding->in(Scopes::singleton()); } } } }
/** * @expectedException InvalidArgumentException * @expectedExceptionMessage Invalid scope specified */ public function testInvalidScope() { Scopes::invalidScope(); }
public function __construct($interface) { $this->interface = $interface; $this->scope = Scopes::instance(); }