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

AbstractFactoryTest::getContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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