Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions tests/ChunkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand All @@ -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());
}

/**
Expand All @@ -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());
}

/**
Expand All @@ -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());
}

/**
Expand All @@ -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());
}
}
70 changes: 35 additions & 35 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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";
Expand Down Expand Up @@ -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
Expand All @@ -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";
}
Expand Down Expand Up @@ -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";
}
Expand Down Expand Up @@ -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";
}
Expand All @@ -212,7 +212,7 @@ public function testSetGetTimeout(): void

$client->setTimeout($timeout);

$this->assertEquals($timeout, $client->getTimeout());
$this->assertSame($timeout, $client->getTimeout());
}

/**
Expand All @@ -226,7 +226,7 @@ public function testSetGetAllowRedirects(): void

$client->setAllowRedirects($allowRedirects);

$this->assertEquals($allowRedirects, $client->getAllowRedirects());
$this->assertSame($allowRedirects, $client->getAllowRedirects());
}

/**
Expand All @@ -240,7 +240,7 @@ public function testSetGetMaxRedirects(): void

$client->setMaxRedirects($maxRedirects);

$this->assertEquals($maxRedirects, $client->getMaxRedirects());
$this->assertSame($maxRedirects, $client->getMaxRedirects());
}

/**
Expand All @@ -254,7 +254,7 @@ public function testSetGetConnectTimeout(): void

$client->setConnectTimeout($connectTimeout);

$this->assertEquals($connectTimeout, $client->getConnectTimeout());
$this->assertSame($connectTimeout, $client->getConnectTimeout());
}

/**
Expand All @@ -268,7 +268,7 @@ public function testSetGetUserAgent(): void

$client->setUserAgent($userAgent);

$this->assertEquals($userAgent, $client->getUserAgent());
$this->assertSame($userAgent, $client->getUserAgent());
}

/**
Expand Down Expand Up @@ -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');
}
Expand All @@ -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');
}

Expand All @@ -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');
}
Expand All @@ -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());
Expand Down Expand Up @@ -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());
}

/**
Expand All @@ -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'
Expand All @@ -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']);
}
}
12 changes: 6 additions & 6 deletions tests/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand All @@ -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
Expand Down