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