Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
PHPUnit: use better assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed Sep 5, 2017
1 parent cca9819 commit c12658e
Show file tree
Hide file tree
Showing 22 changed files with 261 additions and 261 deletions.
8 changes: 4 additions & 4 deletions test/CallbackStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testToString()
});

$ret = $stream->__toString();
$this->assertEquals('foobarbaz', $ret);
$this->assertSame('foobarbaz', $ret);
}

public function testClose()
Expand Down Expand Up @@ -170,7 +170,7 @@ public function testGetContents()
});

$ret = $stream->getContents();
$this->assertEquals('foobarbaz', $ret);
$this->assertSame('foobarbaz', $ret);
}

public function testGetMetadata()
Expand All @@ -179,7 +179,7 @@ public function testGetMetadata()
});

$ret = $stream->getMetadata('stream_type');
$this->assertEquals('callback', $ret);
$this->assertSame('callback', $ret);

$ret = $stream->getMetadata('seekable');
$this->assertFalse($ret);
Expand Down Expand Up @@ -217,6 +217,6 @@ public function testAllowsArbitraryPhpCallbacks($callback, $expected)
{
$stream = new CallbackStream($callback);
$contents = $stream->getContents();
$this->assertEquals($expected, $contents);
$this->assertSame($expected, $contents);
}
}
2 changes: 1 addition & 1 deletion test/HeaderSecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getFilterValues()
*/
public function testFiltersValuesPerRfc7230($value, $expected)
{
$this->assertEquals($expected, HeaderSecurity::filter($value));
$this->assertSame($expected, HeaderSecurity::filter($value));
}

public function validateValues()
Expand Down
24 changes: 12 additions & 12 deletions test/MessageTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ public function setUp()

public function testProtocolHasAcceptableDefault()
{
$this->assertEquals('1.1', $this->message->getProtocolVersion());
$this->assertSame('1.1', $this->message->getProtocolVersion());
}

public function testProtocolMutatorReturnsCloneWithChanges()
{
$message = $this->message->withProtocolVersion('1.0');
$this->assertNotSame($this->message, $message);
$this->assertEquals('1.0', $message->getProtocolVersion());
$this->assertSame('1.0', $message->getProtocolVersion());
}


Expand Down Expand Up @@ -89,21 +89,21 @@ public function testGetHeaderReturnsHeaderValueAsArray()
{
$message = $this->message->withHeader('X-Foo', ['Foo', 'Bar']);
$this->assertNotSame($this->message, $message);
$this->assertEquals(['Foo', 'Bar'], $message->getHeader('X-Foo'));
$this->assertSame(['Foo', 'Bar'], $message->getHeader('X-Foo'));
}

public function testGetHeaderLineReturnsHeaderValueAsCommaConcatenatedString()
{
$message = $this->message->withHeader('X-Foo', ['Foo', 'Bar']);
$this->assertNotSame($this->message, $message);
$this->assertEquals('Foo,Bar', $message->getHeaderLine('X-Foo'));
$this->assertSame('Foo,Bar', $message->getHeaderLine('X-Foo'));
}

public function testGetHeadersKeepsHeaderCaseSensitivity()
{
$message = $this->message->withHeader('X-Foo', ['Foo', 'Bar']);
$this->assertNotSame($this->message, $message);
$this->assertEquals([ 'X-Foo' => [ 'Foo', 'Bar' ] ], $message->getHeaders());
$this->assertSame([ 'X-Foo' => [ 'Foo', 'Bar' ] ], $message->getHeaders());
}

public function testGetHeadersReturnsCaseWithWhichHeaderFirstRegistered()
Expand All @@ -112,7 +112,7 @@ public function testGetHeadersReturnsCaseWithWhichHeaderFirstRegistered()
->withHeader('X-Foo', 'Foo')
->withAddedHeader('x-foo', 'Bar');
$this->assertNotSame($this->message, $message);
$this->assertEquals([ 'X-Foo' => [ 'Foo', 'Bar' ] ], $message->getHeaders());
$this->assertSame([ 'X-Foo' => [ 'Foo', 'Bar' ] ], $message->getHeaders());
}

