From 985fe42e2c0d1ecd144e576dadb22f717bbbff49 Mon Sep 17 00:00:00 2001 From: peter279k Date: Tue, 30 Nov 2021 14:11:30 +0800 Subject: [PATCH] Improve PHPUnit assertions --- tests/StreamFactoryTest.php | 8 ++++---- tests/StreamTest.php | 38 ++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/tests/StreamFactoryTest.php b/tests/StreamFactoryTest.php index 3af7b91..bc906ad 100644 --- a/tests/StreamFactoryTest.php +++ b/tests/StreamFactoryTest.php @@ -29,11 +29,11 @@ public function testCreateStream() $this->assertTrue($stream->isWritable()); - $this->assertEquals('php://temp', $stream->getMetadata('uri')); + $this->assertSame('php://temp', $stream->getMetadata('uri')); - $this->assertEquals(0, $stream->tell()); + $this->assertSame(0, $stream->tell()); - $this->assertEquals($content, (string) $stream); + $this->assertSame($content, (string) $stream); $stream->close(); } @@ -69,7 +69,7 @@ public function testCreateStreamFromUnopenableFile() public function testCreateStreamWithTemporaryFile() { $stream = (new StreamFactory)->createStreamFromTemporaryFile('foo'); - $this->assertTrue(\file_exists($stream->getMetadata('uri'))); + $this->assertFileExists($stream->getMetadata('uri')); $this->assertSame('foo', \file_get_contents($stream->getMetadata('uri'))); } } diff --git a/tests/StreamTest.php b/tests/StreamTest.php index 0acd4da..7ee6039 100644 --- a/tests/StreamTest.php +++ b/tests/StreamTest.php @@ -47,7 +47,7 @@ public function testDetach() { $stream = new Stream($this->handle); - $this->assertEquals($this->handle, $stream->detach()); + $this->assertSame($this->handle, $stream->detach()); $this->assertStreamResourceEquals($stream, null); $this->assertNull($stream->detach()); } @@ -82,13 +82,13 @@ public function testTell() $stream = new Stream($this->handle); \rewind($this->handle); - $this->assertEquals(0, $stream->tell()); + $this->assertSame(0, $stream->tell()); \fwrite($this->handle, $string, $length); - $this->assertEquals($length, $stream->tell()); + $this->assertSame($length, $stream->tell()); \rewind($this->handle); - $this->assertEquals(0, $stream->tell()); + $this->assertSame(0, $stream->tell()); } public function testTellUnresourceable() @@ -121,7 +121,7 @@ public function testRewind() \fwrite($this->handle, $string, $length); $stream->rewind(); - $this->assertEquals(0, \ftell($this->handle)); + $this->assertSame(0, \ftell($this->handle)); } public function testRewindUnresourceable() @@ -145,7 +145,7 @@ public function testSeek() \fwrite($this->handle, $string, $length); \rewind($this->handle); $stream->seek($length, \SEEK_SET); - $this->assertEquals($length, \ftell($this->handle)); + $this->assertSame($length, \ftell($this->handle)); } public function testSeekUnresourceable() @@ -175,10 +175,10 @@ public function testWrite() $stream = new Stream($this->handle); - $this->assertEquals($length, $stream->write($string)); + $this->assertSame($length, $stream->write($string)); \rewind($this->handle); - $this->assertEquals($string, \fread($this->handle, $length)); + $this->assertSame($string, \fread($this->handle, $length)); } public function testWriteUnresourceable() @@ -219,7 +219,7 @@ public function testRead() \fwrite($this->handle, $string); \rewind($this->handle); - $this->assertEquals($string, $stream->read($length)); + $this->assertSame($string, $stream->read($length)); } public function testReadUnresourceable() @@ -251,7 +251,7 @@ public function testGetContents() \fwrite($this->handle, $string); \rewind($this->handle); - $this->assertEquals($string, $stream->getContents()); + $this->assertSame($string, $stream->getContents()); } public function testGetContentsUnresourceable() @@ -278,7 +278,7 @@ public function testGetMetadata() { $stream = new Stream($this->handle); - $this->assertEquals( + $this->assertSame( \stream_get_meta_data($this->handle), $stream->getMetadata() ); @@ -288,12 +288,12 @@ public function testGetMetadataWithKey() { $stream = new Stream($this->handle); - $this->assertEquals( + $this->assertSame( 'php://memory', $stream->getMetadata('uri') ); - $this->assertEquals( + $this->assertSame( null, $stream->getMetadata('undefined') ); @@ -315,10 +315,10 @@ public function testGetSize() $stream = new Stream($this->handle); \fwrite($this->handle, $string); - $this->assertEquals($length, $stream->getSize()); + $this->assertSame($length, $stream->getSize()); \ftruncate($this->handle, 0); - $this->assertEquals(0, $stream->getSize()); + $this->assertSame(0, $stream->getSize()); } public function testGetSizeUnresourceable() @@ -337,7 +337,7 @@ public function testToString() $stream = new Stream($this->handle); \fwrite($this->handle, $string); - $this->assertEquals($string, (string) $stream); + $this->assertSame($string, (string) $stream); } public function testToStringUnresourceable() @@ -345,14 +345,14 @@ public function testToStringUnresourceable() $stream = new Stream($this->handle); $stream->close(); - $this->assertEquals('', (string) $stream); + $this->assertSame('', (string) $stream); } public function testToStringUnreadable() { $stream = new Stream(\STDOUT); - $this->assertEquals('', (string) $stream); + $this->assertSame('', (string) $stream); } public function testExceptions() @@ -370,6 +370,6 @@ private function assertStreamResourceEquals(StreamInterface $stream, $expected) $property->setAccessible(true); - return $this->assertEquals($property->getValue($stream), $expected); + return $this->assertSame($property->getValue($stream), $expected); } }