Skip to content

Commit 7aa7272

Browse files
committed
Rewrite tests to work w/o accessing protected members via reflection
1 parent 6290081 commit 7aa7272

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

src/test/php/rdbms/unittest/tds/TdsDataStreamTest.class.php

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,6 @@ protected function headerWith($length, $last= true) {
5353
return pack('CCnnCc', 0x04, $last ? 0x01 : 0x00, $length + 8, 0x00, 0x00, 0x00);
5454
}
5555

56-
/**
57-
* Assertion helper
58-
*
59-
* @param string bytes
60-
* @param rdbms.tds.TdsDataStream str
61-
* @throws unittest.AssertionFailedError
62-
*/
63-
protected function assertBytes($bytes, $str) {
64-
$field= typeof($str)->getField('sock')->setAccessible(true);
65-
Assert::equals(new Bytes($bytes), new Bytes($field->get($str)->bytes));
66-
}
67-
6856
#[Test, Expect(TdsProtocolException::class)]
6957
public function nullHeader() {
7058
$this->newDataStream(null)->read(1);
@@ -189,18 +177,22 @@ public function illegalPacketSize() {
189177

190178
#[Test]
191179
public function writeBytes() {
192-
$str= $this->newDataStream();
180+
$socket= self::$sock->newInstance();
181+
$str= new TdsDataStream($socket);
193182
$str->write(0x04, 'Login');
194-
$this->assertBytes($this->headerWith(5).'Login', $str);
183+
184+
Assert::equals(new Bytes($this->headerWith(5).'Login'), new Bytes($socket->bytes));
195185
}
196186

197187
#[Test]
198188
public function writeBytesSpanningMultiplePackets() {
199-
$str= $this->newDataStream('', 10);
189+
$socket= self::$sock->newInstance();
190+
$str= new TdsDataStream($socket, 10);
200191
$str->write(0x04, 'Test');
201-
$this->assertBytes(
202-
$this->headerWith(2, false).'Te'.$this->headerWith(2, true).'st',
203-
$str
192+
193+
Assert::equals(
194+
new Bytes($this->headerWith(2, false).'Te'.$this->headerWith(2, true).'st'),
195+
new Bytes($socket->bytes),
204196
);
205197
}
206198
}

0 commit comments

Comments
 (0)