Skip to content

Commit 3c776ff

Browse files
committed
Fix #96 - Error in external id parsing
1 parent bb72e94 commit 3c776ff

2 files changed

Lines changed: 98 additions & 3 deletions

File tree

src/AbraFlexi/Relation.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* This file is part of the SpojeNet\AbraFlexi package.
77
*
88
* (c) 2019-2024 SpojeNet s.r.o. <http://spoje.net/>
9-
* (c) 2025 SpojeNetIT s.r.o. <http://spojenet.cz/>
9+
* (c) 2025-2026 SpojeNetIT s.r.o. <http://spojenet.cz/>
1010
*
1111
* For the full copyright and license information, please view the LICENSE
1212
* file that was distributed with this source code.
@@ -108,7 +108,11 @@ public function offsetUnset(mixed $offset): void
108108
*/
109109
public static function fromExtId(string $extIdRaw, string $column): self
110110
{
111-
[,$ext,$extId] = explode(':', $extIdRaw);
111+
if (substr_count($extIdRaw, ':') > 1) {
112+
[,$ext,$extId] = explode(':', $extIdRaw);
113+
} else {
114+
[$ext,$extId] = explode(':', $extIdRaw);
115+
}
112116

113117
return new self($extIdRaw, $ext, $extId, trim($column.' '.$ext).':'.$extId);
114118
}

tests/src/AbraFlexi/RelationTest.php

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* This file is part of the SpojeNet\AbraFlexi package.
77
*
88
* (c) 2019-2024 SpojeNet s.r.o. <http://spoje.net/>
9-
* (c) 2025 SpojeNetIT s.r.o. <http://spojenet.cz/>
9+
* (c) 2025-2026 SpojeNetIT s.r.o. <http://spojenet.cz/>
1010
*
1111
* For the full copyright and license information, please view the LICENSE
1212
* file that was distributed with this source code.
@@ -50,6 +50,12 @@ protected function tearDown(): void
5050
*/
5151
public function testToString(): void
5252
{
53+
$relationExt = new Relation('ext:e810294f-ab67-4cb0-89bf-aeadd0fb94d2', 'banka');
54+
$this->assertSame('ext:e810294f-ab67-4cb0-89bf-aeadd0fb94d2', (string) $relationExt);
55+
56+
$relationExt2 = new Relation('ext:test:123', 'faktura-prijata');
57+
$this->assertSame('ext:test:123', (string) $relationExt2);
58+
5359
$relation = new Relation('CODE123', 'faktura-vydana');
5460
$this->assertSame('CODE123', (string) $relation);
5561

@@ -68,4 +74,89 @@ public function testgetRelationTarget(): void
6874
// Assert that the record code matches the expected value.
6975
$this->assertEquals('code:CZ', $target->getRecordCode());
7076
}
77+
78+
/**
79+
* @covers \AbraFlexi\Relation::offsetExists
80+
*/
81+
public function testoffsetExists(): void
82+
{
83+
// Initially, no data is set, so any offset should not exist
84+
$this->assertFalse($this->object->offsetExists('foo'));
85+
// Set a value and check existence
86+
$this->object->offsetSet('foo', 'bar');
87+
$this->assertTrue($this->object->offsetExists('foo'));
88+
}
89+
90+
/**
91+
* @covers \AbraFlexi\Relation::offsetGet
92+
*/
93+
public function testoffsetGet(): void
94+
{
95+
// No value set, should return null
96+
$this->assertNull($this->object->offsetGet('foo'));
97+
// Set a value and get it
98+
$this->object->offsetSet('foo', 'bar');
99+
$this->assertSame('bar', $this->object->offsetGet('foo'));
100+
}
101+
102+
/**
103+
* @covers \AbraFlexi\Relation::offsetSet
104+
*/
105+
public function testoffsetSet(): void
106+
{
107+
// Set a value and verify it is set
108+
$this->object->offsetSet('foo', 'bar');
109+
$this->assertSame('bar', $this->object->offsetGet('foo'));
110+
}
111+
112+
/**
113+
* @covers \AbraFlexi\Relation::offsetUnset
114+
*/
115+
public function testoffsetUnset(): void
116+
{
117+
// Set a value, then unset it and check
118+
$this->object->offsetSet('foo', 'bar');
119+
$this->assertTrue($this->object->offsetExists('foo'));
120+
$this->object->offsetUnset('foo');
121+
$this->assertFalse($this->object->offsetExists('foo'));
122+
}
123+
124+
/**
125+
* @covers \AbraFlexi\Relation::fromExtId
126+
*/
127+
public function testfromExtId(): void
128+
{
129+
$extIdRaw = 'ext:bank:12345';
130+
$column = 'id';
131+
$relation = Relation::fromExtId($extIdRaw, $column);
132+
$this->assertInstanceOf(Relation::class, $relation);
133+
$this->assertSame($extIdRaw, $relation->value);
134+
$this->assertSame('bank', $relation->target);
135+
$this->assertSame('12345', $relation->ref);
136+
$this->assertSame('id bank:12345', $relation->showAs);
137+
138+
$extUuid = 'ext:e810294f-ab67-4cb0-89bf-aeadd0fb94d2';
139+
140+
$relation2 = Relation::fromExtId($extUuid, $column);
141+
$this->assertSame($extUuid, $relation2->value);
142+
}
143+
144+
/**
145+
* @covers \AbraFlexi\Relation::fromTypDokl
146+
*/
147+
public function testfromTypDokl(): void
148+
{
149+
$typDokl = [
150+
'kod' => 'FV',
151+
'typDoklK' => 'faktura-vydana',
152+
'id' => '789',
153+
'typDoklK@showAs' => 'Faktura vydaná',
154+
];
155+
$relation = Relation::fromTypDokl($typDokl);
156+
$this->assertInstanceOf(Relation::class, $relation);
157+
$this->assertSame('FV', $relation->value);
158+
$this->assertSame('faktura-vydana', $relation->target);
159+
$this->assertSame('789', $relation->ref);
160+
$this->assertSame('Faktura vydaná', $relation->showAs);
161+
}
71162
}

0 commit comments

Comments
 (0)