public function testHasHeaderReturnsFalseIfHeaderIsNotPresent()
Expand All @@ -133,7 +133,7 @@ public function testAddHeaderAppendsToExistingHeader()
$this->assertNotSame($this->message, $message);
$message2 = $message->withAddedHeader('X-Foo', 'Bar');
$this->assertNotSame($message, $message2);
$this->assertEquals('Foo,Bar', $message2->getHeaderLine('X-Foo'));
$this->assertSame('Foo,Bar', $message2->getHeaderLine('X-Foo'));
}

public function testHeaderExistsIfWithNoValues()
Expand Down Expand Up @@ -178,7 +178,7 @@ public function testHeaderRemovalIsCaseInsensitive()
$this->assertFalse($message2->hasHeader('X-Foo'));

$headers = $message2->getHeaders();
$this->assertEquals(0, count($headers));
$this->assertSame(0, count($headers));
}

public function invalidGeneralHeaderValues()
Expand Down Expand Up @@ -228,8 +228,8 @@ public function testWithHeaderReplacesDifferentCapitalization()
{
$this->message = $this->message->withHeader('X-Foo', ['foo']);
$new = $this->message->withHeader('X-foo', ['bar']);
$this->assertEquals(['bar'], $new->getHeader('x-foo'));
$this->assertEquals(['X-foo' => ['bar']], $new->getHeaders());
$this->assertSame(['bar'], $new->getHeader('x-foo'));
$this->assertSame(['X-foo' => ['bar']], $new->getHeaders());
}

