Skip to content
This repository was archived by the owner on Dec 31, 2022. It is now read-only.

Commit 4ce9d9c

Browse files
authored
Merge pull request #20 from peter279k/improve_assertions
Improve PHPUnit assertions
2 parents 535faf7 + 985fe42 commit 4ce9d9c

2 files changed

Lines changed: 23 additions & 23 deletions

File tree

tests/StreamFactoryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public function testCreateStream()
2929

3030
$this->assertTrue($stream->isWritable());
3131

32-
$this->assertEquals('php://temp', $stream->getMetadata('uri'));
32+
$this->assertSame('php://temp', $stream->getMetadata('uri'));
3333

34-
$this->assertEquals(0, $stream->tell());
34+
$this->assertSame(0, $stream->tell());
3535

36-
$this->assertEquals($content, (string) $stream);
36+
$this->assertSame($content, (string) $stream);
3737

3838
$stream->close();
3939
}
@@ -69,7 +69,7 @@ public function testCreateStreamFromUnopenableFile()
6969
public function testCreateStreamWithTemporaryFile()
7070
{
7171
$stream = (new StreamFactory)->createStreamFromTemporaryFile('foo');
72-
$this->assertTrue(\file_exists($stream->getMetadata('uri')));
72+
$this->assertFileExists($stream->getMetadata('uri'));
7373
$this->assertSame('foo', \file_get_contents($stream->getMetadata('uri')));
7474
}
7575
}

tests/StreamTest.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testDetach()
4747
{
4848
$stream = new Stream($this->handle);
4949

50-
$this->assertEquals($this->handle, $stream->detach());
50+
$this->assertSame($this->handle, $stream->detach());
5151
$this->assertStreamResourceEquals($stream, null);
5252
$this->assertNull($stream->detach());
5353
}
@@ -82,13 +82,13 @@ public function testTell()
8282
$stream = new Stream($this->handle);
8383

8484
\rewind($this->handle);
85-
$this->assertEquals(0, $stream->tell());
85+
$this->assertSame(0, $stream->tell());
8686

8787
\fwrite($this->handle, $string, $length);
88-
$this->assertEquals($length, $stream->tell());
88+
$this->assertSame($length, $stream->tell());
8989

9090
\rewind($this->handle);
91-
$this->assertEquals(0, $stream->tell());
91+
$this->assertSame(0, $stream->tell());
9292
}
9393

9494
public function testTellUnresourceable()
@@ -121,7 +121,7 @@ public function testRewind()
121121

122122
\fwrite($this->handle, $string, $length);
123123
$stream->rewind();
124-
$this->assertEquals(0, \ftell($this->handle));
124+
$this->assertSame(0, \ftell($this->handle));
125125
}
126126

127127
public function testRewindUnresourceable()
@@ -145,7 +145,7 @@ public function testSeek()
145145
\fwrite($this->handle, $string, $length);
146146
\rewind($this->handle);
147147
$stream->seek($length, \SEEK_SET);
148-
$this->assertEquals($length, \ftell($this->handle));
148+
$this->assertSame($length, \ftell($this->handle));
149149
}
150150

151151
public function testSeekUnresourceable()
@@ -175,10 +175,10 @@ public function testWrite()
175175

176176
$stream = new Stream($this->handle);
177177

178-
$this->assertEquals($length, $stream->write($string));
178+
$this->assertSame($length, $stream->write($string));
179179

180180
\rewind($this->handle);
181-
$this->assertEquals($string, \fread($this->handle, $length));
181+
$this->assertSame($string, \fread($this->handle, $length));
182182
}
183183

184184
public function testWriteUnresourceable()
@@ -219,7 +219,7 @@ public function testRead()
219219

220220
\fwrite($this->handle, $string);
221221
\rewind($this->handle);
222-
$this->assertEquals($string, $stream->read($length));
222+
$this->assertSame($string, $stream->read($length));
223223
}
224224

225225
public function testReadUnresourceable()
@@ -251,7 +251,7 @@ public function testGetContents()
251251

252252
\fwrite($this->handle, $string);
253253
\rewind($this->handle);
254-
$this->assertEquals($string, $stream->getContents());
254+
$this->assertSame($string, $stream->getContents());
255255
}
256256

257257
public function testGetContentsUnresourceable()
@@ -278,7 +278,7 @@ public function testGetMetadata()
278278
{
279279
$stream = new Stream($this->handle);
280280

281-
$this->assertEquals(
281+
$this->assertSame(
282282
\stream_get_meta_data($this->handle),
283283
$stream->getMetadata()
284284
);
@@ -288,12 +288,12 @@ public function testGetMetadataWithKey()
288288
{
289289
$stream = new Stream($this->handle);
290290

291-
$this->assertEquals(
291+
$this->assertSame(
292292
'php://memory',
293293
$stream->getMetadata('uri')
294294
);
295295

296-
$this->assertEquals(
296+
$this->assertSame(
297297
null,
298298
$stream->getMetadata('undefined')
299299
);
@@ -315,10 +315,10 @@ public function testGetSize()
315315
$stream = new Stream($this->handle);
316316

317317
\fwrite($this->handle, $string);
318-
$this->assertEquals($length, $stream->getSize());
318+
$this->assertSame($length, $stream->getSize());
319319

320320
\ftruncate($this->handle, 0);
321-
$this->assertEquals(0, $stream->getSize());
321+
$this->assertSame(0, $stream->getSize());
322322
}
323323

324324
public function testGetSizeUnresourceable()
@@ -337,22 +337,22 @@ public function testToString()
337337
$stream = new Stream($this->handle);
338338

339339
\fwrite($this->handle, $string);
340-
$this->assertEquals($string, (string) $stream);
340+
$this->assertSame($string, (string) $stream);
341341
}
342342

343343
public function testToStringUnresourceable()
344344
{
345345
$stream = new Stream($this->handle);
346346

347347
$stream->close();
348-
$this->assertEquals('', (string) $stream);
348+
$this->assertSame('', (string) $stream);
349349
}
350350

351351
public function testToStringUnreadable()
352352
{
353353
$stream = new Stream(\STDOUT);
354354

355-
$this->assertEquals('', (string) $stream);
355+
$this->assertSame('', (string) $stream);
356356
}
357357

358358
public function testExceptions()
@@ -370,6 +370,6 @@ private function assertStreamResourceEquals(StreamInterface $stream, $expected)
370370

371371
$property->setAccessible(true);
372372

373-
return $this->assertEquals($property->getValue($stream), $expected);
373+
return $this->assertSame($property->getValue($stream), $expected);
374374
}
375375
}

0 commit comments

Comments
 (0)