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

Commit

Permalink
Improve PHPUnit assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
peter279k committed Nov 30, 2021
1 parent 535faf7 commit 985fe42
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
8 changes: 4 additions & 4 deletions tests/StreamFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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')));
}
}
38 changes: 19 additions & 19 deletions tests/StreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -278,7 +278,7 @@ public function testGetMetadata()
{
$stream = new Stream($this->handle);

$this->assertEquals(
$this->assertSame(
\stream_get_meta_data($this->handle),
$stream->getMetadata()
);
Expand All @@ -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')
);
Expand All @@ -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()
Expand All @@ -337,22 +337,22 @@ 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()
{
$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()
Expand All @@ -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);
}
}

0 comments on commit 985fe42

Please sign in to comment.