Skip to content

Commit 92fdf5a

Browse files
fixed test
1 parent c1a90cd commit 92fdf5a

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

src/protocol/v6/structures/Vector.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ class Vector implements IStructure
2020
public function __construct(
2121
public readonly Bytes $type_marker,
2222
public readonly Bytes $data
23-
) {
24-
}
23+
) {}
2524

2625
public function __toString(): string
2726
{
@@ -78,10 +77,6 @@ public static function encode(array $data, ?TypeMarker $type = null): self
7877
}
7978
}
8079

81-
if ($type === null) {
82-
throw new \InvalidArgumentException('Unsupported data type for vector');
83-
}
84-
8580
// Pack the data
8681
$packed = [];
8782
$littleEndian = unpack('S', "\x01\x00")[1] === 1;
@@ -128,10 +123,10 @@ public function decode(): array
128123
default:
129124
throw new \InvalidArgumentException('Unknown vector type marker: ' . $this->type_marker[0]);
130125
}
131-
126+
132127
$output = [];
133128
$littleEndian = unpack('S', "\x01\x00")[1] === 1;
134-
foreach(mb_str_split((string)$this->data, $size, '8bit') as $value) {
129+
foreach (mb_str_split((string)$this->data, $size, '8bit') as $value) {
135130
$output[] = unpack($unpackFormat, in_array($unpackFormat, self::$endiannessFormats) && $littleEndian ? strrev($value) : $value)[1];
136131
}
137132

tests/structures/V6/StructuresTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,16 @@ public function testVector(AProtocol $protocol)
4343
//unpack
4444
$res = iterator_to_array(
4545
$protocol
46-
->run('CYPHER 25 RETURN vector([1.05, 0.123, 5], 3, FLOAT),
46+
->run(
47+
'CYPHER 25 RETURN vector([1.05, 0.123, 5], 3, FLOAT),
4748
vector([1.05, 0.123, 5], 3, FLOAT32),
4849
vector([5, 543, 342765], 3, INTEGER),
4950
vector([5, -60, 120], 3, INTEGER8),
5051
vector([5, -20000, 30000], 3, INTEGER16),
5152
vector([5, -2000000000, 2000000000], 3, INTEGER32)',
52-
[], ['mode' => 'r'])
53+
[],
54+
['mode' => 'r']
55+
)
5356
->pull()
5457
->getResponses(),
5558
false
@@ -106,8 +109,6 @@ public function testVector(AProtocol $protocol)
106109
public function testVectorExceptions()
107110
{
108111
$this->expectException(\InvalidArgumentException::class);
109-
Vector::encode([]);
110-
$this->expectException(\InvalidArgumentException::class);
111-
Vector::encode(range(1, 5000));
112+
Vector::encode(['abc', 'def']);
112113
}
113114
}

0 commit comments

Comments
 (0)