Completed
Pull Request — master (#2)
by Korotkov
04:20
created

AbstractFactoryTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 31
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testXML() 0 7 1
A testJson() 0 4 1
A setUp() 0 4 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\Handler;
13
use Creational\AbstractFactory\XMLFactory;
14
use Creational\AbstractFactory\JsonFactory;
15
use PHPUnit\Framework\TestCase as PHPUnit_Framework_TestCase;
16
17
/**
18
 * Class AbstractFactoryTest
19
 * @package Creational\AbstractFactory\Tests
20
 */
21
class AbstractFactoryTest extends PHPUnit_Framework_TestCase
22
{
23
24
    /**
25
     * @var Handler
26
     */
27
    protected $handler;
28
    /**
29
     * @var string
30
     */
31
    protected $content;
32
33
    protected function setUp(): void
34
    {
35
        $this->handler = new Handler();
36
        $this->content = 'Message';
37
    }
38
39
    public function testJson()
40
    {
41
        $content = json_encode($this->content);
42
        $this->assertEquals($this->handler->getMessage(new JsonFactory(), $this->content), $content);
43
    }
44
45
    public function testXML()
46
    {
47
        $dom     = new \DOMDocument("1.0", "utf-8");
48
        $content = $dom->createElement("content", $this->content);
49
        $dom->appendChild($content);
50
51
        $this->assertEquals($this->handler->getMessage(new XMLFactory(), $this->content), $dom->saveXML());
52
    }
53
}
54