From 7f0ae384e310fbfeb6e8f62c04e90938fbf34ec7 Mon Sep 17 00:00:00 2001 From: peter279k Date: Tue, 30 Nov 2021 11:59:44 +0800 Subject: [PATCH] Using assertSame to make assertion equals strict --- tests/MessageTest.php | 62 +++++++++++++++++------------------ tests/RequestFactoryTest.php | 8 ++--- tests/RequestTest.php | 36 ++++++++++---------- tests/ResponseFactoryTest.php | 6 ++-- tests/ResponseTest.php | 16 ++++----- 5 files changed, 64 insertions(+), 64 deletions(-) diff --git a/tests/MessageTest.php b/tests/MessageTest.php index f6c22c3..5a14e66 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -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()); } /** @@ -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()); } /** @@ -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()); } /** @@ -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()); @@ -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()); } /** @@ -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()); } /** @@ -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()); } /** @@ -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()); @@ -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()); } /** @@ -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()); } /** @@ -272,7 +272,7 @@ public function testDeleteHeaderCaseInsensitive() : void ->withHeader('x-foo', 'bar') ->withoutHeader('X-Foo'); - $this->assertEquals([], $mess->getHeaders()); + $this->assertSame([], $mess->getHeaders()); } /** @@ -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()); } /** @@ -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()); } /** @@ -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')); } /** @@ -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')); } /** @@ -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')); } /** @@ -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')); } /** @@ -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')); } /** @@ -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')); } /** @@ -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... diff --git a/tests/RequestFactoryTest.php b/tests/RequestFactoryTest.php index 7e0b6a8..db4474b 100644 --- a/tests/RequestFactoryTest.php +++ b/tests/RequestFactoryTest.php @@ -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')); } /** @@ -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()); } /** diff --git a/tests/RequestTest.php b/tests/RequestTest.php index e7f8339..f56a2ab 100644 --- a/tests/RequestTest.php +++ b/tests/RequestTest.php @@ -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()); } /** @@ -86,7 +86,7 @@ public function testLowercasedMethod() : void { $mess = (new Request)->withMethod('post'); - $this->assertEquals('POST', $mess->getMethod()); + $this->assertSame('POST', $mess->getMethod()); } /** @@ -98,7 +98,7 @@ public function testFigMethod($method) : void { $mess = (new Request)->withMethod($method); - $this->assertEquals($method, $mess->getMethod()); + $this->assertSame($method, $mess->getMethod()); } /** @@ -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()); } /** @@ -140,7 +140,7 @@ public function testRequestTargetWithDifferentUriForms($requestTarget) : void { $mess = (new Request)->withRequestTarget($requestTarget); - $this->assertEquals($requestTarget, $mess->getRequestTarget()); + $this->assertSame($requestTarget, $mess->getRequestTarget()); } /** @@ -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()); } /** @@ -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()); } /** @@ -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()); } /** @@ -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()); } /** @@ -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()); } /** @@ -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()); } /** @@ -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')); } /** @@ -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')); } /** @@ -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')); } /** @@ -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')); } /** @@ -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... diff --git a/tests/ResponseFactoryTest.php b/tests/ResponseFactoryTest.php index 5a3d095..a592709 100644 --- a/tests/ResponseFactoryTest.php +++ b/tests/ResponseFactoryTest.php @@ -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')); } /** diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php index 3b93f3c..0dfabf7 100644 --- a/tests/ResponseTest.php +++ b/tests/ResponseTest.php @@ -47,12 +47,12 @@ public function testStatus() : void $this->assertNotEquals($mess, $copy); // default values - $this->assertEquals(200, $mess->getStatusCode()); - $this->assertEquals(REASON_PHRASES[200], $mess->getReasonPhrase()); + $this->assertSame(200, $mess->getStatusCode()); + $this->assertSame(REASON_PHRASES[200], $mess->getReasonPhrase()); // assigned values - $this->assertEquals(204, $copy->getStatusCode()); - $this->assertEquals(REASON_PHRASES[204], $copy->getReasonPhrase()); + $this->assertSame(204, $copy->getStatusCode()); + $this->assertSame(REASON_PHRASES[204], $copy->getReasonPhrase()); } /** @@ -64,8 +64,8 @@ public function testFigStatus($statusCode, $reasonPhrase) : void { $mess = (new Response)->withStatus($statusCode); - $this->assertEquals($statusCode, $mess->getStatusCode()); - $this->assertEquals($reasonPhrase, $mess->getReasonPhrase()); + $this->assertSame($statusCode, $mess->getStatusCode()); + $this->assertSame($reasonPhrase, $mess->getReasonPhrase()); } /** @@ -87,7 +87,7 @@ public function testUnknownStatusCode() : void { $mess = (new Response)->withStatus(599); - $this->assertEquals('Unknown Status Code', $mess->getReasonPhrase()); + $this->assertSame('Unknown Status Code', $mess->getReasonPhrase()); } /** @@ -109,7 +109,7 @@ public function testCustomReasonPhrase() : void { $mess = (new Response)->withStatus(200, 'test'); - $this->assertEquals('test', $mess->getReasonPhrase()); + $this->assertSame('test', $mess->getReasonPhrase()); } // Providers...