Failed Conditions
Push — master ( 65cf51...40aca8 )
by Adrien
03:16
created

ReaderTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testReadWrongFormat() 0 11 1
A testReadFileWithNoXsdValidation() 0 8 1
A testReadEmptyDocument() 0 5 1
A testReadFile() 0 5 1
A getDefaultConfig() 0 6 1
1
<?php
2
3
namespace Genkgo\TestCamt\Unit;
4
5
use DOMDocument;
6
use Genkgo\TestCamt\AbstractTestCase;
7
use Genkgo\Camt\DTO;
8
use Genkgo\Camt\Camt053\MessageFormat;
9
use Genkgo\Camt\Config;
10
use Genkgo\Camt\Exception\ReaderException;
11
use Genkgo\Camt\Reader;
12
13
class ReaderTest extends AbstractTestCase
14
{
15
    protected function getDefaultConfig()
16
    {
17
        $config = new Config();
18
        $config->addMessageFormat(new MessageFormat\V02());
19
20
        return $config;
21
    }
22
23
    public function testReadEmptyDocument()
24
    {
25
        $this->expectException(ReaderException::class);
26
        $reader = new Reader($this->getDefaultConfig());
27
        $reader->readDom(new DOMDocument('1.0', 'UTF-8'));
28
    }
29
30
    public function testReadWrongFormat()
31
    {
32
        $this->expectException(ReaderException::class);
33
34
        $dom = new DOMDocument('1.0', 'UTF-8');
35
        $root = $dom->createElement('Document');
36
        $root->setAttribute('xmlns', 'unknown');
37
        $dom->appendChild($root);
38
39
        $reader = new Reader($this->getDefaultConfig());
40
        $reader->readDom($dom);
41
    }
42
43
    public function testReadFile()
44
    {
45
        $reader = new Reader(Config::getDefault());
46
        $message = $reader->readFile(__DIR__.'/Camt053/Stubs/camt053.v2.minimal.xml');
47
        $this->assertInstanceOf(DTO\Message::class, $message);
48
    }
49
50
51
    public function testReadFileWithNoXsdValidation()
52
    {
53
        $config = Config::getDefault();
54
        $config->disableXsdValidation();
55
56
        $reader = new Reader($config);
57
        $message = $reader->readFile(__DIR__.'/Camt053/Stubs/camt053.v2.minimal.xml');
58
        $this->assertInstanceOf(DTO\Message::class, $message);
59
    }
60
}
61