Skip to content

Commit

Permalink
Merge pull request #20 from open-source-contributions/improve_assertions
Browse files Browse the repository at this point in the history
Using assertSame to make assertion equals strict
  • Loading branch information
fenric committed Nov 30, 2021
2 parents f47c9a2 + 7f0ae38 commit 140918d
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 64 deletions.
62 changes: 31 additions & 31 deletions tests/MessageTest.php
Expand Up @@ -56,9 +56,9 @@ public function testProtocolVersion() : void
$this->assertNotEquals($mess, $copy);

// default value
$this->assertEquals('1.1', $mess->getProtocolVersion());
$this->assertSame('1.1', $mess->getProtocolVersion());
// assigned value
$this->assertEquals('2.0', $copy->getProtocolVersion());
$this->assertSame('2.0', $copy->getProtocolVersion());
}

/**
Expand All @@ -83,8 +83,8 @@ public function testSetHeader() : void

$this->assertInstanceOf(MessageInterface::class, $copy);
$this->assertNotEquals($mess, $copy);
$this->assertEquals([], $mess->getHeaders());
$this->assertEquals(['X-Foo' => ['bar']], $copy->getHeaders());
$this->assertSame([], $mess->getHeaders());
$this->assertSame(['X-Foo' => ['bar']], $copy->getHeaders());
}

/**
Expand All @@ -94,7 +94,7 @@ public function testSetHeaderWithSeveralValues() : void
{
$mess = (new Message)->withHeader('X-Foo', ['bar', 'baz']);

$this->assertEquals(['X-Foo' => ['bar', 'baz']], $mess->getHeaders());
$this->assertSame(['X-Foo' => ['bar', 'baz']], $mess->getHeaders());
}

/**
Expand All @@ -106,7 +106,7 @@ public function testSetSeveralHeaders() : void
->withHeader('X-Foo', ['bar', 'baz'])
->withHeader('X-Quux', ['quuux', 'quuuux']);

$this->assertEquals([
$this->assertSame([
'X-Foo' => ['bar', 'baz'],
'X-Quux' => ['quuux', 'quuuux'],
], $mess->getHeaders());
Expand All @@ -119,7 +119,7 @@ public function testSetHeaderLowercase() : void
{
$mess = (new Message)->withHeader('x-foo', 'bar');

$this->assertEquals(['X-Foo' => ['bar']], $mess->getHeaders());
$this->assertSame(['X-Foo' => ['bar']], $mess->getHeaders());
}

/**
Expand Down Expand Up @@ -168,8 +168,8 @@ public function testAddHeader() : void

$this->assertInstanceOf(MessageInterface::class, $copy);
$this->assertNotEquals($mess, $copy);
$this->assertEquals(['X-Foo' => ['bar']], $mess->getHeaders());
$this->assertEquals(['X-Foo' => ['bar', 'baz']], $copy->getHeaders());
$this->assertSame(['X-Foo' => ['bar']], $mess->getHeaders());
$this->assertSame(['X-Foo' => ['bar', 'baz']], $copy->getHeaders());
}

/**
Expand All @@ -181,7 +181,7 @@ public function testAddHeaderWithSeveralValues() : void
->withHeader('X-Foo', ['bar', 'baz'])
->withAddedHeader('X-Foo', ['quux', 'quuux']);

$this->assertEquals(['X-Foo' => ['bar', 'baz', 'quux', 'quuux']], $mess->getHeaders());
$this->assertSame(['X-Foo' => ['bar', 'baz', 'quux', 'quuux']], $mess->getHeaders());
}

/**
Expand All @@ -195,7 +195,7 @@ public function testAddSeveralHeaders() : void
->withAddedHeader('X-Foo', 'quuux')
->withAddedHeader('X-Baz', 'quuuux');

$this->assertEquals([
$this->assertSame([
'X-Foo' => ['bar', 'quuux'],
'X-Baz' => ['quux', 'quuuux'],
], $mess->getHeaders());
Expand All @@ -210,7 +210,7 @@ public function testAddHeaderLowercase() : void
->withHeader('x-foo', 'bar')
->withAddedHeader('x-foo', 'baz');

$this->assertEquals(['X-Foo' => ['bar', 'baz']], $mess->getHeaders());
$this->assertSame(['X-Foo' => ['bar', 'baz']], $mess->getHeaders());
}

/**
Expand Down Expand Up @@ -259,8 +259,8 @@ public function testDeleteHeader() : void

$this->assertInstanceOf(MessageInterface::class, $copy);
$this->assertNotEquals($mess, $copy);
$this->assertEquals(['X-Foo' => ['bar']], $mess->getHeaders());
$this->assertEquals([], $copy->getHeaders());
$this->assertSame(['X-Foo' => ['bar']], $mess->getHeaders());
$this->assertSame([], $copy->getHeaders());
}

/**
Expand All @@ -272,7 +272,7 @@ public function testDeleteHeaderCaseInsensitive() : void
->withHeader('x-foo', 'bar')
->withoutHeader('X-Foo');

$this->assertEquals([], $mess->getHeaders());
$this->assertSame([], $mess->getHeaders());
}

/**
Expand All @@ -283,8 +283,8 @@ public function testReplaceHeader() : void
$mess = (new Message)->withHeader('X-Foo', 'bar');
$copy = $mess->withHeader('X-Foo', 'baz');

$this->assertEquals(['X-Foo' => ['bar']], $mess->getHeaders());
$this->assertEquals(['X-Foo' => ['baz']], $copy->getHeaders());
$this->assertSame(['X-Foo' => ['bar']], $mess->getHeaders());
$this->assertSame(['X-Foo' => ['baz']], $copy->getHeaders());
}

/**
Expand All @@ -296,7 +296,7 @@ public function testReplaceHeaderCaseInsensitive() : void
->withHeader('x-foo', 'bar')
->withHeader('X-Foo', 'baz');

$this->assertEquals(['X-Foo' => ['baz']], $mess->getHeaders());
$this->assertSame(['X-Foo' => ['baz']], $mess->getHeaders());
}

/**
Expand Down Expand Up @@ -329,8 +329,8 @@ public function testGetHeader() : void
{
$mess = (new Message)->withHeader('X-Foo', 'bar');

$this->assertEquals(['bar'], $mess->getHeader('X-Foo'));
$this->assertEquals([], $mess->getHeader('X-Bar'));
$this->assertSame(['bar'], $mess->getHeader('X-Foo'));
$this->assertSame([], $mess->getHeader('X-Bar'));
}

/**
Expand All @@ -340,9 +340,9 @@ public function testGetHeaderCaseInsensitive() : void
{
$mess = (new Message)->withHeader('x-foo', 'bar');

$this->assertEquals(['bar'], $mess->getHeader('x-foo'));
$this->assertEquals(['bar'], $mess->getHeader('X-Foo'));
$this->assertEquals(['bar'], $mess->getHeader('X-FOO'));
$this->assertSame(['bar'], $mess->getHeader('x-foo'));
$this->assertSame(['bar'], $mess->getHeader('X-Foo'));
$this->assertSame(['bar'], $mess->getHeader('X-FOO'));
}

/**
Expand All @@ -352,7 +352,7 @@ public function testGetHeaderWithSeveralValues() : void
{
$mess = (new Message)->withHeader('X-Foo', ['bar', 'baz', 'quux']);

$this->assertEquals(['bar', 'baz', 'quux'], $mess->getHeader('X-Foo'));
$this->assertSame(['bar', 'baz', 'quux'], $mess->getHeader('X-Foo'));
}

/**
Expand All @@ -362,8 +362,8 @@ public function testGetHeaderLine() : void
{
$mess = (new Message)->withHeader('X-Foo', 'bar');

$this->assertEquals('bar', $mess->getHeaderLine('X-Foo'));
$this->assertEquals('', $mess->getHeaderLine('X-Bar'));
$this->assertSame('bar', $mess->getHeaderLine('X-Foo'));
$this->assertSame('', $mess->getHeaderLine('X-Bar'));
}

/**
Expand All @@ -373,9 +373,9 @@ public function testGetHeaderLineCaseInsensitive() : void
{
$mess = (new Message)->withHeader('x-foo', 'bar');

$this->assertEquals('bar', $mess->getHeaderLine('x-foo'));
$this->assertEquals('bar', $mess->getHeaderLine('X-Foo'));
$this->assertEquals('bar', $mess->getHeaderLine('X-FOO'));
$this->assertSame('bar', $mess->getHeaderLine('x-foo'));
$this->assertSame('bar', $mess->getHeaderLine('X-Foo'));
$this->assertSame('bar', $mess->getHeaderLine('X-FOO'));
}

/**
Expand All @@ -385,7 +385,7 @@ public function testGetHeaderLineWithSeveralValues() : void
{
$mess = (new Message)->withHeader('X-Foo', ['bar', 'baz', 'quux']);

$this->assertEquals('bar, baz, quux', $mess->getHeaderLine('X-Foo'));
$this->assertSame('bar, baz, quux', $mess->getHeaderLine('X-Foo'));
}

/**
Expand All @@ -403,7 +403,7 @@ public function testBody() : void
// default value
$this->assertNotSame($body, $mess->getBody());
// assigned value
$this->assertEquals($body, $copy->getBody());
$this->assertSame($body, $copy->getBody());
}

// Providers...
Expand Down
8 changes: 4 additions & 4 deletions tests/RequestFactoryTest.php
Expand Up @@ -41,15 +41,15 @@ public function testCreateRequest() : void
$request = (new RequestFactory)->createRequest($method, $uri);

$this->assertInstanceOf(RequestInterface::class, $request);
$this->assertEquals($method, $request->getMethod());
$this->assertEquals($uri, $request->getUri());
$this->assertSame($method, $request->getMethod());
$this->assertSame($uri, $request->getUri());

// default body of the request...
$this->assertInstanceOf(StreamInterface::class, $request->getBody());
$this->assertTrue($request->getBody()->isSeekable());
$this->assertTrue($request->getBody()->isWritable());
$this->assertTrue($request->getBody()->isReadable());
$this->assertEquals('php://temp', $request->getBody()->getMetadata('uri'));
$this->assertSame('php://temp', $request->getBody()->getMetadata('uri'));
}

/**
Expand All @@ -61,7 +61,7 @@ public function testCreateRequestWithUriAsString() : void
$request = (new RequestFactory)->createRequest('GET', $uri);

$this->assertInstanceOf(UriInterface::class, $request->getUri());
$this->assertEquals($uri, (string) $request->getUri());
$this->assertSame($uri, (string) $request->getUri());
}

/**
Expand Down
36 changes: 18 additions & 18 deletions tests/RequestTest.php
Expand Up @@ -74,9 +74,9 @@ public function testMethod() : void
$this->assertNotEquals($mess, $copy);

// default value
$this->assertEquals('GET', $mess->getMethod());
$this->assertSame('GET', $mess->getMethod());
// assigned value
$this->assertEquals('POST', $copy->getMethod());
$this->assertSame('POST', $copy->getMethod());
}

/**
Expand All @@ -86,7 +86,7 @@ public function testLowercasedMethod() : void
{
$mess = (new Request)->withMethod('post');

$this->assertEquals('POST', $mess->getMethod());
$this->assertSame('POST', $mess->getMethod());
}

/**
Expand All @@ -98,7 +98,7 @@ public function testFigMethod($method) : void
{
$mess = (new Request)->withMethod($method);

$this->assertEquals($method, $mess->getMethod());
$this->assertSame($method, $mess->getMethod());
}

/**
Expand Down Expand Up @@ -126,9 +126,9 @@ public function testRequestTarget() : void
$this->assertNotEquals($mess, $copy);

// default value
$this->assertEquals('/', $mess->getRequestTarget());
$this->assertSame('/', $mess->getRequestTarget());
// assigned value
$this->assertEquals('/path?query', $copy->getRequestTarget());
$this->assertSame('/path?query', $copy->getRequestTarget());
}

/**
Expand All @@ -140,7 +140,7 @@ public function testRequestTargetWithDifferentUriForms($requestTarget) : void
{
$mess = (new Request)->withRequestTarget($requestTarget);

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

/**
Expand All @@ -164,7 +164,7 @@ public function testGetRequestTargetHavingUriWithoutPath() : void
$mess = (new Request)->withUri($uri);

// returns "/" as default path
$this->assertEquals('/', $mess->getRequestTarget());
$this->assertSame('/', $mess->getRequestTarget());
}

/**
Expand All @@ -176,7 +176,7 @@ public function testGetRequestTargetHavingUriWithNotAbsolutePath() : void
$mess = (new Request)->withUri($uri);

// returns "/" as default path
$this->assertEquals('/', $mess->getRequestTarget());
$this->assertSame('/', $mess->getRequestTarget());
}

/**
Expand All @@ -187,7 +187,7 @@ public function testGetRequestTargetHavingUriWithAbsolutePath() : void
$uri = (new UriFactory)->createUri('/path');
$mess = (new Request)->withUri($uri);

$this->assertEquals('/path', $mess->getRequestTarget());
$this->assertSame('/path', $mess->getRequestTarget());
}

/**
Expand All @@ -198,7 +198,7 @@ public function testGetRequestTargetHavingUriWithAbsolutePathAndQuery() : void
$uri = (new UriFactory)->createUri('/path?query');
$mess = (new Request)->withUri($uri);

$this->assertEquals('/path?query', $mess->getRequestTarget());
$this->assertSame('/path?query', $mess->getRequestTarget());
}

/**
Expand All @@ -209,7 +209,7 @@ public function testGetRequestTargetIgnoringNewUri() : void
$uri = (new UriFactory)->createUri('/new');
$mess = (new Request)->withRequestTarget('/primary')->withUri($uri);

$this->assertEquals('/primary', $mess->getRequestTarget());
$this->assertSame('/primary', $mess->getRequestTarget());
}

/**
Expand All @@ -228,7 +228,7 @@ public function testUri() : void
// default value
$this->assertNotSame($uri, $mess->getUri());
// assigned value
$this->assertEquals($uri, $copy->getUri());
$this->assertSame($uri, $copy->getUri());
}

/**
Expand All @@ -239,7 +239,7 @@ public function testUriWithAssigningHostHeaderFromUriHost() : void
$uri = (new UriFactory)->createUri('http://localhost');
$mess = (new Request)->withUri($uri);

$this->assertEquals($uri->getHost(), $mess->getHeaderLine('host'));
$this->assertSame($uri->getHost(), $mess->getHeaderLine('host'));
}

/**
Expand All @@ -250,7 +250,7 @@ public function testUriWithAssigningHostHeaderFromUriHostAndPort() : void
$uri = (new UriFactory)->createUri('http://localhost:3000');
$mess = (new Request)->withUri($uri);

$this->assertEquals($uri->getHost() . ':' . $uri->getPort(), $mess->getHeaderLine('host'));
$this->assertSame($uri->getHost() . ':' . $uri->getPort(), $mess->getHeaderLine('host'));
}

/**
Expand All @@ -261,7 +261,7 @@ public function testUriWithReplacingHostHeaderFromUri() : void
$uri = (new UriFactory)->createUri('http://localhost');
$mess = (new Request)->withHeader('host', 'example.com')->withUri($uri);

$this->assertEquals($uri->getHost(), $mess->getHeaderLine('host'));
$this->assertSame($uri->getHost(), $mess->getHeaderLine('host'));
}

/**
Expand All @@ -272,7 +272,7 @@ public function testUriWithPreservingHostHeader() : void
$uri = (new UriFactory)->createUri('http://localhost');
$mess = (new Request)->withHeader('host', 'example.com')->withUri($uri, true);

$this->assertEquals('example.com', $mess->getHeaderLine('host'));
$this->assertSame('example.com', $mess->getHeaderLine('host'));
}

/**
Expand All @@ -283,7 +283,7 @@ public function testUriWithPreservingHostHeaderIfItIsEmpty() : void
$uri = (new UriFactory)->createUri('http://localhost');
$mess = (new Request)->withUri($uri, true);

$this->assertEquals($uri->getHost(), $mess->getHeaderLine('host'));
$this->assertSame($uri->getHost(), $mess->getHeaderLine('host'));
}

// Providers...
Expand Down
6 changes: 3 additions & 3 deletions tests/ResponseFactoryTest.php
Expand Up @@ -41,15 +41,15 @@ public function testCreateResponse() : void
->createResponse($statusCode, $reasonPhrase);

$this->assertInstanceOf(ResponseInterface::class, $response);
$this->assertEquals($statusCode, $response->getStatusCode());
$this->assertEquals($reasonPhrase, $response->getReasonPhrase());
$this->assertSame($statusCode, $response->getStatusCode());
$this->assertSame($reasonPhrase, $response->getReasonPhrase());

// default body of the response...
$this->assertInstanceOf(StreamInterface::class, $response->getBody());
$this->assertTrue($response->getBody()->isSeekable());
$this->assertTrue($response->getBody()->isWritable());
$this->assertTrue($response->getBody()->isReadable());
$this->assertEquals('php://temp', $response->getBody()->getMetadata('uri'));
$this->assertSame('php://temp', $response->getBody()->getMetadata('uri'));
}

/**
Expand Down

0 comments on commit 140918d

Please sign in to comment.