mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 01:31:45 +01:00
Tests > increase code coverage
This commit is contained in:
@@ -1229,20 +1229,27 @@ class Miscellaneous
|
||||
* to "true". To read exact length of HTTP headers from CURL you can use "curl_getinfo()" function
|
||||
* and read "CURLINFO_HEADER_SIZE" option.
|
||||
*
|
||||
* @param string $response the full content of response, including HTTP headers
|
||||
* @param int $headerSize The length of HTTP headers in content
|
||||
* @param string $response Full content of response, including HTTP headers
|
||||
* @param int $headerSize Length of HTTP headers in content
|
||||
* @return array
|
||||
*/
|
||||
public static function getCurlResponseWithHeaders($response, $headerSize)
|
||||
{
|
||||
$headerContent = mb_substr($response, 0, $headerSize);
|
||||
$content = mb_substr($response, $headerSize);
|
||||
$headers = [];
|
||||
$cookies = [];
|
||||
|
||||
$headerContent = '';
|
||||
$content = '';
|
||||
|
||||
if (0 < $headerSize) {
|
||||
$headerContent = mb_substr($response, 0, $headerSize);
|
||||
$content = mb_substr($response, $headerSize);
|
||||
}
|
||||
|
||||
/*
|
||||
* Let's transform headers content into two arrays: headers and cookies
|
||||
*/
|
||||
if (!empty($headerContent)) {
|
||||
foreach (explode("\r\n", $headerContent) as $i => $line) {
|
||||
/*
|
||||
* First line is only HTTP status and is unneeded so skip it
|
||||
@@ -1329,6 +1336,7 @@ class Miscellaneous
|
||||
$headers[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'headers' => $headers,
|
||||
|
||||
@@ -28,6 +28,7 @@ class MiscellaneousTest extends BaseTestCase
|
||||
private $stringSmall;
|
||||
private $stringCommaSeparated;
|
||||
private $stringDotSeparated;
|
||||
private $stringWithoutSpaces;
|
||||
|
||||
/**
|
||||
* @throws ReflectionException
|
||||
@@ -365,6 +366,7 @@ class MiscellaneousTest extends BaseTestCase
|
||||
{
|
||||
self::assertEquals('Lorem ipsum dolor sit<br>amet, consectetur<br>adipiscing<br>elit', Miscellaneous::breakLongText($this->stringCommaSeparated, 20));
|
||||
self::assertEquals('Lorem ipsum dolor sit---amet, consectetur---adipiscing---elit', Miscellaneous::breakLongText($this->stringCommaSeparated, 20, '---'));
|
||||
self::assertEquals('LoremIpsum<br>DolorSitAm<br>etConsecte<br>turAdipisc<br>ingElit', Miscellaneous::breakLongText($this->stringWithoutSpaces, 10));
|
||||
}
|
||||
|
||||
public function testRemoveDirectoryUsingNotExistingDirectory()
|
||||
@@ -768,6 +770,21 @@ class MiscellaneousTest extends BaseTestCase
|
||||
self::assertNotEmpty(Miscellaneous::getProjectRootPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $headerSize Length of HTTP headers in content
|
||||
* @dataProvider provideHeaderSizeForEmptyCurlResponse
|
||||
*/
|
||||
public function testGetCurlResponseWithHeadersUsingEmptyResponse($headerSize)
|
||||
{
|
||||
$expected = [
|
||||
'headers' => [],
|
||||
'cookies' => [],
|
||||
'content' => '',
|
||||
];
|
||||
|
||||
self::assertEquals($expected, Miscellaneous::getCurlResponseWithHeaders('', $headerSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides string to convert characters to latin characters and not lower cased and not human-readable
|
||||
*
|
||||
@@ -1178,6 +1195,30 @@ class MiscellaneousTest extends BaseTestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides length/size of HTTP headers for an empty response
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideHeaderSizeForEmptyCurlResponse()
|
||||
{
|
||||
yield[
|
||||
-10,
|
||||
];
|
||||
|
||||
yield[
|
||||
-1,
|
||||
];
|
||||
|
||||
yield[
|
||||
0,
|
||||
];
|
||||
|
||||
yield[
|
||||
10,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -1188,6 +1229,7 @@ class MiscellaneousTest extends BaseTestCase
|
||||
$this->stringSmall = 'Lorem ipsum dolor sit amet.';
|
||||
$this->stringCommaSeparated = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit';
|
||||
$this->stringDotSeparated = 'Etiam ullamcorper. Suspendisse a pellentesque dui, non felis.';
|
||||
$this->stringWithoutSpaces = 'LoremIpsumDolorSitAmetConsecteturAdipiscingElit';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1200,5 +1242,6 @@ class MiscellaneousTest extends BaseTestCase
|
||||
unset($this->stringSmall);
|
||||
unset($this->stringCommaSeparated);
|
||||
unset($this->stringDotSeparated);
|
||||
unset($this->stringWithoutSpaces);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user