/**
Expand Down Expand Up @@ -311,13 +311,13 @@ public function testDoesNotAllowCRLFInjectionWhenCallingWithAddedHeader($name, $
public function testWithHeaderAllowsHeaderContinuations()
{
$message = $this->message->withHeader('X-Foo-Bar', "value,\r\n second value");
$this->assertEquals("value,\r\n second value", $message->getHeaderLine('X-Foo-Bar'));
$this->assertSame("value,\r\n second value", $message->getHeaderLine('X-Foo-Bar'));
}

public function testWithAddedHeaderAllowsHeaderContinuations()
{
$message = $this->message->withAddedHeader('X-Foo-Bar', "value,\r\n second value");
$this->assertEquals("value,\r\n second value", $message->getHeaderLine('X-Foo-Bar'));
$this->assertSame("value,\r\n second value", $message->getHeaderLine('X-Foo-Bar'));
}

public function numericHeaderValuesProvider()
Expand Down
4 changes: 2 additions & 2 deletions test/PhpInputStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function getFileContents()
public function assertStreamContents($test, $message = null)
{
$content = $this->getFileContents();
$this->assertEquals($content, $test, $message);
$this->assertSame($content, $test, $message);
}

public function testStreamIsNeverWritable()
Expand All @@ -61,7 +61,7 @@ public function testGetContentsReturnsRemainingContentsOfStream()
$remainder = $this->stream->getContents();

$contents = $this->getFileContents();
$this->assertEquals(substr($contents, 128), $remainder);
$this->assertSame(substr($contents, 128), $remainder);
}

public function testGetContentsReturnCacheWhenReachedEof()
Expand Down
28 changes: 14 additions & 14 deletions test/RelativeStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testToString()

$stream = new RelativeStream($decorated->reveal(), 100);
$ret = $stream->__toString();
$this->assertEquals('foobarbaz', $ret);
$this->assertSame('foobarbaz', $ret);
}

public function testClose()
Expand All @@ -47,7 +47,7 @@ public function testDetach()
$decorated->detach()->shouldBeCalled()->willReturn(250);
$stream = new RelativeStream($decorated->reveal(), 100);
$ret = $stream->detach();
$this->assertEquals(250, $ret);
$this->assertSame(250, $ret);
}

public function testGetSize()
Expand All @@ -56,7 +56,7 @@ public function testGetSize()
$decorated->getSize()->shouldBeCalled()->willReturn(250);
$stream = new RelativeStream($decorated->reveal(), 100);
$ret = $stream->getSize();
$this->assertEquals(150, $ret);
$this->assertSame(150, $ret);
}

public function testTell()
Expand All @@ -65,7 +65,7 @@ public function testTell()
$decorated->tell()->shouldBeCalled()->willReturn(188);
$stream = new RelativeStream($decorated->reveal(), 100);
$ret = $stream->tell();
$this->assertEquals(88, $ret);
$this->assertSame(88, $ret);
}

public function testIsSeekable()
Expand All @@ -74,7 +74,7 @@ public function testIsSeekable()
$decorated->isSeekable()->shouldBeCalled()->willReturn(true);
$stream = new RelativeStream($decorated->reveal(), 100);
$ret = $stream->isSeekable();
$this->assertEquals(true, $ret);
$this->assertSame(true, $ret);
}

public function testIsWritable()
Expand All @@ -83,7 +83,7 @@ public function testIsWritable()
$decorated->isWritable()->shouldBeCalled()->willReturn(true);
$stream = new RelativeStream($decorated->reveal(), 100);
$ret = $stream->isWritable();
$this->assertEquals(true, $ret);
$this->assertSame(true, $ret);
}

public function testIsReadable()
Expand All @@ -92,7 +92,7 @@ public function testIsReadable()
$decorated->isReadable()->shouldBeCalled()->willReturn(false);
$stream = new RelativeStream($decorated->reveal(), 100);
$ret = $stream->isReadable();
$this->assertEquals(false, $ret);
$this->assertSame(false, $ret);
}

public function testSeek()
Expand All @@ -101,7 +101,7 @@ public function testSeek()
$decorated->seek(126, SEEK_SET)->shouldBeCalled()->willReturn(0);
$stream = new RelativeStream($decorated->reveal(), 100);
$ret = $stream->seek(26);
$this->assertEquals(0, $ret);
$this->assertSame(0, $ret);
}

public function testRewind()
Expand All @@ -110,7 +110,7 @@ public function testRewind()
$decorated->seek(100, SEEK_SET)->shouldBeCalled()->willReturn(0);
$stream = new RelativeStream($decorated->reveal(), 100);
$ret = $stream->rewind();
$this->assertEquals(0, $ret);
$this->assertSame(0, $ret);
}

public function testWrite()
Expand All @@ -120,7 +120,7 @@ public function testWrite()
$decorated->write("foobaz")->shouldBeCalled()->willReturn(6);
$stream = new RelativeStream($decorated->reveal(), 100);
$ret = $stream->write("foobaz");
$this->assertEquals(6, $ret);
$this->assertSame(6, $ret);
}

public function testRead()
Expand All @@ -130,7 +130,7 @@ public function testRead()
$decorated->read(3)->shouldBeCalled()->willReturn("foo");
$stream = new RelativeStream($decorated->reveal(), 100);
$ret = $stream->read(3);
$this->assertEquals("foo", $ret);
$this->assertSame("foo", $ret);
}

public function testGetContents()
Expand All @@ -140,7 +140,7 @@ public function testGetContents()
$decorated->getContents()->shouldBeCalled()->willReturn("foo");
$stream = new RelativeStream($decorated->reveal(), 100);
$ret = $stream->getContents();
$this->assertEquals("foo", $ret);
$this->assertSame("foo", $ret);
}

public function testGetMetadata()
Expand All @@ -149,7 +149,7 @@ public function testGetMetadata()
$decorated->getMetadata("bar")->shouldBeCalled()->willReturn("foo");
$stream = new RelativeStream($decorated->reveal(), 100);
$ret = $stream->getMetadata("bar");
$this->assertEquals("foo", $ret);
$this->assertSame("foo", $ret);
}

public function testWriteRaisesExceptionWhenPointerIsBehindOffset()
Expand Down Expand Up @@ -200,6 +200,6 @@ public function testCanReadContentFromNotSeekableResource()
$decorated->getContents()->willReturn('CONTENTS');

$stream = new RelativeStream($decorated->reveal(), 3);
$this->assertEquals('CONTENTS', $stream->__toString());
$this->assertSame('CONTENTS', $stream->__toString());
}
}
34 changes: 17 additions & 17 deletions test/Request/SerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testSerializesBasicRequest()
->withAddedHeader('Accept', 'text/html');

$message = Serializer::toString($request);
$this->assertEquals(
$this->assertSame(
"GET /foo/bar?baz=bat HTTP/1.1\r\nHost: example.com\r\nAccept: text/html",
$message
);
Expand Down Expand Up @@ -91,12 +91,12 @@ public function testCanDeserializeRequestWithOriginForm($line, $requestTarget, $
$message = $line . "\r\nX-Foo-Bar: Baz\r\n\r\nContent";
$request = Serializer::fromString($message);

$this->assertEquals('GET', $request->getMethod());
$this->assertEquals($requestTarget, $request->getRequestTarget());
$this->assertSame('GET', $request->getMethod());
$this->assertSame($requestTarget, $request->getRequestTarget());

$uri = $request->getUri();
foreach ($expectations as $method => $expect) {
$this->assertEquals($expect, $uri->{$method}());
$this->assertSame($expect, $uri->{$method}());
}
}

Expand Down Expand Up @@ -156,40 +156,40 @@ public function testCanDeserializeRequestWithAbsoluteForm($line, $requestTarget,
$message = $line . "\r\nX-Foo-Bar: Baz\r\n\r\nContent";
$request = Serializer::fromString($message);

$this->assertEquals('GET', $request->getMethod());
$this->assertSame('GET', $request->getMethod());

$this->assertEquals($requestTarget, $request->getRequestTarget());
$this->assertSame($requestTarget, $request->getRequestTarget());

$uri = $request->getUri();
foreach ($expectations as $method => $expect) {
$this->assertEquals($expect, $uri->{$method}());
$this->assertSame($expect, $uri->{$method}());
}
}

public function testCanDeserializeRequestWithAuthorityForm()
{
$message = "CONNECT www.example.com:80 HTTP/1.1\r\nX-Foo-Bar: Baz";
$request = Serializer::fromString($message);
$this->assertEquals('CONNECT', $request->getMethod());
$this->assertEquals('www.example.com:80', $request->getRequestTarget());
$this->assertSame('CONNECT', $request->getMethod());
$this->assertSame('www.example.com:80', $request->getRequestTarget());

$uri = $request->getUri();
$this->assertNotEquals('www.example.com', $uri->getHost());
$this->assertNotEquals(80, $uri->getPort());
$this->assertNotSame('www.example.com', $uri->getHost());
$this->assertNotSame(80, $uri->getPort());
}

public function testCanDeserializeRequestWithAsteriskForm()
{
$message = "OPTIONS * HTTP/1.1\r\nHost: www.example.com";
$request = Serializer::fromString($message);
$this->assertEquals('OPTIONS', $request->getMethod());
$this->assertEquals('*', $request->getRequestTarget());
$this->assertSame('OPTIONS', $request->getMethod());
$this->assertSame('*', $request->getRequestTarget());

$uri = $request->getUri();
$this->assertNotEquals('www.example.com', $uri->getHost());
$this->assertNotSame('www.example.com', $uri->getHost());

$this->assertTrue($request->hasHeader('Host'));
$this->assertEquals('www.example.com', $request->getHeaderLine('Host'));
$this->assertSame('www.example.com', $request->getHeaderLine('Host'));
}

public function invalidRequestLines()
Expand Down Expand Up @@ -224,7 +224,7 @@ public function testCanDeserializeResponseWithMultipleHeadersOfSameName()

$this->assertTrue($request->hasHeader('X-Foo-Bar'));
$values = $request->getHeader('X-Foo-Bar');
$this->assertEquals(['Baz', 'Bat'], $values);
$this->assertSame(['Baz', 'Bat'], $values);
}

public function headersWithContinuationLines()
Expand All @@ -246,7 +246,7 @@ public function testCanDeserializeResponseWithHeaderContinuations($text)
$this->assertInstanceOf(Request::class, $request);

$this->assertTrue($request->hasHeader('X-Foo-Bar'));
$this->assertEquals('Baz;Bat', $request->getHeaderLine('X-Foo-Bar'));
$this->assertSame('Baz;Bat', $request->getHeaderLine('X-Foo-Bar'));
}

public function messagesWithInvalidHeaders()
Expand Down
Loading

0 comments on commit c12658e

Please sign in to comment.