-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add PostObjectInterface::getIcon() which returns an IconInterfa…
…ce (#1233)
- Loading branch information
Showing
11 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Municipio\PostObject\Decorators; | ||
|
||
use Municipio\PostObject\Icon\IconInterface; | ||
use Municipio\PostObject\Icon\Resolvers\IconResolverInterface; | ||
use Municipio\PostObject\PostObjectInterface; | ||
|
||
/** | ||
* IconResolvingPostObject | ||
*/ | ||
class IconResolvingPostObject extends AbstractPostObjectDecorator implements PostObjectInterface | ||
{ | ||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct(PostObjectInterface $inner, private IconResolverInterface $iconResolver) | ||
{ | ||
$this->postObject = $inner; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getIcon(): ?IconInterface | ||
{ | ||
return $this->iconResolver->resolve(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
library/PostObject/Decorators/IconResolvingPostObject.test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Municipio\PostObject\Decorators; | ||
|
||
use Municipio\PostObject\Icon\IconInterface; | ||
use Municipio\PostObject\Icon\Resolvers\IconResolverInterface; | ||
use Municipio\PostObject\Icon\Resolvers\NullIconResolver; | ||
use Municipio\PostObject\PostObject; | ||
use Municipio\PostObject\PostObjectInterface; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class IconResolvingPostObjectTest extends TestCase | ||
{ | ||
/** | ||
* @testdox class can be instantiated | ||
*/ | ||
public function testClassCanBeInstantiated() | ||
{ | ||
$decorator = new IconResolvingPostObject(new PostObject(), new NullIconResolver()); | ||
$this->assertInstanceOf(IconResolvingPostObject::class, $decorator); | ||
} | ||
|
||
/** | ||
* @testdox getIcon() calls provided icon resolver | ||
*/ | ||
public function testGetIconCallsProvidedIconResolver() | ||
{ | ||
$icon = $this->createMock(IconInterface::class); | ||
$iconResolver = $this->createMock(IconResolverInterface::class); | ||
|
||
$icon->method('getIcon')->willReturn('test-icon'); | ||
$iconResolver->method('resolve')->willReturn($icon); | ||
|
||
$postObject = new IconResolvingPostObject(new PostObject(), $iconResolver); | ||
|
||
$this->assertEquals('test-icon', $postObject->getIcon()->getIcon()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Municipio\PostObject\Icon; | ||
|
||
/** | ||
* Interface that adhere to the Icon component atttibutes. | ||
* @see https://styleguide.getmunicipio.com/components/atoms/icon | ||
*/ | ||
interface IconInterface | ||
{ | ||
/** | ||
* Sizes: xs, sm, md, lg, xl, xxl | ||
*/ | ||
public function getSize(): string; | ||
|
||
/** | ||
* A label on the icon | ||
*/ | ||
public function getLabel(): string; | ||
|
||
/** | ||
* Get the term icon. | ||
*/ | ||
public function getIcon(): string; | ||
|
||
/** | ||
* Get the term color. | ||
*/ | ||
public function getColor(): string; | ||
|
||
/** | ||
* A custom HEX color | ||
*/ | ||
public function getCustomColor(): string; | ||
|
||
/** | ||
* Icon HTML tag | ||
*/ | ||
public function getComponentElement(): string; | ||
|
||
/** | ||
* If the icons should be filled or not | ||
*/ | ||
public function getFilled(): bool; | ||
|
||
/** | ||
* If the icon is decorative only or serves a purpose. | ||
*/ | ||
public function getDecorative(): bool; | ||
|
||
/** | ||
* Get the term ID. | ||
*/ | ||
public function toArray(): array; | ||
} |
15 changes: 15 additions & 0 deletions
15
library/PostObject/Icon/Resolvers/IconResolverInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Municipio\PostObject\Icon\Resolvers; | ||
|
||
use Municipio\PostObject\Icon\IconInterface; | ||
|
||
interface IconResolverInterface | ||
{ | ||
/** | ||
* Resolve icon. | ||
* | ||
* @return IconInterface|null | ||
*/ | ||
public function resolve(): ?IconInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Municipio\PostObject\Icon\Resolvers; | ||
|
||
use Municipio\PostObject\Icon\IconInterface; | ||
|
||
/** | ||
* Null icon resolver. | ||
*/ | ||
class NullIconResolver implements IconResolverInterface | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function resolve(): ?IconInterface | ||
{ | ||
return null; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
library/PostObject/Icon/Resolvers/NullIconResolver.test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Municipio\PostObject\Icon\Resolvers; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class NullIconResolverTest extends TestCase | ||
{ | ||
/** | ||
* @testdox class can be instantiated | ||
*/ | ||
public function testClassCanBeInstantiated() | ||
{ | ||
$this->assertInstanceOf(NullIconResolver::class, new NullIconResolver()); | ||
} | ||
|
||
/** | ||
* @testdox resolve() returns null | ||
*/ | ||
public function testResolveReturnsNull() | ||
{ | ||
$resolver = new NullIconResolver(); | ||
$this->assertNull($resolver->resolve()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters