Skip to content

Commit 4a49552

Browse files
committed
Helpers in Base and Message arer moved to Segments trait,
removed sender and receiver from Base (use Interchange), rename a test, improve composition so that before encoding the objects can be inspected from Interchange (Interchange may contain a group of Messages which can contain Segments)
1 parent 7d5b779 commit 4a49552

12 files changed

+361
-297
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
/phpunit.gitlab.xml export-ignore
1212
/gitlab-test-mysql.sh export-ignore
1313
/.gitlab-ci.yml export-ignore
14+
codeCoverage/

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ coverage
1111
coverage.xml
1212
phpunit.local.xml
1313
.phpunit.result.cache
14+
.phpunit.cache/
1415
composer.lock
1516
/tests/_output

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"codestyle:lint": "vendor/bin/php-cs-fixer fix --dry-run"
1616
},
1717
"require-dev": {
18-
"sabas/edifact": "^0.4.1",
19-
"phpunit/phpunit": "~8.0",
18+
"sabas/edifact": "^1.0",
19+
"phpunit/phpunit": "~11.0",
2020
"friendsofphp/php-cs-fixer": "^3.9.5"
2121
}
2222
}

phpunit.xml

+11-19
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
bootstrap="vendor/autoload.php"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false">
11-
<testsuites>
12-
<testsuite name="EdiFact-Generator">
13-
<directory>./tests/GeneratorTest</directory>
14-
</testsuite>
15-
</testsuites>
16-
<filter>
17-
<whitelist processUncoveredFilesFromWhitelist="true">
18-
<directory suffix=".php">./src</directory>
19-
</whitelist>
20-
</filter>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.4/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" cacheDirectory=".phpunit.cache" requireCoverageMetadata="false" beStrictAboutCoverageMetadata="true" displayDetailsOnTestsThatTriggerDeprecations="true" displayDetailsOnTestsThatTriggerErrors="true" displayDetailsOnTestsThatTriggerNotices="true" displayDetailsOnTestsThatTriggerWarnings="true">
3+
<testsuites>
4+
<testsuite name="EdiFact-Generator">
5+
<directory>./tests/GeneratorTest</directory>
6+
</testsuite>
7+
</testsuites>
8+
<source>
9+
<include>
10+
<directory suffix=".php">./src</directory>
11+
</include>
12+
</source>
2113
</phpunit>

src/Generator/Base.php

+5-129
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@
22

33
namespace EDI\Generator;
44

5+
use EDI\Generator\Traits\Segments;
6+
57
/**
68
* Class Base
79
*
810
* @package EDI\Generator
911
*/
1012
class Base
1113
{
14+
use Segments;
15+
1216
/** @var array */
1317
protected $messageContent = [];
1418

1519
/** @var array */
1620
protected $composed;
1721

18-
/** @var string */
19-
protected $sender;
20-
21-
/** @var string */
22-
protected $receiver;
23-
2422
/** @var string */
2523
// protected $managingOrganisation = '89';
2624

@@ -33,7 +31,7 @@ public function addKeyToCompose($keyName)
3331
}
3432

3533
/**
36-
* compose message by keys givven in an ordered array
34+
* compose message by keys given in an ordered array
3735
*
3836
* @param array $keys
3937
*
@@ -74,46 +72,6 @@ public function getComposed()
7472
return $this->composed;
7573
}
7674

77-
/**
78-
* @return string
79-
*/
80-
public function getSender()
81-
{
82-
return $this->sender;
83-
}
84-
85-
/**
86-
* @param string $sender
87-
*
88-
* @return $this
89-
*/
90-
public function setSender($sender)
91-
{
92-
$this->sender = $sender;
93-
94-
return $this;
95-
}
96-
97-
/**
98-
* @return string
99-
*/
100-
public function getReceiver()
101-
{
102-
return $this->receiver;
103-
}
104-
105-
/**
106-
* @param string $receiver
107-
*
108-
* @return $this
109-
*/
110-
public function setReceiver($receiver)
111-
{
112-
$this->receiver = $receiver;
113-
114-
return $this;
115-
}
116-
11775
/**
11876
* Crop String to max char length
11977
*
@@ -151,86 +109,4 @@ protected function isAllowed($value, $array, $errorMessage = null)
151109
}
152110
}
153111

154-
/**
155-
* SEGMENT UTILITIES
156-
*/
157-
158-
/**
159-
* @param string, $functionCode
160-
* @param $identifier
161-
*
162-
* @return array|bool
163-
*/
164-
protected static function addRFFSegment($functionCode, $identifier)
165-
{
166-
if (empty($identifier)) {
167-
return false;
168-
}
169-
170-
return [
171-
'RFF',
172-
[
173-
$functionCode,
174-
self::maxChars($identifier, 35),
175-
],
176-
];
177-
}
178-
179-
/**
180-
* @param string|\DateTime $date
181-
* @param string $type
182-
* @param int $formatQualifier
183-
*
184-
* @return array
185-
* @throws EdifactException
186-
* @see http://www.unece.org/trade/untdid/d96a/trsd/trsddtm.htm
187-
*/
188-
protected static function addDTMSegment($date, $type, $formatQualifier = EdifactDate::DATE)
189-
{
190-
$data = [];
191-
$data[] = (string) $type;
192-
if (!empty($date)) {
193-
$data[] = EdifactDate::get($date, $formatQualifier);
194-
$data[] = (string) $formatQualifier;
195-
}
196-
197-
return ['DTM', $data];
198-
}
199-
200-
/**
201-
* @param $documentNumber
202-
* @param $type
203-
*
204-
* @return array
205-
*/
206-
public static function addBGMSegment($documentNumber, $type)
207-
{
208-
return [
209-
'BGM',
210-
[
211-
$type,
212-
'',
213-
'89',
214-
],
215-
$documentNumber,
216-
];
217-
}
218-
219-
/**
220-
* @param $qualifier
221-
* @param $value
222-
*
223-
* @return array
224-
*/
225-
public static function addMOASegment($qualifier, $value)
226-
{
227-
return [
228-
'MOA',
229-
[
230-
'',
231-
(string) $qualifier,
232-
EdiFactNumber::convert($value),
233-
],
234-
];
235-
}
236112
}

src/Generator/Interchange.php

+21-2
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,19 @@ public function setCharset($identifier, $version)
6565
return $this;
6666
}
6767

68+
/**
69+
* Set the application reference
70+
* $appref Application reference
71+
* @param $appref
72+
* @return $this
73+
*/
6874
public function setApplicationReference($appref)
6975
{
7076
$this->appref = $appref;
7177

7278
return $this;
7379
}
7480

75-
7681
/**
7782
* Add a Message to the Interchange
7883
* @param $msg
@@ -85,6 +90,15 @@ public function addMessage($msg)
8590
return $this;
8691
}
8792

93+
/**
94+
* Return the messages array
95+
* @return array
96+
*/
97+
public function getMessages()
98+
{
99+
return $this->messages;
100+
}
101+
88102
/**
89103
* Format the Interchange segments
90104
* @return $this
@@ -94,12 +108,17 @@ public function compose()
94108
$temp = [];
95109
$unb = ['UNB', $this->charset, $this->sender, $this->receiver, [$this->date, $this->time], $this->interchangeCode];
96110
if ($this->appref !== null) {
111+
$unb[] = '';
97112
$unb[] = $this->appref;
98113
}
99114

100115
$temp[] = $unb;
101116
foreach ($this->messages as $msg) {
102-
foreach ($msg->getComposed() as $i) {
117+
$msgContent = $msg->getComposed();
118+
if ($msgContent === null) {
119+
$msgContent = $msg->compose()->getComposed();
120+
}
121+
foreach ($msgContent as $i) {
103122
$temp[] = $i;
104123
}
105124
}

0 commit comments

Comments
 (0)