Skip to content

Commit c748d38

Browse files
committed
Complete test coverage of Parser and Encoder
1 parent 5600d59 commit c748d38

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

src/EDI/Encoder.php

-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public function encodeSegment($row)
8181
} else {
8282
foreach ($row[$i] as &$temp) {
8383
$temp = $this->escapeValue($temp);
84-
//var_dump($temp);
8584
}
8685
$elm = implode($this->sepComp, $row[$i]);
8786
}

tests/EDITest/EncoderTest.php

+16
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,20 @@ public function testEncodeMessageNotWrapped()
3535
$res = $e->get();
3636
$this->assertEquals($expected, $res);
3737
}
38+
39+
public function testEncodeMessageWithUNA()
40+
{
41+
$message=[["LOC","9","VNSGN"],["LOC","11","ITGOA"],["MEA","WT","",["KGM","9040"]]];
42+
$expected="UNA:+.? 'LOC+9+VNSGN'LOC+11+ITGOA'MEA+WT++KGM:9040'";
43+
$e = new Encoder($message);
44+
$e->setUNA("&+.?");
45+
$e->disableUNA();
46+
$e->enableUNA();
47+
$res = $e->get();
48+
$this->assertEquals($expected, $res);
49+
$e->setUNA("&+.? '", true);
50+
$res2 = $e->get();
51+
$expected2="UNA&+.? 'LOC+9+VNSGN'LOC+11+ITGOA'MEA+WT++KGM&9040'";
52+
$this->assertEquals($expected2, $res2);
53+
}
3854
}

tests/EDITest/InterpreterTest.php

+37
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,41 @@ public function testDESADV()
7575
$this->assertCount(2, $interpreter->getServiceSegments());
7676
$this->assertEquals([], $interpreter->getErrors());
7777
}
78+
79+
public function testMissingUNTUNZ()
80+
{
81+
$edi = "UNB+UNOA:2+LBCTI:01+OOCLIES:ZZ+160414:0307+1865'UNH+1907+BAPLIE:D:95B:UN:SMDG20'BGM++391651645'";
82+
$parser = new Parser($edi);
83+
$mapping = new \EDI\Mapping\MappingProvider('D95B');
84+
$analyser = new Analyser();
85+
$segs = $analyser->loadSegmentsXml($mapping->getSegments());
86+
$svc = $analyser->loadSegmentsXml($mapping->getServiceSegments(3));
87+
88+
$interpreter = new Interpreter($mapping->getMessage('BAPLIE'), $segs, $svc);
89+
$interpreter->prepare($parser->get());
90+
$errors = $interpreter->getErrors();
91+
$this->assertCount(2, $errors);
92+
$segments = [];
93+
foreach ($errors as $err) {
94+
$segments[] = $err['segmentId'];
95+
}
96+
$this->assertEquals(['UNZ', 'UNT'], $segments);
97+
}
98+
99+
public function testTooManyElements()
100+
{
101+
$edi = "UNB+UNOA:2+LBCTI:01+OOCLIES:ZZ:AA:DD+160414:0307+1865'UNZ+1+1865+TEST+TEST'";
102+
$parser = new Parser($edi);
103+
$mapping = new \EDI\Mapping\MappingProvider('D95B');
104+
$analyser = new Analyser();
105+
$segs = $analyser->loadSegmentsXml($mapping->getSegments());
106+
$svc = $analyser->loadSegmentsXml($mapping->getServiceSegments(3));
107+
108+
$interpreter = new Interpreter($mapping->getMessage('BAPLIE'), $segs, $svc);
109+
$p = $interpreter->prepare($parser->get());
110+
$errors = $interpreter->getErrors();
111+
$svcSegs = $interpreter->getServiceSegments();
112+
$this->assertCount(0, $errors);
113+
$this->assertArrayHasKey('Extension2', $svcSegs['interchangeTrailer']);
114+
}
78115
}

tests/EDITest/ParserTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,19 @@ public function testUNHData()
143143
$this->assertEquals("COARRI", $p->getMessageFormat());
144144
$this->assertEquals("95B", $p->getMessageDirectory());
145145
}
146+
147+
public function testUNHDataOnlyFormat()
148+
{
149+
$arr= ["UNH+1452515553811+COARRI'"];
150+
$p=new Parser($arr);
151+
$this->assertEquals("COARRI", $p->getMessageFormat());
152+
$this->assertNull($p->getMessageDirectory());
153+
}
154+
155+
public function testUNAString()
156+
{
157+
$p=new Parser(["UNA:+.? '", "UNH+123", "LOC+9+VNSGN'"]);
158+
$result=$p->errors();
159+
$this->assertEmpty($result);
160+
}
146161
}

0 commit comments

Comments
 (0)