mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 09:31:51 +01:00
Fix code pointed by Psalm
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
namespace Meritoo\Test\Common\Utilities;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Utilities\Arrays;
|
||||
use Meritoo\Common\Utilities\Locale;
|
||||
@@ -20,7 +21,7 @@ use Meritoo\Test\Common\Utilities\Arrays\SimpleToString;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Utilities\Arrays
|
||||
* @covers \Meritoo\Common\Utilities\Arrays
|
||||
*/
|
||||
class ArraysTest extends BaseTestCase
|
||||
{
|
||||
@@ -212,7 +213,7 @@ class ArraysTest extends BaseTestCase
|
||||
self::assertEquals('amet/1/primis', Arrays::getLastElementBreadCrumb($this->complexArray));
|
||||
}
|
||||
|
||||
public function testGetLastRow()
|
||||
public function testGetLastRow(): void
|
||||
{
|
||||
// Negative cases
|
||||
self::assertNull(Arrays::getLastRow([]));
|
||||
@@ -234,34 +235,32 @@ class ArraysTest extends BaseTestCase
|
||||
], Arrays::getLastRow($this->complexArray));
|
||||
}
|
||||
|
||||
public function testReplaceArrayKeys()
|
||||
{
|
||||
$effect = [
|
||||
'nullam' => 'donec',
|
||||
'x' => [
|
||||
'vitae' => [
|
||||
'x' => 'quis',
|
||||
],
|
||||
],
|
||||
'elit',
|
||||
];
|
||||
|
||||
$dataArray = $this->complexArray['sit'];
|
||||
self::assertEquals($effect, Arrays::replaceArrayKeys($dataArray, '|.*li.*|', 'x'));
|
||||
|
||||
self::assertEquals([
|
||||
'x' => 'sit',
|
||||
4 => 'amet',
|
||||
], Arrays::replaceArrayKeys($this->simpleArray, '|[0-3]+|', 'x'));
|
||||
/**
|
||||
* @param string $description Description of test case
|
||||
* @param array $array Array which keys should be replaced
|
||||
* @param string $oldKeyPattern Regular expression of the old key
|
||||
* @param string $newKey Name of the new key
|
||||
* @param array $expected Expected result
|
||||
*
|
||||
* @dataProvider provideArrayToReplaceKeys
|
||||
*/
|
||||
public function testReplaceKeys(
|
||||
string $description,
|
||||
array $array,
|
||||
string $oldKeyPattern,
|
||||
string $newKey,
|
||||
?array $expected
|
||||
): void {
|
||||
self::assertSame($expected, Arrays::replaceKeys($array, $oldKeyPattern, $newKey), $description);
|
||||
}
|
||||
|
||||
public function testMakeArray()
|
||||
public function testMakeArray(): void
|
||||
{
|
||||
self::assertSame($this->simpleArray, Arrays::makeArray($this->simpleArray));
|
||||
self::assertSame(['test'], Arrays::makeArray('test'));
|
||||
}
|
||||
|
||||
public function testArray2JavaScript()
|
||||
public function testArray2JavaScript(): void
|
||||
{
|
||||
// Negative cases
|
||||
self::assertNull(Arrays::array2JavaScript([]));
|
||||
@@ -339,36 +338,25 @@ letsTest[2] = value_2;';
|
||||
*
|
||||
* @dataProvider provideArrayToQuoteStrings
|
||||
*/
|
||||
public function testQuoteStrings($description, $expected, array $array)
|
||||
public function testQuoteStrings(string $description, ?array $expected, array $array): void
|
||||
{
|
||||
self::assertSame($expected, Arrays::quoteStrings($array), $description);
|
||||
}
|
||||
|
||||
public function testRemoveMarginalElement()
|
||||
/**
|
||||
* @param string $description Description of test case
|
||||
* @param array $array The array which should be shortened
|
||||
* @param bool $last If is set to true, last element is removed (default behaviour). Otherwise - first.
|
||||
* @param null|array $expected Expected result
|
||||
*
|
||||
* @dataProvider provideArrayToRemoveMarginalElement
|
||||
*/
|
||||
public function testRemoveMarginalElement(string $description, array $array, bool $last, ?array $expected): void
|
||||
{
|
||||
$array = $this->simpleArray;
|
||||
$string = 'Lorem ipsum';
|
||||
|
||||
// Removing first element
|
||||
self::assertSame([
|
||||
0 => 'Lorem',
|
||||
1 => 'ipsum',
|
||||
2 => 'dolor',
|
||||
3 => 'sit',
|
||||
], Arrays::removeMarginalElement($array));
|
||||
self::assertEquals('Lorem ipsu', Arrays::removeMarginalElement($string));
|
||||
|
||||
// Removing last element
|
||||
self::assertSame([
|
||||
1 => 'ipsum',
|
||||
2 => 'dolor',
|
||||
3 => 'sit',
|
||||
4 => 'amet',
|
||||
], Arrays::removeMarginalElement($array, false));
|
||||
self::assertEquals('orem ipsum', Arrays::removeMarginalElement($string, false));
|
||||
self::assertSame($expected, Arrays::removeMarginalElement($array, $last), $description);
|
||||
}
|
||||
|
||||
public function testRemoveElements()
|
||||
public function testRemoveElements(): void
|
||||
{
|
||||
$array1 = $this->simpleArray;
|
||||
$array2 = $this->simpleArray;
|
||||
@@ -467,7 +455,7 @@ letsTest[2] = value_2;';
|
||||
self::assertEquals($replaced, Arrays::setKeysAsValues($array, false));
|
||||
}
|
||||
|
||||
public function testGetNonArrayElementsCount()
|
||||
public function testGetNonArrayElementsCount(): void
|
||||
{
|
||||
// Negative cases
|
||||
self::assertNull(Arrays::getNonArrayElementsCount([]));
|
||||
@@ -478,11 +466,10 @@ letsTest[2] = value_2;';
|
||||
self::assertEquals(12, Arrays::getNonArrayElementsCount($this->twoDimensionsArray));
|
||||
}
|
||||
|
||||
public function testString2array()
|
||||
public function testString2array(): void
|
||||
{
|
||||
// Negative cases
|
||||
self::assertNull(Arrays::string2array(''));
|
||||
self::assertNull(Arrays::string2array(null));
|
||||
|
||||
// Positive cases
|
||||
$array = [
|
||||
@@ -504,7 +491,7 @@ letsTest[2] = value_2;';
|
||||
self::assertEquals($array, Arrays::string2array('red : #f00 | green : #0f0 | blue : #00f'));
|
||||
}
|
||||
|
||||
public function testAreKeysInArray()
|
||||
public function testAreKeysInArray(): void
|
||||
{
|
||||
// Negative cases
|
||||
self::assertFalse(Arrays::areKeysInArray([], []));
|
||||
@@ -568,12 +555,12 @@ letsTest[2] = value_2;';
|
||||
self::assertTrue(Arrays::areKeysInArray($keys17, $this->complexArray, false));
|
||||
}
|
||||
|
||||
public function testGetLastElementsPathsUsingEmptyArray()
|
||||
public function testGetLastElementsPathsUsingEmptyArray(): void
|
||||
{
|
||||
self::assertNull(Arrays::getLastElementsPaths([]));
|
||||
}
|
||||
|
||||
public function testGetLastElementsPathsUsingDefaults()
|
||||
public function testGetLastElementsPathsUsingDefaults(): void
|
||||
{
|
||||
// Using default separator and other default arguments
|
||||
$expected = [
|
||||
@@ -592,7 +579,7 @@ letsTest[2] = value_2;';
|
||||
self::assertEquals($expected, Arrays::getLastElementsPaths($this->complexArray));
|
||||
}
|
||||
|
||||
public function testGetLastElementsPathsUsingCustomSeparator()
|
||||
public function testGetLastElementsPathsUsingCustomSeparator(): void
|
||||
{
|
||||
// Using custom separator
|
||||
$separator = ' -> ';
|
||||
@@ -613,20 +600,24 @@ letsTest[2] = value_2;';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|string $stopIfMatchedBy Patterns of keys or paths that matched will stop the process of path
|
||||
* building and including children of those keys or paths (recursive will
|
||||
* not be used for keys in lower level of given array)
|
||||
* @param string $separator Separator used in resultant strings. Default: ".".
|
||||
* @param array $expected Expected array
|
||||
* @param array $stopIfMatchedBy Patterns of keys or paths that matched will stop the process of path building and
|
||||
* including children of those keys or paths (recursive will not be used for keys in
|
||||
* lower level of given array)
|
||||
* @param string $separator Separator used in resultant strings. Default: ".".
|
||||
* @param array $expected Expected array
|
||||
*
|
||||
* @dataProvider provideStopIfMatchedByForGetLastElementsPaths
|
||||
*/
|
||||
public function testGetLastElementsPathsUsingStopIfMatchedBy($stopIfMatchedBy, $separator, array $expected)
|
||||
{
|
||||
self::assertEquals($expected, Arrays::getLastElementsPaths($this->superComplexArray, $separator, '', $stopIfMatchedBy));
|
||||
public function testGetLastElementsPathsUsingStopIfMatchedBy(
|
||||
array $stopIfMatchedBy,
|
||||
string $separator,
|
||||
array $expected
|
||||
): void {
|
||||
$paths = Arrays::getLastElementsPaths($this->superComplexArray, $separator, '', $stopIfMatchedBy);
|
||||
self::assertEquals($expected, $paths);
|
||||
}
|
||||
|
||||
public function testAreAllKeysMatchedByPattern()
|
||||
public function testAreAllKeysMatchedByPattern(): void
|
||||
{
|
||||
$pattern = '\d+';
|
||||
|
||||
@@ -1471,6 +1462,30 @@ letsTest[2] = value_2;';
|
||||
self::assertSame($expected, Arrays::getNonEmptyValuesAsString($values, $separator), $description);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description Description of test case
|
||||
* @param mixed $value The value to verify
|
||||
* @param bool $expected Expected information
|
||||
*
|
||||
* @dataProvider provideValueToIsEmptyArray
|
||||
*/
|
||||
public function testIsEmptyArray(string $description, $value, bool $expected): void
|
||||
{
|
||||
self::assertSame($expected, Arrays::isEmptyArray($value), $description);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description Description of test case
|
||||
* @param mixed $value The value to verify
|
||||
* @param bool $expected Expected information
|
||||
*
|
||||
* @dataProvider provideValueToIsNotEmptyArray
|
||||
*/
|
||||
public function testIsNotEmptyArray(string $description, $value, bool $expected): void
|
||||
{
|
||||
self::assertSame($expected, Arrays::isNotEmptyArray($value), $description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides simple array to set/replace values with keys
|
||||
*
|
||||
@@ -1573,13 +1588,13 @@ letsTest[2] = value_2;';
|
||||
* Provides patterns of keys or paths that matched will stop the process and the expected array for the
|
||||
* getLastElementsPaths() method
|
||||
*
|
||||
* @return \Generator
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideStopIfMatchedByForGetLastElementsPaths()
|
||||
public function provideStopIfMatchedByForGetLastElementsPaths(): ?Generator
|
||||
{
|
||||
// Special exception: do not use, stop recursive on the "diam" key
|
||||
yield[
|
||||
'diam',
|
||||
['diam'],
|
||||
'.',
|
||||
[
|
||||
'ipsum.quis.vestibulum.porta-1.0' => 'turpis',
|
||||
@@ -1787,9 +1802,9 @@ letsTest[2] = value_2;';
|
||||
/**
|
||||
* Provide values to filter and get non-empty values
|
||||
*
|
||||
* @return \Generator
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideValuesToFilterNonEmpty()
|
||||
public function provideValuesToFilterNonEmpty(): ?Generator
|
||||
{
|
||||
$simpleObject = new SimpleToString('1234');
|
||||
|
||||
@@ -2554,6 +2569,307 @@ letsTest[2] = value_2;';
|
||||
];
|
||||
}
|
||||
|
||||
public function provideValueToIsEmptyArray(): ?\Generator
|
||||
{
|
||||
yield[
|
||||
'An empty string',
|
||||
'',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'Non-empty string',
|
||||
'test',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'Null',
|
||||
null,
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'An integer equals 0',
|
||||
1234,
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'An integer greater than 0',
|
||||
1234,
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'An empty array',
|
||||
[],
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'Non-empty array',
|
||||
[
|
||||
'test',
|
||||
],
|
||||
false,
|
||||
];
|
||||
}
|
||||
|
||||
public function provideValueToIsNotEmptyArray(): ?\Generator
|
||||
{
|
||||
yield[
|
||||
'An empty string',
|
||||
'',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'Non-empty string',
|
||||
'test',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'Null',
|
||||
null,
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'An integer equals 0',
|
||||
1234,
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'An integer greater than 0',
|
||||
1234,
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'An empty array',
|
||||
[],
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'Non-empty array',
|
||||
[
|
||||
'test',
|
||||
],
|
||||
true,
|
||||
];
|
||||
}
|
||||
|
||||
public function provideArrayToRemoveMarginalElement(): Generator
|
||||
{
|
||||
yield[
|
||||
'An empty array - remove last element',
|
||||
[],
|
||||
true,
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
'An empty array - remove first element',
|
||||
[],
|
||||
false,
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
'One-dimensional array - remove last element',
|
||||
[
|
||||
'Lorem',
|
||||
'ipsum',
|
||||
'dolor',
|
||||
'sit',
|
||||
'amet',
|
||||
],
|
||||
true,
|
||||
[
|
||||
0 => 'Lorem',
|
||||
1 => 'ipsum',
|
||||
2 => 'dolor',
|
||||
3 => 'sit',
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
'One-dimensional array - remove first element',
|
||||
[
|
||||
'Lorem',
|
||||
'ipsum',
|
||||
'dolor',
|
||||
'sit',
|
||||
'amet',
|
||||
],
|
||||
false,
|
||||
[
|
||||
1 => 'ipsum',
|
||||
2 => 'dolor',
|
||||
3 => 'sit',
|
||||
4 => 'amet',
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
'Multi-dimensional array - remove last element',
|
||||
[
|
||||
'lorem' => [
|
||||
'ipsum' => [
|
||||
'dolor' => 'sit',
|
||||
'diam' => [
|
||||
'non' => 'egestas',
|
||||
],
|
||||
],
|
||||
],
|
||||
'consectetur' => 'adipiscing',
|
||||
'mollis' => 1234,
|
||||
2 => [],
|
||||
'sit' => [
|
||||
'nullam' => 'donec',
|
||||
'aliquet' => [
|
||||
'vitae' => [
|
||||
'ligula' => 'quis',
|
||||
],
|
||||
],
|
||||
'elit',
|
||||
],
|
||||
'amet' => [
|
||||
'iaculis',
|
||||
'primis',
|
||||
],
|
||||
],
|
||||
true,
|
||||
[
|
||||
'lorem' => [
|
||||
'ipsum' => [
|
||||
'dolor' => 'sit',
|
||||
'diam' => [
|
||||
'non' => 'egestas',
|
||||
],
|
||||
],
|
||||
],
|
||||
'consectetur' => 'adipiscing',
|
||||
'mollis' => 1234,
|
||||
2 => [],
|
||||
'sit' => [
|
||||
'nullam' => 'donec',
|
||||
'aliquet' => [
|
||||
'vitae' => [
|
||||
'ligula' => 'quis',
|
||||
],
|
||||
],
|
||||
'elit',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
'Multi-dimensional array - remove first element',
|
||||
[
|
||||
'lorem' => [
|
||||
'ipsum' => [
|
||||
'dolor' => 'sit',
|
||||
'diam' => [
|
||||
'non' => 'egestas',
|
||||
],
|
||||
],
|
||||
],
|
||||
'consectetur' => 'adipiscing',
|
||||
'mollis' => 1234,
|
||||
2 => [],
|
||||
'sit' => [
|
||||
'nullam' => 'donec',
|
||||
'aliquet' => [
|
||||
'vitae' => [
|
||||
'ligula' => 'quis',
|
||||
],
|
||||
],
|
||||
'elit',
|
||||
],
|
||||
'amet' => [
|
||||
'iaculis',
|
||||
'primis',
|
||||
],
|
||||
],
|
||||
false,
|
||||
[
|
||||
'consectetur' => 'adipiscing',
|
||||
'mollis' => 1234,
|
||||
2 => [],
|
||||
'sit' => [
|
||||
'nullam' => 'donec',
|
||||
'aliquet' => [
|
||||
'vitae' => [
|
||||
'ligula' => 'quis',
|
||||
],
|
||||
],
|
||||
'elit',
|
||||
],
|
||||
'amet' => [
|
||||
'iaculis',
|
||||
'primis',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function provideArrayToReplaceKeys(): Generator
|
||||
{
|
||||
yield[
|
||||
'An empty array',
|
||||
[],
|
||||
'',
|
||||
'',
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
'1st case',
|
||||
[
|
||||
'nullam' => 'donec',
|
||||
'aliquet' => [
|
||||
'vitae' => [
|
||||
'ligula' => 'quis',
|
||||
],
|
||||
],
|
||||
'elit',
|
||||
],
|
||||
'|.*li.*|',
|
||||
'x',
|
||||
[
|
||||
'nullam' => 'donec',
|
||||
'x' => [
|
||||
'vitae' => [
|
||||
'x' => 'quis',
|
||||
],
|
||||
],
|
||||
'elit',
|
||||
],
|
||||
];
|
||||
|
||||
yield[
|
||||
'2nd case',
|
||||
[
|
||||
'Lorem',
|
||||
'ipsum',
|
||||
'dolor',
|
||||
'sit',
|
||||
'amet',
|
||||
],
|
||||
'|[0-3]+|',
|
||||
'x',
|
||||
[
|
||||
'x' => 'sit',
|
||||
4 => 'amet',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
||||
@@ -28,7 +28,7 @@ use Meritoo\Common\Utilities\Locale;
|
||||
*/
|
||||
class DateTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertHasNoConstructor(Date::class);
|
||||
}
|
||||
@@ -37,7 +37,7 @@ class DateTest extends BaseTestCase
|
||||
* @param mixed $value Empty value, e.g. ""
|
||||
* @dataProvider provideEmptyValue
|
||||
*/
|
||||
public function testGetDateTimeEmptyValue($value)
|
||||
public function testGetDateTimeEmptyValue($value): void
|
||||
{
|
||||
self::assertFalse(Date::getDateTime($value));
|
||||
}
|
||||
@@ -46,7 +46,7 @@ class DateTest extends BaseTestCase
|
||||
* @param mixed $value Incorrect source of DateTime
|
||||
* @dataProvider provideIncorrectDateTimeValue
|
||||
*/
|
||||
public function testGetDateTimeIncorrectValue($value)
|
||||
public function testGetDateTimeIncorrectValue($value): void
|
||||
{
|
||||
self::assertFalse(Date::getDateTime($value));
|
||||
}
|
||||
@@ -55,7 +55,7 @@ class DateTest extends BaseTestCase
|
||||
* @param bool $value The value which maybe is a date
|
||||
* @dataProvider provideBooleanValue
|
||||
*/
|
||||
public function testGetDateTimeBoolean($value)
|
||||
public function testGetDateTimeBoolean($value): void
|
||||
{
|
||||
self::assertFalse(Date::getDateTime($value));
|
||||
}
|
||||
@@ -64,7 +64,7 @@ class DateTest extends BaseTestCase
|
||||
* @param string $relativeFormat Relative / compound format of DateTime
|
||||
* @dataProvider provideDateTimeRelativeFormat
|
||||
*/
|
||||
public function testGetDateTimeRelativeFormats($relativeFormat)
|
||||
public function testGetDateTimeRelativeFormats($relativeFormat): void
|
||||
{
|
||||
/*
|
||||
* Values based on relative / compound formats, but... without explicitly declaring them as compound
|
||||
@@ -85,12 +85,12 @@ class DateTest extends BaseTestCase
|
||||
* @param DateTime $dateTime Instance of DateTime class
|
||||
* @dataProvider provideDateTimeInstance
|
||||
*/
|
||||
public function testGetDateTimeInstanceDateTime(DateTime $dateTime)
|
||||
public function testGetDateTimeInstanceDateTime(DateTime $dateTime): void
|
||||
{
|
||||
self::assertInstanceOf(DateTime::class, Date::getDateTime($dateTime));
|
||||
}
|
||||
|
||||
public function testGetDateTimeConcreteDates()
|
||||
public function testGetDateTimeConcreteDates(): void
|
||||
{
|
||||
// Using the standard date format provided by the tested method
|
||||
self::assertInstanceOf(DateTime::class, Date::getDateTime('2015-03-20'));
|
||||
@@ -104,7 +104,7 @@ class DateTest extends BaseTestCase
|
||||
* @param mixed $value Empty value, e.g. ""
|
||||
* @dataProvider provideEmptyValue
|
||||
*/
|
||||
public function testIsValidDateEmptyDates($value)
|
||||
public function testIsValidDateEmptyDates($value): void
|
||||
{
|
||||
self::assertFalse(Date::isValidDate($value));
|
||||
}
|
||||
@@ -113,12 +113,12 @@ class DateTest extends BaseTestCase
|
||||
* @param mixed $value Incorrect source of DateTime
|
||||
* @dataProvider provideIncorrectDateTimeValue
|
||||
*/
|
||||
public function testIsValidDateIncorrectDates($value)
|
||||
public function testIsValidDateIncorrectDates($value): void
|
||||
{
|
||||
self::assertFalse(Date::isValidDate($value));
|
||||
}
|
||||
|
||||
public function testIsValidDateValidDates()
|
||||
public function testIsValidDateValidDates(): void
|
||||
{
|
||||
self::assertTrue(Date::isValidDate('2017-01-01'));
|
||||
self::assertTrue(Date::isValidDate('2017-01-01 10:30', true));
|
||||
@@ -134,7 +134,7 @@ class DateTest extends BaseTestCase
|
||||
* @param mixed $value Empty source of date format
|
||||
* @dataProvider provideEmptyValue
|
||||
*/
|
||||
public function testIsValidDateFormatEmptyFormats($value)
|
||||
public function testIsValidDateFormatEmptyFormats($value): void
|
||||
{
|
||||
self::assertFalse(Date::isValidDateFormat($value));
|
||||
}
|
||||
@@ -143,12 +143,12 @@ class DateTest extends BaseTestCase
|
||||
* @param mixed $format Invalid format of date
|
||||
* @dataProvider provideInvalidDateFormats
|
||||
*/
|
||||
public function testIsValidDateFormatInvalidFormats($format)
|
||||
public function testIsValidDateFormatInvalidFormats($format): void
|
||||
{
|
||||
self::assertFalse(Date::isValidDateFormat($format));
|
||||
}
|
||||
|
||||
public function testIsValidDateFormatValidFormats()
|
||||
public function testIsValidDateFormatValidFormats(): void
|
||||
{
|
||||
self::assertTrue(Date::isValidDateFormat('Y'));
|
||||
self::assertTrue(Date::isValidDateFormat('yy'));
|
||||
@@ -165,12 +165,12 @@ class DateTest extends BaseTestCase
|
||||
* @param mixed $value Empty value, e.g. ""
|
||||
* @dataProvider provideEmptyValue
|
||||
*/
|
||||
public function testGenerateRandomTimeEmptyFormat($value)
|
||||
public function testGenerateRandomTimeEmptyFormat($value): void
|
||||
{
|
||||
self::assertNull(Date::generateRandomTime($value));
|
||||
}
|
||||
|
||||
public function testGenerateRandomTimeIncorrectFormat()
|
||||
public function testGenerateRandomTimeIncorrectFormat(): void
|
||||
{
|
||||
self::assertNull(Date::generateRandomTime(','));
|
||||
self::assertNull(Date::generateRandomTime(';'));
|
||||
@@ -178,12 +178,12 @@ class DateTest extends BaseTestCase
|
||||
self::assertNull(Date::generateRandomTime('?'));
|
||||
}
|
||||
|
||||
public function testGenerateRandomTimeDefaultFormat()
|
||||
public function testGenerateRandomTimeDefaultFormat(): void
|
||||
{
|
||||
self::assertRegExp('/\d{2}:\d{2}:\d{2}/', Date::generateRandomTime());
|
||||
}
|
||||
|
||||
public function testGenerateRandomTimeCustomFormat()
|
||||
public function testGenerateRandomTimeCustomFormat(): void
|
||||
{
|
||||
self::assertRegExp('/^0[1-9]{1}|1[0-2]{1}$/', Date::generateRandomTime('h')); // 01 through 12
|
||||
self::assertRegExp('/^[0-5]?[0-9]$/', Date::generateRandomTime('i')); // 00 through 59
|
||||
@@ -193,12 +193,12 @@ class DateTest extends BaseTestCase
|
||||
self::assertRegExp('/^[1-9]|1[0-2]:\d{2}$/', Date::generateRandomTime('g:i'));
|
||||
}
|
||||
|
||||
public function testGetCurrentDayOfWeek()
|
||||
public function testGetCurrentDayOfWeek(): void
|
||||
{
|
||||
self::assertRegExp('/^[0-6]{1}$/', (string)Date::getCurrentDayOfWeek());
|
||||
}
|
||||
|
||||
public function testGetCurrentDayOfWeekName()
|
||||
public function testGetCurrentDayOfWeekName(): void
|
||||
{
|
||||
// Required to avoid failure:
|
||||
//
|
||||
@@ -228,7 +228,7 @@ class DateTest extends BaseTestCase
|
||||
*
|
||||
* @dataProvider provideIncorrectYearMonthDay
|
||||
*/
|
||||
public function testGetDayOfWeekIncorrectValues($year, $month, $day)
|
||||
public function testGetDayOfWeekIncorrectValues($year, $month, $day): void
|
||||
{
|
||||
$this->expectException(UnknownDatePartTypeException::class);
|
||||
self::assertEmpty(Date::getDayOfWeek($year, $month, $day));
|
||||
@@ -241,7 +241,7 @@ class DateTest extends BaseTestCase
|
||||
*
|
||||
* @dataProvider provideYearMonthDay
|
||||
*/
|
||||
public function testGetDayOfWeek($year, $month, $day)
|
||||
public function testGetDayOfWeek($year, $month, $day): void
|
||||
{
|
||||
self::assertRegExp('/^[0-6]{1}$/', (string)Date::getDayOfWeek($year, $month, $day));
|
||||
}
|
||||
@@ -252,18 +252,18 @@ class DateTest extends BaseTestCase
|
||||
*
|
||||
* @dataProvider provideEmptyDatesForDateDifference
|
||||
*/
|
||||
public function testGetDateDifferenceEmptyDates($dateStart, $dateEnd)
|
||||
public function testGetDateDifferenceEmptyDates($dateStart, $dateEnd): void
|
||||
{
|
||||
self::assertNull(Date::getDateDifference($dateStart, $dateEnd));
|
||||
}
|
||||
|
||||
public function testGetDateDifferenceInvalidDates()
|
||||
public function testGetDateDifferenceInvalidDates(): void
|
||||
{
|
||||
self::assertNull(Date::getDateDifference('2017-01-40', '2017-13-01'));
|
||||
self::assertNull(Date::getDateDifference('xyz', 'lorem'));
|
||||
}
|
||||
|
||||
public function testGetDateDifferenceOneDay()
|
||||
public function testGetDateDifferenceOneDay(): void
|
||||
{
|
||||
// Difference of 1 day
|
||||
$dateStart = '2017-01-01';
|
||||
@@ -311,7 +311,7 @@ class DateTest extends BaseTestCase
|
||||
self::assertEquals(0, Date::getDateDifference(new DateTime('yesterday'), new DateTime('midnight'), Date::DATE_DIFFERENCE_UNIT_MINUTES));
|
||||
}
|
||||
|
||||
public function testGetDateDifferenceOneDayTwoHours()
|
||||
public function testGetDateDifferenceOneDayTwoHours(): void
|
||||
{
|
||||
// Difference of 1 day, 2 hours and 15 minutes
|
||||
$dateStart = '2017-01-01 12:00';
|
||||
@@ -344,7 +344,7 @@ class DateTest extends BaseTestCase
|
||||
self::assertEquals(15, Date::getDateDifference(new DateTime($dateStart), new DateTime($dateEnd), Date::DATE_DIFFERENCE_UNIT_MINUTES));
|
||||
}
|
||||
|
||||
public function testGetDateDifferenceOneMonthFortyOneDays()
|
||||
public function testGetDateDifferenceOneMonthFortyOneDays(): void
|
||||
{
|
||||
// Difference of 1 month, 41 days, 4 hours and 30 minutes
|
||||
$dateStart = '2017-01-01 12:00';
|
||||
@@ -377,7 +377,7 @@ class DateTest extends BaseTestCase
|
||||
self::assertEquals(30, Date::getDateDifference(new DateTime($dateStart), new DateTime($dateEnd), Date::DATE_DIFFERENCE_UNIT_MINUTES));
|
||||
}
|
||||
|
||||
public function testGetDateDifferenceNewYear()
|
||||
public function testGetDateDifferenceNewYear(): void
|
||||
{
|
||||
$dateStart = '2017-12-31 23:59';
|
||||
$dateEnd = '2018-01-01 00:00';
|
||||
@@ -409,7 +409,7 @@ class DateTest extends BaseTestCase
|
||||
self::assertEquals(1, Date::getDateDifference(new DateTime($dateStart), new DateTime($dateEnd), Date::DATE_DIFFERENCE_UNIT_MINUTES));
|
||||
}
|
||||
|
||||
public function testGetDateDifferenceLessThan24Hours()
|
||||
public function testGetDateDifferenceLessThan24Hours(): void
|
||||
{
|
||||
$dateStart = '2017-01-01 16:00';
|
||||
$dateEnd = '2017-01-02 10:00';
|
||||
@@ -441,7 +441,7 @@ class DateTest extends BaseTestCase
|
||||
self::assertEquals(0, Date::getDateDifference(new DateTime($dateStart), new DateTime($dateEnd), Date::DATE_DIFFERENCE_UNIT_MINUTES));
|
||||
}
|
||||
|
||||
public function testGetDateDifferenceEqual24Hours()
|
||||
public function testGetDateDifferenceEqual24Hours(): void
|
||||
{
|
||||
$dateStart = '2017-01-01 00:00';
|
||||
$dateEnd = '2017-01-02 00:00';
|
||||
@@ -473,7 +473,7 @@ class DateTest extends BaseTestCase
|
||||
self::assertEquals(0, Date::getDateDifference(new DateTime($dateStart), new DateTime($dateEnd), Date::DATE_DIFFERENCE_UNIT_MINUTES));
|
||||
}
|
||||
|
||||
public function testGetDateDifferenceInvertedDates()
|
||||
public function testGetDateDifferenceInvertedDates(): void
|
||||
{
|
||||
$dateStart = '2017-01-02 10:00';
|
||||
$dateEnd = '2017-01-01 16:00';
|
||||
@@ -505,7 +505,7 @@ class DateTest extends BaseTestCase
|
||||
self::assertEquals(0, Date::getDateDifference(new DateTime($dateStart), new DateTime($dateEnd), Date::DATE_DIFFERENCE_UNIT_MINUTES));
|
||||
}
|
||||
|
||||
public function testGetDateDifferenceNoDifference()
|
||||
public function testGetDateDifferenceNoDifference(): void
|
||||
{
|
||||
// No difference
|
||||
$dateStart = '2017-01-01 12:00';
|
||||
@@ -542,7 +542,7 @@ class DateTest extends BaseTestCase
|
||||
* @param mixed $invalidCount Empty value, e.g. ""
|
||||
* @dataProvider provideEmptyValue
|
||||
*/
|
||||
public function testGetDatesCollectionInvalidCount($invalidCount)
|
||||
public function testGetDatesCollectionInvalidCount($invalidCount): void
|
||||
{
|
||||
self::assertEquals([], Date::getDatesCollection(new DateTime(), $invalidCount));
|
||||
self::assertEquals([], Date::getDatesCollection(new DateTime(), -1));
|
||||
@@ -552,14 +552,14 @@ class DateTest extends BaseTestCase
|
||||
* @param mixed $invalidInterval Empty value, e.g. ""
|
||||
* @dataProvider provideEmptyValue
|
||||
*/
|
||||
public function testGetDatesCollectionInvalidInterval($invalidInterval)
|
||||
public function testGetDatesCollectionInvalidInterval($invalidInterval): void
|
||||
{
|
||||
self::assertEquals([], Date::getDatesCollection(new DateTime(), 2, $invalidInterval));
|
||||
self::assertEquals([], Date::getDatesCollection(new DateTime(), 2, 'lorem'));
|
||||
self::assertEquals([], Date::getDatesCollection(new DateTime(), 2, '%d'));
|
||||
}
|
||||
|
||||
public function testGetDatesCollection()
|
||||
public function testGetDatesCollection(): void
|
||||
{
|
||||
// 1 date only
|
||||
$effect = [
|
||||
@@ -596,7 +596,7 @@ class DateTest extends BaseTestCase
|
||||
self::assertEquals($effect, Date::getDatesCollection(new DateTime('2017-01-01'), 3, 'P%dM'));
|
||||
}
|
||||
|
||||
public function testGetRandomDateUsingDefaults()
|
||||
public function testGetRandomDateUsingDefaults(): void
|
||||
{
|
||||
$startDate = new DateTime();
|
||||
$start = 1;
|
||||
@@ -619,7 +619,7 @@ class DateTest extends BaseTestCase
|
||||
*
|
||||
* @dataProvider provideDataOfRandomDateIncorrectEnd
|
||||
*/
|
||||
public function testGetRandomDateIncorrectEnd(DateTime $startDate, $start, $end)
|
||||
public function testGetRandomDateIncorrectEnd(DateTime $startDate, $start, $end): void
|
||||
{
|
||||
$randomDate = Date::getRandomDate($startDate, $start, $end);
|
||||
|
||||
@@ -636,7 +636,7 @@ class DateTest extends BaseTestCase
|
||||
*
|
||||
* @dataProvider provideDataOfRandomDate
|
||||
*/
|
||||
public function testGetRandomDate(DateTime $startDate, $start, $end)
|
||||
public function testGetRandomDate(DateTime $startDate, $start, $end): void
|
||||
{
|
||||
$randomDate = Date::getRandomDate($startDate, $start, $end);
|
||||
|
||||
@@ -651,9 +651,9 @@ class DateTest extends BaseTestCase
|
||||
|
||||
/**
|
||||
* @param mixed $period Empty value, e.g. ""
|
||||
* @dataProvider provideEmptyValue
|
||||
* @dataProvider provideEmptyScalarValue
|
||||
*/
|
||||
public function testGetDatesForPeriodUsingEmptyPeriod($period)
|
||||
public function testGetDatesForPeriodUsingEmptyPeriod($period): void
|
||||
{
|
||||
self::assertNull(Date::getDatesForPeriod($period));
|
||||
}
|
||||
@@ -662,7 +662,7 @@ class DateTest extends BaseTestCase
|
||||
* @param int $period Incorrect period to verify
|
||||
* @dataProvider provideIncorrectPeriod
|
||||
*/
|
||||
public function testGetDatesForPeriodUsingIncorrectPeriod($period)
|
||||
public function testGetDatesForPeriodUsingIncorrectPeriod($period): void
|
||||
{
|
||||
self::assertNull(Date::getDatesForPeriod($period));
|
||||
}
|
||||
@@ -674,7 +674,7 @@ class DateTest extends BaseTestCase
|
||||
*
|
||||
* @dataProvider provideCorrectPeriod
|
||||
*/
|
||||
public function testGetDatesForPeriod($period, DatePeriod $expected)
|
||||
public function testGetDatesForPeriod($period, DatePeriod $expected): void
|
||||
{
|
||||
self::assertEquals($expected, Date::getDatesForPeriod($period));
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ use stdClass;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Utilities\Miscellaneous
|
||||
* @covers \Meritoo\Common\Utilities\Miscellaneous
|
||||
*/
|
||||
class MiscellaneousTest extends BaseTestCase
|
||||
{
|
||||
@@ -707,22 +707,40 @@ class MiscellaneousTest extends BaseTestCase
|
||||
*
|
||||
* @dataProvider provideNumberToFillMissingZeros
|
||||
*/
|
||||
public function testFillMissingZeros($number, $length, $before, $expected)
|
||||
public function testFillMissingZeros($number, $length, $before, $expected): void
|
||||
{
|
||||
self::assertSame($expected, Miscellaneous::fillMissingZeros($number, $length, $before));
|
||||
}
|
||||
|
||||
public function testGetProjectRootPath()
|
||||
public function testGetProjectRootPath(): void
|
||||
{
|
||||
self::assertNotEmpty(Miscellaneous::getProjectRootPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description Description of test case
|
||||
* @param string $string The string which should be shortened
|
||||
* @param bool $last (optional) If is set to true, last element is removed (default behaviour).
|
||||
* Otherwise - first.
|
||||
* @param null|string $expected Expected result
|
||||
*
|
||||
* @dataProvider provideStringToRemoveMarginalCharacter
|
||||
*/
|
||||
public function testRemoveMarginalCharacter(
|
||||
string $description,
|
||||
string $string,
|
||||
bool $last,
|
||||
?string $expected
|
||||
): void {
|
||||
self::assertEquals($expected, Miscellaneous::removeMarginalCharacter($string, $last), $description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides string to convert characters to latin characters and not lower cased and not human-readable
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideStringToLatinNotLowerCaseHuman()
|
||||
public function provideStringToLatinNotLowerCaseHuman(): ?Generator
|
||||
{
|
||||
yield[
|
||||
'asuo',
|
||||
@@ -1443,6 +1461,51 @@ class MiscellaneousTest extends BaseTestCase
|
||||
];
|
||||
}
|
||||
|
||||
public function provideStringToRemoveMarginalCharacter(): ?Generator
|
||||
{
|
||||
yield[
|
||||
'An empty string - remove last character',
|
||||
'',
|
||||
true,
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
'An empty string - remove first character',
|
||||
'',
|
||||
false,
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
'Simple, two words - remove last character',
|
||||
'Lorem ipsum',
|
||||
true,
|
||||
'Lorem ipsu',
|
||||
];
|
||||
|
||||
yield[
|
||||
'Simple, two words - remove first character',
|
||||
'Lorem ipsum',
|
||||
false,
|
||||
'orem ipsum',
|
||||
];
|
||||
|
||||
yield[
|
||||
'Two sentences - remove last character',
|
||||
'Etiam ullamcorper. Suspendisse a pellentesque dui, non felis.',
|
||||
true,
|
||||
'Etiam ullamcorper. Suspendisse a pellentesque dui, non felis',
|
||||
];
|
||||
|
||||
yield[
|
||||
'Two sentences - remove first character',
|
||||
'Etiam ullamcorper. Suspendisse a pellentesque dui, non felis.',
|
||||
false,
|
||||
'tiam ullamcorper. Suspendisse a pellentesque dui, non felis.',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
||||
@@ -49,20 +49,20 @@ class ReflectionTest extends BaseTestCase
|
||||
* @param mixed $invalidClass Empty value, e.g. ""
|
||||
* @dataProvider provideEmptyValue
|
||||
*/
|
||||
public function testGetClassNameInvalidClass($invalidClass)
|
||||
public function testGetClassNameInvalidClass($invalidClass): void
|
||||
{
|
||||
self::assertNull(Reflection::getClassName($invalidClass));
|
||||
self::assertNull(Reflection::getClassName(123));
|
||||
}
|
||||
|
||||
public function testGetClassNameNotExistingClass()
|
||||
public function testGetClassNameNotExistingClass(): void
|
||||
{
|
||||
// Not existing class
|
||||
self::assertEquals('', Reflection::getClassName('xyz'));
|
||||
self::assertEquals('', Reflection::getClassName('xyz', true));
|
||||
}
|
||||
|
||||
public function testGetClassNameExistingClass()
|
||||
public function testGetClassNameExistingClass(): void
|
||||
{
|
||||
// Existing class
|
||||
self::assertEquals(self::class, Reflection::getClassName(self::class));
|
||||
@@ -77,9 +77,9 @@ class ReflectionTest extends BaseTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* A case when namespace of class contains name of class (name of class is duplicated, occurs twice)
|
||||
* A case when namespace of class contains name of class (iow. name of class occurs twice)
|
||||
*/
|
||||
public function testGetClassWhileNamespaceContainsClassName()
|
||||
public function testGetClassWhileNamespaceContainsClassName(): void
|
||||
{
|
||||
self::assertEquals(
|
||||
'Meritoo\Common\Collection\Collection',
|
||||
@@ -92,13 +92,13 @@ class ReflectionTest extends BaseTestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetClassNamespaceNotExistingClass()
|
||||
public function testGetClassNamespaceNotExistingClass(): void
|
||||
{
|
||||
// Not existing class
|
||||
self::assertEquals('', Reflection::getClassNamespace('xyz'));
|
||||
}
|
||||
|
||||
public function testGetClassNamespaceExistingClass()
|
||||
public function testGetClassNamespaceExistingClass(): void
|
||||
{
|
||||
// Existing class
|
||||
self::assertEquals('Meritoo\Test\Common\Utilities', Reflection::getClassNamespace(self::class));
|
||||
|
||||
Reference in New Issue
Block a user