diff --git a/Attribute/BooleanSpecializedAttributeDecorator.php b/Attribute/BooleanSpecializedAttributeDecorator.php new file mode 100644 index 00000000..abefefe9 --- /dev/null +++ b/Attribute/BooleanSpecializedAttributeDecorator.php @@ -0,0 +1,10 @@ +attribute = $attribute; + } + + /** + * {@inheritDoc} + **/ + public function getName() + { + return $this->attribute->getName(); + } + + /** + * {@inheritDoc} + **/ + public function getDisplayName() + { + return $this->attribute->getDisplayName(); + } + + /** + * {@inheritDoc} + **/ + public function getSearchKey(array $options = []) + { + return $this->attribute->getSearchKey($options); + } + + /** + * Returns the underlying attribute that is being decorated + * @return SpecializedAttributeInterface + **/ + public function getAttribute() + { + return $this->attribute; + } + + /** + * {@inheritDoc} + */ + public function getSpecialization() + { + return $this->attribute->getSpecialization(); + } + + /** + * {@inheritDoc} + */ + public function setContext(AttributeSpecializationContextInterface $context) + { + $this->attribute->setContext($context); + } + + /** + * {@inheritDoc} + */ + public function getContext() + { + return $this->attribute->getContext(); + } + + public function __toString() + { + return $this->getDisplayName(); + } + +} diff --git a/Tests/Attribute/BooleanSpecializedAttributeDecoratorTest.php b/Tests/Attribute/BooleanSpecializedAttributeDecoratorTest.php new file mode 100644 index 00000000..04b6a23f --- /dev/null +++ b/Tests/Attribute/BooleanSpecializedAttributeDecoratorTest.php @@ -0,0 +1,68 @@ +filter = m::mock(SpecializedAttributeInterface::class); + $this->decorator = new BooleanSpecializedAttributeDecorator($this->filter); + } + + public function tearDown() + { + m::close(); + } + + public function testIsSpecializedAttribute() + { + $this->assertInstanceOf(SpecializedAttributeInterface::class, $this->decorator); + } + + public function testIsBooleanAttribute() + { + $this->assertInstanceOf(BooleanAttributeInterface::class, $this->decorator); + } + + public function testOneToOneDecoration() + { + $name = 'filter'; + $displayName = 'Filter'; + $searchKey = 'fil_ter'; + $this->filter + ->shouldReceive('getName') + ->andReturn($name); + + $this->filter + ->shouldReceive('getDisplayName') + ->andReturn($displayName); + + $this->filter + ->shouldReceive('getSearchKey') + ->andReturn($searchKey); + + $this->assertEquals($name, $this->decorator->getName()); + $this->assertEquals($displayName, $this->decorator->getDisplayName()); + $this->assertEquals($searchKey, $this->decorator->getSearchKey()); + } +} diff --git a/Tests/Attribute/FloatSpecializedAttributeDecoratorTest.php b/Tests/Attribute/FloatSpecializedAttributeDecoratorTest.php new file mode 100644 index 00000000..46275ba1 --- /dev/null +++ b/Tests/Attribute/FloatSpecializedAttributeDecoratorTest.php @@ -0,0 +1,68 @@ +filter = m::mock(SpecializedAttributeInterface::class); + $this->decorator = new FloatSpecializedAttributeDecorator($this->filter); + } + + public function tearDown() + { + m::close(); + } + + public function testIsSpecializedAttribute() + { + $this->assertInstanceOf(SpecializedAttributeInterface::class, $this->decorator); + } + + public function testIsBooleanAttribute() + { + $this->assertInstanceOf(FloatAttributeInterface::class, $this->decorator); + } + + public function testOneToOneDecoration() + { + $name = 'filter'; + $displayName = 'Filter'; + $searchKey = 'fil_ter'; + $this->filter + ->shouldReceive('getName') + ->andReturn($name); + + $this->filter + ->shouldReceive('getDisplayName') + ->andReturn($displayName); + + $this->filter + ->shouldReceive('getSearchKey') + ->andReturn($searchKey); + + $this->assertEquals($name, $this->decorator->getName()); + $this->assertEquals($displayName, $this->decorator->getDisplayName()); + $this->assertEquals($searchKey, $this->decorator->getSearchKey()); + } +}