diff --git a/src/ServiceLocatorAwareTrait.php b/src/ServiceLocatorAwareTrait.php new file mode 100644 index 00000000..ab81e565 --- /dev/null +++ b/src/ServiceLocatorAwareTrait.php @@ -0,0 +1,48 @@ +serviceLocator = $serviceLocator; + + return $this; + } + + /** + * Get service locator + * + * @return ServiceLocator + */ + public function getServiceLocator() + { + return $this->serviceLocator; + } +} diff --git a/test/ServiceLocatorAwareTraitTest.php b/test/ServiceLocatorAwareTraitTest.php new file mode 100644 index 00000000..d33e136a --- /dev/null +++ b/test/ServiceLocatorAwareTraitTest.php @@ -0,0 +1,46 @@ +getObjectForTrait('\Zend\ServiceManager\ServiceLocatorAwareTrait'); + + $this->assertAttributeEquals(null, 'serviceLocator', $object); + + $serviceLocator = new ServiceManager; + + $object->setServiceLocator($serviceLocator); + + $this->assertAttributeEquals($serviceLocator, 'serviceLocator', $object); + } + + public function testGetServiceLocator() + { + $object = $this->getObjectForTrait('\Zend\ServiceManager\ServiceLocatorAwareTrait'); + + $this->assertNull($object->getServiceLocator()); + + $serviceLocator = new ServiceManager; + + $object->setServiceLocator($serviceLocator); + + $this->assertEquals($serviceLocator, $object->getServiceLocator()); + } +}