Passed
Push — master ( 592044...6c5e57 )
by Korotkov
01:47
created

AbstractFactoryTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 12
dl 0
loc 37
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testXML() 0 9 1
A testJson() 0 6 1
A setUp() 0 3 1
A getContent() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author    : Korotkov Danila <[email protected]>
7
 * @license   https://mit-license.org/ MIT
8
 */
9
10
namespace Creational\AbstractFactory\Tests;
11
12
use Creational\AbstractFactory\XMLFactory;
13
use Creational\AbstractFactory\JsonFactory;
14
use PHPUnit\Framework\TestCase as PHPUnit_Framework_TestCase;
15
16
/**
17
 * Class AbstractFactoryTest
18
 * @package Creational\AbstractFactory\Tests
19
 */
20
class AbstractFactoryTest extends PHPUnit_Framework_TestCase
21
{
22
    /**
23
     * @var string
24
     */
25
    private $content;
26
27
    protected function setUp(): void
28
    {
29
        $this->content = 'Message';
30
    }
31
32
    public function testJson()
33
    {
34
        $content     = \json_encode($this->content);
35
        $jsonFactory = new JsonFactory();
36
37
        $this->assertEquals($jsonFactory->createMessage($this->getContent())->getContent(), $content);
38
    }
39
40
    public function testXML()
41
    {
42
        $dom     = new \DOMDocument("1.0", "utf-8");
43
        $content = $dom->createElement("content", $this->getContent());
44
        $dom->appendChild($content);
45
        $xmlFactory = new XMLFactory();
46
47
48
        $this->assertEquals($xmlFactory->createMessage($this->getContent())->getContent(), $dom->saveXML());
49
    }
50
51
    /**
52
     * @return string
53
     */
54
    public function getContent(): string
55
    {
56
        return $this->content;
57
    }
58
}
59