Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 0.2 #9

Merged
merged 11 commits into from
Oct 4, 2017
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ a `CouldNotRenderExceptionInterface` MUST be thrown.

### Interfaces
- [`RendererInterface`] - Represents a renderer, i.e. something that can produce output.
- [`ContextRendererInterface`] - A renderer that uses context to render.
- [`TemplateInterface`] - A renderer that uses context to render.
- [`BlockInterface`] - A renderer that has access to the render context, and is also [stringable].
- [`RendererAwareInterface`] - Something that exposes a renderer.
- [`ContextAwareInterface`] - Something that can have a rendering context retrieved.
- [`BlockAwareInterface`] - Something that can have a block retrieved.
- [`TemplateAwareInterface`] - Something that can have a template retrieved.
- [`RendererExceptionInterface`] - An exception that occurs in relation to a renderer, and is aware of it.
- [`CouldNotRenderExceptionInterface`] - A specialized renderer exception that signals problems during rendering.
- [`ContextRenderExceptionInterface`] - A specialized "could-not-render" exception that is aware
- [`TemplateRenderExceptionInterface`] - A specialized "could-not-render" exception that is aware
of the rendering context.


Expand All @@ -36,11 +37,12 @@ of the rendering context.
[stringable]: https://github.com/Dhii/stringable-interface

[`RendererInterface`]: src/RendererInterface.php
[`ContextRendererInterface`]: src/ContextRendererInterface.php
[`TemplateInterface`]: src/TemplateInterface.php
[`BlockInterface`]: src/BlockInterface.php
[`RendererAwareInterface`]: src/RendererAwareInterface.php
[`ContextAwareInterface`]: src/ContextAwareInterface.php
[`BlockAwareInterface`]: src/BlockAwareInterface.php
[`TemplateAwareInterface`]: src/TemplateAwareInterface.php
[`RendererExceptionInterface`]: src/Exception/RendererExceptionInterface.php
[`CouldNotRenderExceptionInterface`]: src/Exception/CouldNotRenderExceptionInterface.php
[`ContextRenderExceptionInterface`]: src/Exception/ContextRenderExceptionInterface.php
[`TemplateRenderExceptionInterface`]: src/Exception/ContextRenderExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
namespace Dhii\Output\Exception;

use Dhii\Output\ContextAwareInterface;
use Dhii\Output\ContextRendererInterface;
use Dhii\Output\TemplateInterface;

/**
* An exception that occurs when cannot render with a context.
*
* @since 0.1
*/
interface ContextRenderExceptionInterface extends
interface TemplateRenderExceptionInterface extends
CouldNotRenderExceptionInterface,
ContextAwareInterface
{
Expand All @@ -19,7 +19,7 @@ interface ContextRenderExceptionInterface extends
*
* @since 0.1
*
* @return ContextRendererInterface The renderer.
* @return TemplateInterface The renderer.
*/
public function getRenderer();
}
1 change: 1 addition & 0 deletions src/RendererInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Dhii\Output;

use Dhii\Util\String\StringableInterface as Stringable;
use Dhii\Output\Exception\CouldNotRenderExceptionInterface;
use Dhii\Output\Exception\RendererExceptionInterface;

Expand Down
20 changes: 20 additions & 0 deletions src/TemplateAwareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Dhii\Output;

/**
* Something that can have a template retrieved from it.
*
* @since [*next-version*]
*/
interface TemplateAwareInterface
{
/**
* Retrieves the template associated with this instance.
*
* @since [*next-version*]
*
* @return TemplateInterface|null The template, if any.
*/
public function getTemplate();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Dhii\Output;

use Dhii\Util\String\StringableInterface as Stringable;
use Dhii\Output\Exception\ContextRenderExceptionInterface;
use Dhii\Output\Exception\TemplateRenderExceptionInterface;
use Dhii\Output\Exception\RendererExceptionInterface;

/**
Expand All @@ -15,7 +15,7 @@
*
* @since 0.1
*/
interface ContextRendererInterface extends RendererInterface
interface TemplateInterface extends RendererInterface
{
/**
* Produce output based on context.
Expand All @@ -25,7 +25,7 @@ interface ContextRendererInterface extends RendererInterface
* @param mixed|null $context The context;
* something that can provide more information on how to perform rendering.
*
* @throws ContextRenderExceptionInterface If cannot render.
* @throws TemplateRenderExceptionInterface If cannot render.
* @throws RendererExceptionInterface Any other problem related to the renderer.
*
* @return string|Stringable The output.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ContextRenderExceptionInterfaceTest extends TestCase
*
* @since 0.1
*/
const TEST_SUBJECT_CLASSNAME = 'Dhii\Output\Exception\ContextRenderExceptionInterface';
const TEST_SUBJECT_CLASSNAME = 'Dhii\Output\Exception\TemplateRenderExceptionInterface';

/**
* Creates a new instance of the test subject.
Expand Down
51 changes: 51 additions & 0 deletions test/unit/TemplateAwareInterfaceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Dhii\Output\UnitTest;

use Xpmock\TestCase;
use Dhii\Output\TemplateAwareInterface as TestSubject;

/**
* Tests {@see TestSubject}.
*
* @since [*next-version*]
*/
class TemplateAwareInterfaceTest extends TestCase
{
/**
* The class name of the test subject.
*
* @since [*next-version*]
*/
const TEST_SUBJECT_CLASSNAME = 'Dhii\Output\TemplateAwareInterface';

/**
* Creates a new instance of the test subject.
*
* @since [*next-version*]
*
* @return TestSubject
*/
public function createInstance()
{
$mock = $this->mock(static::TEST_SUBJECT_CLASSNAME)
->getTemplate();

return $mock->new();
}

/**
* Tests whether a valid instance of the test subject can be created.
*
* @since [*next-version*]
*/
public function testCanBeCreated()
{
$subject = $this->createInstance();

$this->assertInstanceOf(
static::TEST_SUBJECT_CLASSNAME, $subject,
'Could not create a valid instance of the test subject.'
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Dhii\Output\UnitTest;

use Dhii\Output\ContextRendererInterface as TestSubject;
use Dhii\Output\TemplateInterface as TestSubject;
use Xpmock\TestCase;

/**
Expand All @@ -17,7 +17,7 @@ class ContextRendererInterfaceTest extends TestCase
*
* @since 0.1
*/
const TEST_SUBJECT_CLASSNAME = 'Dhii\Output\ContextRendererInterface';
const TEST_SUBJECT_CLASSNAME = 'Dhii\Output\TemplateInterface';

/**
* Creates a new instance of the test subject.
Expand Down