mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 09:31:51 +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
|
* to "true". To read exact length of HTTP headers from CURL you can use "curl_getinfo()" function
|
||||||
* and read "CURLINFO_HEADER_SIZE" option.
|
* and read "CURLINFO_HEADER_SIZE" option.
|
||||||
*
|
*
|
||||||
* @param string $response the full content of response, including HTTP headers
|
* @param string $response Full content of response, including HTTP headers
|
||||||
* @param int $headerSize The length of HTTP headers in content
|
* @param int $headerSize Length of HTTP headers in content
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function getCurlResponseWithHeaders($response, $headerSize)
|
public static function getCurlResponseWithHeaders($response, $headerSize)
|
||||||
{
|
{
|
||||||
$headerContent = mb_substr($response, 0, $headerSize);
|
|
||||||
$content = mb_substr($response, $headerSize);
|
|
||||||
$headers = [];
|
$headers = [];
|
||||||
$cookies = [];
|
$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
|
* Let's transform headers content into two arrays: headers and cookies
|
||||||
*/
|
*/
|
||||||
|
if (!empty($headerContent)) {
|
||||||
foreach (explode("\r\n", $headerContent) as $i => $line) {
|
foreach (explode("\r\n", $headerContent) as $i => $line) {
|
||||||
/*
|
/*
|
||||||
* First line is only HTTP status and is unneeded so skip it
|
* First line is only HTTP status and is unneeded so skip it
|
||||||
@@ -1329,6 +1336,7 @@ class Miscellaneous
|
|||||||
$headers[$key] = $value;
|
$headers[$key] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'headers' => $headers,
|
'headers' => $headers,
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ class MiscellaneousTest extends BaseTestCase
|
|||||||
private $stringSmall;
|
private $stringSmall;
|
||||||
private $stringCommaSeparated;
|
private $stringCommaSeparated;
|
||||||
private $stringDotSeparated;
|
private $stringDotSeparated;
|
||||||
|
private $stringWithoutSpaces;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ReflectionException
|
* @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<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('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()
|
public function testRemoveDirectoryUsingNotExistingDirectory()
|
||||||
@@ -768,6 +770,21 @@ class MiscellaneousTest extends BaseTestCase
|
|||||||
self::assertNotEmpty(Miscellaneous::getProjectRootPath());
|
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
|
* 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}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@@ -1188,6 +1229,7 @@ class MiscellaneousTest extends BaseTestCase
|
|||||||
$this->stringSmall = 'Lorem ipsum dolor sit amet.';
|
$this->stringSmall = 'Lorem ipsum dolor sit amet.';
|
||||||
$this->stringCommaSeparated = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit';
|
$this->stringCommaSeparated = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit';
|
||||||
$this->stringDotSeparated = 'Etiam ullamcorper. Suspendisse a pellentesque dui, non felis.';
|
$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->stringSmall);
|
||||||
unset($this->stringCommaSeparated);
|
unset($this->stringCommaSeparated);
|
||||||
unset($this->stringDotSeparated);
|
unset($this->stringDotSeparated);
|
||||||
|
unset($this->stringWithoutSpaces);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user