Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Attribute/BooleanSpecializedAttributeDecorator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Markup\NeedleBundle\Attribute;

/**
* A decorator for an attribute that declares a Boolean type (clobbering any underlying type).
*/
class BooleanSpecializedAttributeDecorator extends SpecializedAttributeDecorator implements BooleanAttributeInterface
{
}
9 changes: 9 additions & 0 deletions Attribute/FloatSpecializedAttributeDecorator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Markup\NeedleBundle\Attribute;

/**
* A decorator for an attribute that declares a float type (clocking any underlying type).
*/
class FloatSpecializedAttributeDecorator extends SpecializedAttributeDecorator implements FloatAttributeInterface
{}
87 changes: 87 additions & 0 deletions Attribute/SpecializedAttributeDecorator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

namespace Markup\NeedleBundle\Attribute;

/**
* A superclass for a decorator for attributes, setting up the default behaviour of a 1:1 map.
*/
abstract class SpecializedAttributeDecorator implements SpecializedAttributeInterface
{
/**
* The attribute being decorated.
*
* @var SpecializedAttributeInterface
**/
private $attribute;

/**
* @param SpecializedAttributeInterface $attribute
**/
public function __construct(SpecializedAttributeInterface $attribute)
{
$this->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();
}

}
68 changes: 68 additions & 0 deletions Tests/Attribute/BooleanSpecializedAttributeDecoratorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace Markup\NeedleBundle\Tests\Filter;

use Markup\NeedleBundle\Attribute\BooleanAttributeInterface;
use Markup\NeedleBundle\Attribute\BooleanSpecializedAttributeDecorator;
use Markup\NeedleBundle\Attribute\SpecializedAttributeInterface;
use Mockery as m;

/**
* A test for a decorator for a filter that declares a Boolean type (clocking any underlying type).
*/
class BooleanSpecializedAttributeDecoratorTest extends \PHPUnit_Framework_TestCase
{
/**
* @var SpecializedAttributeInterface|m\Mock
*/
private $filter;

/**
* @var BooleanSpecializedAttributeDecorator
*/
private $decorator;


public function setUp()
{
$this->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());
}
}
68 changes: 68 additions & 0 deletions Tests/Attribute/FloatSpecializedAttributeDecoratorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace Markup\NeedleBundle\Tests\Filter;

use Markup\NeedleBundle\Attribute\FloatAttributeInterface;
use Markup\NeedleBundle\Attribute\FloatSpecializedAttributeDecorator;
use Markup\NeedleBundle\Attribute\SpecializedAttributeInterface;
use Mockery as m;

/**
* A test for a decorator for a filter that declares a Boolean type (clocking any underlying type).
*/
class FloatSpecializedAttributeDecoratorTest extends \PHPUnit_Framework_TestCase
{
/**
* @var SpecializedAttributeInterface|m\Mock
*/
private $filter;

/**
* @var FloatSpecializedAttributeDecorator
*/
private $decorator;


public function setUp()
{
$this->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());
}
}