1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Odiseo\SyliusReportPlugin\Renderer; |
4
|
|
|
|
5
|
|
|
use Odiseo\SyliusReportPlugin\DataFetcher\Data; |
6
|
|
|
use Odiseo\SyliusReportPlugin\Model\ReportInterface; |
7
|
|
|
use Odiseo\SyliusReportPlugin\Renderer\DefaultRenderers; |
8
|
|
|
use Odiseo\SyliusReportPlugin\Renderer\DelegatingRenderer; |
9
|
|
|
use Odiseo\SyliusReportPlugin\Renderer\DelegatingRendererInterface; |
10
|
|
|
use Odiseo\SyliusReportPlugin\Renderer\RendererInterface; |
11
|
|
|
use Odiseo\SyliusReportPlugin\Renderer\TableRenderer; |
12
|
|
|
use PhpSpec\ObjectBehavior; |
13
|
|
|
use Sylius\Component\Registry\ServiceRegistryInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @author Diego D'amico <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
class DelegatingRendererSpec extends ObjectBehavior |
19
|
|
|
{ |
20
|
|
|
function let(ServiceRegistryInterface $registry) |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
$this->beConstructedWith($registry); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
function it_is_initializable() |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$this->shouldHaveType(DelegatingRenderer::class); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
function it_should_implement_delegating_renderer_interface() |
31
|
|
|
{ |
32
|
|
|
$this->shouldImplement(DelegatingRendererInterface::class); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
function it_get_the_renderer_with_given_report(ReportInterface $report, ServiceRegistryInterface $registry) |
36
|
|
|
{ |
37
|
|
|
$report->getRenderer()->willReturn(DefaultRenderers::TABLE); |
38
|
|
|
$registry->get(DefaultRenderers::TABLE)->willReturn(TableRenderer::class); |
39
|
|
|
$this->getRenderer($report)->shouldReturn(TableRenderer::class); |
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
function it_throws_an_exception_if_report_has_not_renderer(ReportInterface $report, ServiceRegistryInterface $registry) |
43
|
|
|
{ |
44
|
|
|
$report->getRenderer()->willReturn(null); |
45
|
|
|
$registry->get(DefaultRenderers::TABLE)->willReturn(TableRenderer::class); |
46
|
|
|
|
47
|
|
|
$this |
48
|
|
|
->shouldThrow(new \InvalidArgumentException('Cannot render data for ReportInterface instance without renderer defined.')) |
49
|
|
|
->during('getRenderer', [$report]) |
50
|
|
|
; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
function it_render_with_given_report_configuration_and_data(ReportInterface $report, RendererInterface $renderer, Data $data, ServiceRegistryInterface $registry) |
54
|
|
|
{ |
55
|
|
|
$report->getRenderer()->willReturn(DefaultRenderers::TABLE); |
56
|
|
|
$registry->get(DefaultRenderers::TABLE)->willReturn($renderer); |
57
|
|
|
$renderer->render($report, $data)->willReturn('<div>Table render</div>'); |
58
|
|
|
|
59
|
|
|
$this->render($report, $data)->shouldReturn('<div>Table render</div>'); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.