XmlWriterSpec   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 38
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_is_a_writer() 0 5 1
A it_writes_an_item() 0 19 1
1
<?php
2
3
namespace spec\Port\Xml;
4
5
use PhpSpec\ObjectBehavior;
6
use Prophecy\Argument;
7
8
class XmlWriterSpec extends ObjectBehavior
9
{
10
    function let(\XmlWriter $xmlWriter)
11
    {
12
        $this->beConstructedWith($xmlWriter, 'file', 'elements', 'element', '1.0', 'UTF-8');
13
    }
14
15
    function it_is_initializable()
16
    {
17
        $this->shouldHaveType('Port\Xml\XmlWriter');
18
    }
19
20
    function it_is_a_writer()
21
    {
22
        $this->shouldImplement('Port\Writer');
23
        $this->shouldImplement('Port\Writer\FlushableWriter');
24
    }
25
26
    function it_writes_an_item(\XmlWriter $xmlWriter)
27
    {
28
        $xmlWriter->openUri('file')->shouldBeCalled();
29
        $xmlWriter->startDocument('1.0', 'UTF-8')->shouldBeCalled();
30
        $xmlWriter->startElement('elements')->shouldBeCalled();
31
        $xmlWriter->startElement('element')->shouldBeCalledTimes(2);
32
        $xmlWriter->writeElement('key1', 'value1')->shouldBeCalled();
33
        $xmlWriter->writeElement('key2', 'value2')->shouldBeCalled();
34
        $xmlWriter->endElement()->shouldBeCalledTimes(3);
35
        $xmlWriter->endDocument()->shouldBeCalled();
36
        $xmlWriter->flush()->shouldBeCalled();
37
38
        $this->prepare();
39
40
        $this->writeItem(['key1' => 'value1']);
41
        $this->writeItem(['key2' => 'value2']);
42
43
        $this->finish();
44
    }
45
}
46