diff --git a/tests/ChunkTest.php b/tests/ChunkTest.php index 53ff8aa..79f2648 100644 --- a/tests/ChunkTest.php +++ b/tests/ChunkTest.php @@ -20,20 +20,20 @@ public function testChunkCreation(): void $chunk = new Chunk($data, $size, $timestamp, $index); // Test getData method - $this->assertEquals($data, $chunk->getData()); + $this->assertSame($data, $chunk->getData()); $this->assertIsString($chunk->getData()); // Test getSize method - $this->assertEquals($size, $chunk->getSize()); + $this->assertSame($size, $chunk->getSize()); $this->assertIsInt($chunk->getSize()); - $this->assertEquals(strlen($chunk->getData()), $chunk->getSize()); + $this->assertSame(strlen($chunk->getData()), $chunk->getSize()); // Test getTimestamp method - $this->assertEquals($timestamp, $chunk->getTimestamp()); + $this->assertSame($timestamp, $chunk->getTimestamp()); $this->assertIsFloat($chunk->getTimestamp()); // Test getIndex method - $this->assertEquals($index, $chunk->getIndex()); + $this->assertSame($index, $chunk->getIndex()); $this->assertIsInt($chunk->getIndex()); } @@ -50,10 +50,10 @@ public function testEmptyChunk(): void $chunk = new Chunk($data, $size, $timestamp, $index); - $this->assertEquals('', $chunk->getData()); - $this->assertEquals(0, $chunk->getSize()); - $this->assertEquals($timestamp, $chunk->getTimestamp()); - $this->assertEquals(1, $chunk->getIndex()); + $this->assertSame('', $chunk->getData()); + $this->assertSame(0, $chunk->getSize()); + $this->assertSame($timestamp, $chunk->getTimestamp()); + $this->assertSame(1, $chunk->getIndex()); } /** @@ -69,11 +69,11 @@ public function testBinaryChunk(): void $chunk = new Chunk($data, $size, $timestamp, $index); - $this->assertEquals($data, $chunk->getData()); - $this->assertEquals(5, $chunk->getSize()); - $this->assertEquals($timestamp, $chunk->getTimestamp()); - $this->assertEquals(2, $chunk->getIndex()); - $this->assertEquals("Hello", $chunk->getData()); + $this->assertSame($data, $chunk->getData()); + $this->assertSame(5, $chunk->getSize()); + $this->assertSame($timestamp, $chunk->getTimestamp()); + $this->assertSame(2, $chunk->getIndex()); + $this->assertSame("Hello", $chunk->getData()); } /** @@ -89,10 +89,10 @@ public function testSpecialCharactersChunk(): void $chunk = new Chunk($data, $size, $timestamp, $index); - $this->assertEquals($data, $chunk->getData()); - $this->assertEquals($size, $chunk->getSize()); - $this->assertEquals($timestamp, $chunk->getTimestamp()); - $this->assertEquals(3, $chunk->getIndex()); + $this->assertSame($data, $chunk->getData()); + $this->assertSame($size, $chunk->getSize()); + $this->assertSame($timestamp, $chunk->getTimestamp()); + $this->assertSame(3, $chunk->getIndex()); } /** @@ -116,10 +116,10 @@ public function testChunkImmutability(): void $modifiedData = $chunk->getData() . " modified"; // Verify original chunk remains unchanged - $this->assertEquals($originalData, $chunk->getData()); - $this->assertEquals($originalSize, $chunk->getSize()); - $this->assertEquals($originalTimestamp, $chunk->getTimestamp()); - $this->assertEquals($originalIndex, $chunk->getIndex()); + $this->assertSame($originalData, $chunk->getData()); + $this->assertSame($originalSize, $chunk->getSize()); + $this->assertSame($originalTimestamp, $chunk->getTimestamp()); + $this->assertSame($originalIndex, $chunk->getIndex()); $this->assertNotEquals($modifiedData, $chunk->getData()); } } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 028670e..e861285 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -45,21 +45,21 @@ public function testFetch( } if ($resp->getStatusCode() === 200) { // If the response is OK $respData = $resp->json(); // Convert body to array - $this->assertEquals($respData['method'], $method); // Assert that the method is equal to the response's method + $this->assertSame($respData['method'], $method); // Assert that the method is equal to the response's method if ($method != Client::METHOD_GET) { if (empty($body)) { // if body is empty then response body should be an empty string - $this->assertEquals($respData['body'], ''); + $this->assertSame($respData['body'], ''); } else { if ($headers['content-type'] != "application/x-www-form-urlencoded") { - $this->assertEquals( // Assert that the body is equal to the response's body + $this->assertSame( // Assert that the body is equal to the response's body $respData['body'], json_encode($body) // Converting the body to JSON string ); } } } - $this->assertEquals($respData['url'], $url); // Assert that the url is equal to the response's url - $this->assertEquals( + $this->assertSame($respData['url'], $url); // Assert that the url is equal to the response's url + $this->assertSame( json_encode($respData['query']), // Converting the query to JSON string json_encode($query) // Converting the query to JSON string ); // Assert that the args are equal to the response's args @@ -71,15 +71,15 @@ public function testFetch( $contentType = $respHeaders['content-type']; } $contentType = explode(';', $contentType)[0]; - $this->assertEquals($host, $url); // Assert that the host is equal to the response's host + $this->assertSame($host, $url); // Assert that the host is equal to the response's host if (empty($headers)) { if (empty($body)) { - $this->assertEquals($contentType, 'application/x-www-form-urlencoded'); + $this->assertSame($contentType, 'application/x-www-form-urlencoded'); } else { - $this->assertEquals($contentType, 'application/json'); + $this->assertSame($contentType, 'application/json'); } } else { - $this->assertEquals($contentType, $headers['content-type']); // Assert that the content-type is equal to the response's content-type + $this->assertSame($contentType, $headers['content-type']); // Assert that the content-type is equal to the response's content-type } } else { // If the response is not OK echo "Please configure your PHP inbuilt SERVER"; @@ -114,10 +114,10 @@ public function testSendFile( if ($resp->getStatusCode() === 200) { // If the response is OK $respData = $resp->json(); // Convert body to array if (isset($respData['method'])) { - $this->assertEquals($respData['method'], Client::METHOD_POST); + $this->assertSame($respData['method'], Client::METHOD_POST); } // Assert that the method is equal to the response's method - $this->assertEquals($respData['url'], 'localhost:8000'); // Assert that the url is equal to the response's url - $this->assertEquals( + $this->assertSame($respData['url'], 'localhost:8000'); // Assert that the url is equal to the response's url + $this->assertSame( json_encode($respData['query']), // Converting the query to JSON string json_encode([]) // Converting the query to JSON string ); // Assert that the args are equal to the response's args @@ -130,10 +130,10 @@ public function testSendFile( ] ]; $resp_files = json_decode($respData['files'], true); - $this->assertEquals($files['file']['name'], $resp_files['file']['name']); - $this->assertEquals($files['file']['full_path'], $resp_files['file']['full_path']); - $this->assertEquals($files['file']['type'], $resp_files['file']['type']); - $this->assertEquals($files['file']['error'], $resp_files['file']['error']); + $this->assertSame($files['file']['name'], $resp_files['file']['name']); + $this->assertSame($files['file']['full_path'], $resp_files['file']['full_path']); + $this->assertSame($files['file']['type'], $resp_files['file']['type']); + $this->assertSame($files['file']['error'], $resp_files['file']['error']); } else { // If the response is not OK echo "Please configure your PHP inbuilt SERVER"; } @@ -166,7 +166,7 @@ public function testGetFile( if ($data && $size) { $contents = fread($data, $size); fclose($data); - $this->assertEquals($resp->getBody(), $contents); // Assert that the body is equal to the expected file contents + $this->assertSame($resp->getBody(), $contents); // Assert that the body is equal to the expected file contents } else { echo "Invalid file path in testcase"; } @@ -195,7 +195,7 @@ public function testRedirect(): void } if ($resp->getStatusCode() === 200) { // If the response is OK $respData = $resp->json(); // Convert body to array - $this->assertEquals($respData['page'], "redirectedPage"); // Assert that the page is the redirected page + $this->assertSame($respData['page'], "redirectedPage"); // Assert that the page is the redirected page } else { // If the response is not OK echo "Please configure your PHP inbuilt SERVER"; } @@ -212,7 +212,7 @@ public function testSetGetTimeout(): void $client->setTimeout($timeout); - $this->assertEquals($timeout, $client->getTimeout()); + $this->assertSame($timeout, $client->getTimeout()); } /** @@ -226,7 +226,7 @@ public function testSetGetAllowRedirects(): void $client->setAllowRedirects($allowRedirects); - $this->assertEquals($allowRedirects, $client->getAllowRedirects()); + $this->assertSame($allowRedirects, $client->getAllowRedirects()); } /** @@ -240,7 +240,7 @@ public function testSetGetMaxRedirects(): void $client->setMaxRedirects($maxRedirects); - $this->assertEquals($maxRedirects, $client->getMaxRedirects()); + $this->assertSame($maxRedirects, $client->getMaxRedirects()); } /** @@ -254,7 +254,7 @@ public function testSetGetConnectTimeout(): void $client->setConnectTimeout($connectTimeout); - $this->assertEquals($connectTimeout, $client->getConnectTimeout()); + $this->assertSame($connectTimeout, $client->getConnectTimeout()); } /** @@ -268,7 +268,7 @@ public function testSetGetUserAgent(): void $client->setUserAgent($userAgent); - $this->assertEquals($userAgent, $client->getUserAgent()); + $this->assertSame($userAgent, $client->getUserAgent()); } /** @@ -368,18 +368,18 @@ public function testRetry(): void $client->setMaxRetries(3); $client->setRetryDelay(1000); - $this->assertEquals(3, $client->getMaxRetries()); - $this->assertEquals(1000, $client->getRetryDelay()); + $this->assertSame(3, $client->getMaxRetries()); + $this->assertSame(1000, $client->getRetryDelay()); $res = $client->fetch('localhost:8000/mock-retry'); - $this->assertEquals(200, $res->getStatusCode()); + $this->assertSame(200, $res->getStatusCode()); unlink(__DIR__ . '/state.json'); // Test if we get a 500 error if we go under the server's max retries $client->setMaxRetries(1); $res = $client->fetch('localhost:8000/mock-retry'); - $this->assertEquals(503, $res->getStatusCode()); + $this->assertSame(503, $res->getStatusCode()); unlink(__DIR__ . '/state.json'); } @@ -397,7 +397,7 @@ public function testRetryWithDelay(): void $res = $client->fetch('localhost:8000/mock-retry'); $this->assertGreaterThan($now + 3.0, microtime(true)); - $this->assertEquals(200, $res->getStatusCode()); + $this->assertSame(200, $res->getStatusCode()); unlink(__DIR__ . '/state.json'); } @@ -414,7 +414,7 @@ public function testCustomRetryStatusCodes(): void $now = microtime(true); $res = $client->fetch('localhost:8000/mock-retry-401'); - $this->assertEquals(200, $res->getStatusCode()); + $this->assertSame(200, $res->getStatusCode()); $this->assertGreaterThan($now + 3.0, microtime(true)); unlink(__DIR__ . '/state.json'); } @@ -439,11 +439,11 @@ public function testChunkHandling(): void ); $this->assertGreaterThan(0, count($chunks)); - $this->assertEquals(200, $response->getStatusCode()); + $this->assertSame(200, $response->getStatusCode()); // Test chunk metadata foreach ($chunks as $index => $chunk) { - $this->assertEquals($index, $chunk->getIndex()); + $this->assertSame($index, $chunk->getIndex()); $this->assertGreaterThan(0, $chunk->getSize()); $this->assertGreaterThan(0, $chunk->getTimestamp()); $this->assertNotEmpty($chunk->getData()); @@ -511,7 +511,7 @@ public function testChunkHandlingWithError(): void if ($errorChunk !== null) { $this->assertNotEmpty($errorChunk->getData()); } - $this->assertEquals(404, $response->getStatusCode()); + $this->assertSame(404, $response->getStatusCode()); } /** @@ -538,13 +538,13 @@ public function testChunkHandlingWithChunkedError(): void ); // Verify response status code - $this->assertEquals(400, $response->getStatusCode()); + $this->assertSame(400, $response->getStatusCode()); // Verify we received chunks $this->assertCount(3, $chunks); // Verify error messages were received in order - $this->assertEquals([ + $this->assertSame([ 'Validation error', 'Additional details', 'Final error message' @@ -554,6 +554,6 @@ public function testChunkHandlingWithChunkedError(): void $this->assertArrayHasKey(0, $chunks); $firstChunk = json_decode($chunks[0]->getData(), true); $this->assertIsArray($firstChunk); - $this->assertEquals('username', $firstChunk['field']); + $this->assertSame('username', $firstChunk['field']); } } diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php index af8e93c..762f377 100644 --- a/tests/ResponseTest.php +++ b/tests/ResponseTest.php @@ -23,9 +23,9 @@ public function testClassConstructorAndGetters( headers: $headers, statusCode: $statusCode ); - $this->assertEquals($body, $resp->getBody()); - $this->assertEquals($headers, $resp->getHeaders()); - $this->assertEquals($statusCode, $resp->getStatusCode()); + $this->assertSame($body, $resp->getBody()); + $this->assertSame($headers, $resp->getHeaders()); + $this->assertSame($statusCode, $resp->getStatusCode()); } /** @@ -46,14 +46,14 @@ public function testClassMethods( headers: $headers, statusCode: $statusCode, ); - $this->assertEquals($body, $resp->getBody()); // Assert that the body is equal to the response's body + $this->assertSame($body, $resp->getBody()); // Assert that the body is equal to the response's body $jsonBody = \json_decode($body, true); // Convert JSON string to object - $this->assertEquals($jsonBody, $resp->json()); // Assert that the JSON body is equal to the response's JSON body + $this->assertSame($jsonBody, $resp->json()); // Assert that the JSON body is equal to the response's JSON body $bin = ""; // Convert string to binary for ($i = 0, $j = strlen($body); $i < $j; $i++) { $bin .= decbin(ord($body)) . " "; } - $this->assertEquals($bin, $resp->blob()); // Assert that the blob body is equal to the response's blob body + $this->assertSame($bin, $resp->blob()); // Assert that the blob body is equal to the response's blob body } /** * Data provider for testClassConstructorAndGetters and testClassMethods