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:
@@ -13,6 +13,7 @@ use Generator;
|
||||
use Meritoo\Common\Collection\Collection;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* Test case of the collection of elements
|
||||
@@ -21,7 +22,7 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Collection\Collection
|
||||
* @covers \Meritoo\Common\Collection\Collection
|
||||
*/
|
||||
class CollectionTest extends BaseTestCase
|
||||
{
|
||||
@@ -327,7 +328,16 @@ class CollectionTest extends BaseTestCase
|
||||
|
||||
public function testExistsVisibilityAndArguments()
|
||||
{
|
||||
static::assertMethodVisibilityAndArguments(Collection::class, 'exists', OopVisibilityType::IS_PRIVATE, 1, 1);
|
||||
$reflectionClass = new ReflectionClass(Collection::class);
|
||||
$method = $reflectionClass->getMethod('exists');
|
||||
|
||||
static::assertMethodVisibilityAndArguments(
|
||||
Collection::class,
|
||||
$method,
|
||||
OopVisibilityType::IS_PRIVATE,
|
||||
1,
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
namespace Meritoo\Test\Common\Exception\Bundle;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\Bundle\IncorrectBundleNameException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
@@ -23,7 +24,7 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
*/
|
||||
class IncorrectBundleNameExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
IncorrectBundleNameException::class,
|
||||
@@ -39,13 +40,13 @@ class IncorrectBundleNameExceptionTest extends BaseTestCase
|
||||
*
|
||||
* @dataProvider provideBundleNameAndMessage
|
||||
*/
|
||||
public function testCreate($description, $bundleName, $expectedMessage)
|
||||
public function testCreate(string $description, string $bundleName, string $expectedMessage): void
|
||||
{
|
||||
$exception = IncorrectBundleNameException::create($bundleName);
|
||||
static::assertSame($expectedMessage, $exception->getMessage(), $description);
|
||||
}
|
||||
|
||||
public function provideBundleNameAndMessage()
|
||||
public function provideBundleNameAndMessage(): Generator
|
||||
{
|
||||
$template = 'Name of bundle \'%s\' is incorrect. It should start with big letter and end with "Bundle". Is'
|
||||
. ' there everything ok?';
|
||||
@@ -56,12 +57,6 @@ class IncorrectBundleNameExceptionTest extends BaseTestCase
|
||||
sprintf($template, ''),
|
||||
];
|
||||
|
||||
yield[
|
||||
'Null as name of bundle',
|
||||
null,
|
||||
sprintf($template, ''),
|
||||
];
|
||||
|
||||
yield[
|
||||
'String with spaces as name of bundle',
|
||||
'This is test',
|
||||
|
||||
@@ -12,6 +12,7 @@ use Generator;
|
||||
use Meritoo\Common\Exception\Reflection\CannotResolveClassNameException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while name of class or trait cannot be resolved
|
||||
@@ -20,13 +21,17 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Reflection\CannotResolveClassNameException
|
||||
* @covers \Meritoo\Common\Exception\Reflection\CannotResolveClassNameException
|
||||
*/
|
||||
class CannotResolveClassNameExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
public function testConstructorVisibilityAndArguments(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(CannotResolveClassNameException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
CannotResolveClassNameException::class,
|
||||
OopVisibilityType::IS_PUBLIC,
|
||||
3
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,7 +43,7 @@ class CannotResolveClassNameExceptionTest extends BaseTestCase
|
||||
*
|
||||
* @dataProvider provideClassName
|
||||
*/
|
||||
public function testConstructorMessage($source, $forClass, $expectedMessage)
|
||||
public function testCreate($source, bool $forClass, string $expectedMessage): void
|
||||
{
|
||||
$exception = CannotResolveClassNameException::create($source, $forClass);
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
@@ -50,7 +55,7 @@ class CannotResolveClassNameExceptionTest extends BaseTestCase
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideClassName()
|
||||
public function provideClassName(): Generator
|
||||
{
|
||||
yield[
|
||||
'Not\Existing\Class',
|
||||
@@ -66,8 +71,8 @@ class CannotResolveClassNameExceptionTest extends BaseTestCase
|
||||
|
||||
yield[
|
||||
[
|
||||
new \stdClass(),
|
||||
new \stdClass(),
|
||||
new stdClass(),
|
||||
new stdClass(),
|
||||
],
|
||||
true,
|
||||
'Name of class from given \'array\' cannot be resolved. Is there everything ok?',
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* (c) Meritoo.pl, http://www.meritoo.pl
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Meritoo\Test\Common\Exception\Reflection;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Exception\Reflection\ClassWithoutConstructorException;
|
||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
use Meritoo\Common\Utilities\Arrays;
|
||||
|
||||
/**
|
||||
* Test case of an exception used while given class hasn't constructor
|
||||
*
|
||||
* @author Meritoo <github@meritoo.pl>
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Reflection\ClassWithoutConstructorException
|
||||
*/
|
||||
class ClassWithoutConstructorExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
ClassWithoutConstructorException::class,
|
||||
OopVisibilityType::IS_PUBLIC,
|
||||
3
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description Description of test case
|
||||
* @param string $className Fully-qualified name of class that hasn't constructor
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider provideClassName
|
||||
*/
|
||||
public function testCreate(string $description, string $className, string $expectedMessage): void
|
||||
{
|
||||
$exception = ClassWithoutConstructorException::create($className);
|
||||
static::assertSame($expectedMessage, $exception->getMessage(), $description);
|
||||
}
|
||||
|
||||
public function provideClassName(): Generator
|
||||
{
|
||||
$template = 'Oops, class \'%s\' hasn\'t constructor. Did you use proper class?';
|
||||
|
||||
yield[
|
||||
'An empty name of class',
|
||||
'',
|
||||
sprintf($template, ''),
|
||||
];
|
||||
|
||||
yield[
|
||||
'The Arrays class',
|
||||
Arrays::class,
|
||||
sprintf($template, Arrays::class),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -20,13 +20,17 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Reflection\MissingChildClassesException
|
||||
* @covers \Meritoo\Common\Exception\Reflection\MissingChildClassesException
|
||||
*/
|
||||
class MissingChildClassesExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
public function testConstructorVisibilityAndArguments(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(MissingChildClassesException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
MissingChildClassesException::class,
|
||||
OopVisibilityType::IS_PUBLIC,
|
||||
3
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,7 +40,7 @@ class MissingChildClassesExceptionTest extends BaseTestCase
|
||||
*
|
||||
* @dataProvider provideParentClass
|
||||
*/
|
||||
public function testConstructorMessage($parentClass, $expectedMessage)
|
||||
public function testCreate($parentClass, string $expectedMessage): void
|
||||
{
|
||||
$exception = MissingChildClassesException::create($parentClass);
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
@@ -47,7 +51,7 @@ class MissingChildClassesExceptionTest extends BaseTestCase
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideParentClass()
|
||||
public function provideParentClass(): ?Generator
|
||||
{
|
||||
$template = 'The \'%s\' class requires one child class at least who will extend her (maybe is an abstract'
|
||||
. ' class), but the child classes are missing. Did you forget to extend this class?';
|
||||
|
||||
@@ -19,11 +19,11 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Reflection\NotExistingPropertyException
|
||||
* @covers \Meritoo\Common\Exception\Reflection\NotExistingPropertyException
|
||||
*/
|
||||
class NotExistingPropertyExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
NotExistingPropertyException::class,
|
||||
@@ -33,20 +33,20 @@ class NotExistingPropertyExceptionTest extends BaseTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description Description of test
|
||||
* @param mixed $object Object that should contains given property
|
||||
* @param string $property Name of the property
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
* @param string $description Description of test
|
||||
* @param mixed $object Object that should contains given property
|
||||
* @param null|string $property Name of the property
|
||||
* @param string $expectedMessage Expected exception's message
|
||||
*
|
||||
* @dataProvider provideObjectPropertyAndMessage
|
||||
*/
|
||||
public function testCreate($description, $object, $property, $expectedMessage)
|
||||
public function testCreate(string $description, $object, ?string $property, string $expectedMessage): void
|
||||
{
|
||||
$exception = NotExistingPropertyException::create($object, $property);
|
||||
static::assertSame($expectedMessage, $exception->getMessage(), $description);
|
||||
}
|
||||
|
||||
public function provideObjectPropertyAndMessage()
|
||||
public function provideObjectPropertyAndMessage(): ?\Generator
|
||||
{
|
||||
$template = 'Property \'%s\' does not exist in instance of class \'%s\'. Did you use proper name of property?';
|
||||
|
||||
|
||||
@@ -20,13 +20,17 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Reflection\TooManyChildClassesException
|
||||
* @covers \Meritoo\Common\Exception\Reflection\TooManyChildClassesException
|
||||
*/
|
||||
class TooManyChildClassesExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
public function testConstructor(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(TooManyChildClassesException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
TooManyChildClassesException::class,
|
||||
OopVisibilityType::IS_PUBLIC,
|
||||
3
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,7 +41,7 @@ class TooManyChildClassesExceptionTest extends BaseTestCase
|
||||
*
|
||||
* @dataProvider provideParentAndChildClasses
|
||||
*/
|
||||
public function testConstructorMessage($parentClass, array $childClasses, $expectedMessage)
|
||||
public function testCreate($parentClass, array $childClasses, string $expectedMessage): void
|
||||
{
|
||||
$exception = TooManyChildClassesException::create($parentClass, $childClasses);
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
@@ -49,7 +53,7 @@ class TooManyChildClassesExceptionTest extends BaseTestCase
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideParentAndChildClasses()
|
||||
public function provideParentAndChildClasses(): ?Generator
|
||||
{
|
||||
$template = "The '%s' class requires one child class at most who will extend her, but more than one child"
|
||||
. " class was found:\n- %s\n\nWhy did you create more than one classes that extend '%s' class?";
|
||||
|
||||
@@ -21,13 +21,17 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Exception\Type\UnknownOopVisibilityTypeException
|
||||
* @covers \Meritoo\Common\Exception\Type\UnknownOopVisibilityTypeException
|
||||
*/
|
||||
class UnknownOopVisibilityTypeExceptionTest extends BaseTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
public function testConstructorVisibilityAndArguments(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(UnknownOopVisibilityTypeException::class, OopVisibilityType::IS_PUBLIC, 3);
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
UnknownOopVisibilityTypeException::class,
|
||||
OopVisibilityType::IS_PUBLIC,
|
||||
3
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,7 +40,7 @@ class UnknownOopVisibilityTypeExceptionTest extends BaseTestCase
|
||||
*
|
||||
* @dataProvider provideUnknownType
|
||||
*/
|
||||
public function testConstructorMessage($unknownType, $expectedMessage)
|
||||
public function testConstructorMessage($unknownType, $expectedMessage): void
|
||||
{
|
||||
$exception = UnknownOopVisibilityTypeException::createException($unknownType);
|
||||
static::assertSame($expectedMessage, $exception->getMessage());
|
||||
@@ -47,7 +51,7 @@ class UnknownOopVisibilityTypeExceptionTest extends BaseTestCase
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideUnknownType()
|
||||
public function provideUnknownType(): Generator
|
||||
{
|
||||
$allTypes = (new OopVisibilityType())->getAll();
|
||||
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
|
||||
namespace Meritoo\Test\Common\Type;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Test\Base\BaseTypeTestCase;
|
||||
use Meritoo\Common\Type\Base\BaseType;
|
||||
use Meritoo\Common\Type\DatePartType;
|
||||
|
||||
/**
|
||||
@@ -25,7 +27,7 @@ class DatePartTypeTest extends BaseTypeTestCase
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function provideTypeToVerify()
|
||||
public function provideTypeToVerify(): Generator
|
||||
{
|
||||
yield[
|
||||
'',
|
||||
@@ -38,12 +40,12 @@ class DatePartTypeTest extends BaseTypeTestCase
|
||||
];
|
||||
|
||||
yield[
|
||||
0,
|
||||
'0',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
1,
|
||||
'1',
|
||||
false,
|
||||
];
|
||||
|
||||
@@ -81,22 +83,22 @@ class DatePartTypeTest extends BaseTypeTestCase
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getAllExpectedTypes()
|
||||
protected function getAllExpectedTypes(): array
|
||||
{
|
||||
return [
|
||||
'DAY' => DatePartType::DAY,
|
||||
'HOUR' => DatePartType::HOUR,
|
||||
'MINUTE' => DatePartType::MINUTE,
|
||||
'MONTH' => DatePartType::MONTH,
|
||||
'SECOND' => DatePartType::SECOND,
|
||||
'YEAR' => DatePartType::YEAR,
|
||||
'DAY' => 'day',
|
||||
'HOUR' => 'hour',
|
||||
'MINUTE' => 'minute',
|
||||
'MONTH' => 'month',
|
||||
'SECOND' => 'second',
|
||||
'YEAR' => 'year',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getTestedTypeInstance()
|
||||
protected function getTestedTypeInstance(): BaseType
|
||||
{
|
||||
return new DatePartType();
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace Meritoo\Test\Common\Type;
|
||||
use DateTime;
|
||||
use Generator;
|
||||
use Meritoo\Common\Test\Base\BaseTypeTestCase;
|
||||
use Meritoo\Common\Type\Base\BaseType;
|
||||
use Meritoo\Common\Type\DatePeriod;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
|
||||
@@ -21,13 +22,17 @@ use Meritoo\Common\Type\OopVisibilityType;
|
||||
* @copyright Meritoo <http://www.meritoo.pl>
|
||||
*
|
||||
* @internal
|
||||
* @covers \Meritoo\Common\Type\DatePeriod
|
||||
* @covers \Meritoo\Common\Type\DatePeriod
|
||||
*/
|
||||
class DatePeriodTest extends BaseTypeTestCase
|
||||
{
|
||||
public function testConstructorVisibilityAndArguments()
|
||||
public function testConstructorVisibilityAndArguments(): void
|
||||
{
|
||||
static::assertConstructorVisibilityAndArguments(DatePeriod::class, OopVisibilityType::IS_PUBLIC, 2, 0);
|
||||
static::assertConstructorVisibilityAndArguments(
|
||||
DatePeriod::class,
|
||||
OopVisibilityType::IS_PUBLIC,
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,7 +41,7 @@ class DatePeriodTest extends BaseTypeTestCase
|
||||
*
|
||||
* @dataProvider provideDatePeriod
|
||||
*/
|
||||
public function testConstruct(DateTime $startDate = null, DateTime $endDate = null)
|
||||
public function testConstruct(DateTime $startDate = null, DateTime $endDate = null): void
|
||||
{
|
||||
$period = new DatePeriod($startDate, $endDate);
|
||||
|
||||
@@ -50,7 +55,7 @@ class DatePeriodTest extends BaseTypeTestCase
|
||||
*
|
||||
* @dataProvider provideDatePeriod
|
||||
*/
|
||||
public function testGettersAndSetters(DateTime $startDate = null, DateTime $endDate = null)
|
||||
public function testGettersAndSetters(DateTime $startDate = null, DateTime $endDate = null): void
|
||||
{
|
||||
$period = new DatePeriod();
|
||||
|
||||
@@ -67,7 +72,7 @@ class DatePeriodTest extends BaseTypeTestCase
|
||||
*
|
||||
* @dataProvider provideDatePeriodAndIncorrectDateFormat
|
||||
*/
|
||||
public function testGetFormattedDateIncorrectDateFormat(DatePeriod $period, $format)
|
||||
public function testGetFormattedDateIncorrectDateFormat(DatePeriod $period, $format): void
|
||||
{
|
||||
self::assertEquals('', $period->getFormattedDate($format));
|
||||
}
|
||||
@@ -80,7 +85,7 @@ class DatePeriodTest extends BaseTypeTestCase
|
||||
*
|
||||
* @dataProvider provideDatePeriodAndDateFormat
|
||||
*/
|
||||
public function testGetFormattedDate(DatePeriod $period, $format, $startDate, $expected)
|
||||
public function testGetFormattedDate(DatePeriod $period, $format, $startDate, $expected): void
|
||||
{
|
||||
self::assertEquals($expected, $period->getFormattedDate($format, $startDate));
|
||||
}
|
||||
@@ -90,7 +95,7 @@ class DatePeriodTest extends BaseTypeTestCase
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideDatePeriod()
|
||||
public function provideDatePeriod(): Generator
|
||||
{
|
||||
$startDate = new DateTime('2001-01-01');
|
||||
$endDate = new DateTime('2002-02-02');
|
||||
@@ -123,7 +128,7 @@ class DatePeriodTest extends BaseTypeTestCase
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideDatePeriodAndIncorrectDateFormat()
|
||||
public function provideDatePeriodAndIncorrectDateFormat(): Generator
|
||||
{
|
||||
$startDate = new DateTime('2001-01-01');
|
||||
$endDate = new DateTime('2002-02-02');
|
||||
@@ -133,11 +138,6 @@ class DatePeriodTest extends BaseTypeTestCase
|
||||
'',
|
||||
];
|
||||
|
||||
yield[
|
||||
new DatePeriod($startDate, $endDate),
|
||||
null,
|
||||
];
|
||||
|
||||
yield[
|
||||
new DatePeriod($startDate, $endDate),
|
||||
false,
|
||||
@@ -149,7 +149,7 @@ class DatePeriodTest extends BaseTypeTestCase
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideDatePeriodAndDateFormat()
|
||||
public function provideDatePeriodAndDateFormat(): Generator
|
||||
{
|
||||
$startDate = new DateTime('2001-01-01');
|
||||
$endDate = new DateTime('2002-02-02');
|
||||
@@ -216,7 +216,7 @@ class DatePeriodTest extends BaseTypeTestCase
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function provideTypeToVerify()
|
||||
public function provideTypeToVerify(): Generator
|
||||
{
|
||||
yield[
|
||||
'',
|
||||
@@ -224,27 +224,22 @@ class DatePeriodTest extends BaseTypeTestCase
|
||||
];
|
||||
|
||||
yield[
|
||||
-1,
|
||||
'-1',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
true,
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
DatePeriod::LAST_MONTH,
|
||||
'4',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
DatePeriod::NEXT_WEEK,
|
||||
'3',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
DatePeriod::THIS_YEAR,
|
||||
'8',
|
||||
true,
|
||||
];
|
||||
}
|
||||
@@ -254,25 +249,25 @@ class DatePeriodTest extends BaseTypeTestCase
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getAllExpectedTypes()
|
||||
protected function getAllExpectedTypes(): array
|
||||
{
|
||||
return [
|
||||
'LAST_MONTH' => DatePeriod::LAST_MONTH,
|
||||
'LAST_WEEK' => DatePeriod::LAST_WEEK,
|
||||
'LAST_YEAR' => DatePeriod::LAST_YEAR,
|
||||
'NEXT_MONTH' => DatePeriod::NEXT_MONTH,
|
||||
'NEXT_WEEK' => DatePeriod::NEXT_WEEK,
|
||||
'NEXT_YEAR' => DatePeriod::NEXT_YEAR,
|
||||
'THIS_MONTH' => DatePeriod::THIS_MONTH,
|
||||
'THIS_WEEK' => DatePeriod::THIS_WEEK,
|
||||
'THIS_YEAR' => DatePeriod::THIS_YEAR,
|
||||
'LAST_MONTH' => 4,
|
||||
'LAST_WEEK' => 1,
|
||||
'LAST_YEAR' => 7,
|
||||
'NEXT_MONTH' => 6,
|
||||
'NEXT_WEEK' => 3,
|
||||
'NEXT_YEAR' => 9,
|
||||
'THIS_MONTH' => 5,
|
||||
'THIS_WEEK' => 2,
|
||||
'THIS_YEAR' => 8,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getTestedTypeInstance()
|
||||
protected function getTestedTypeInstance(): BaseType
|
||||
{
|
||||
return new DatePeriod();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
namespace Meritoo\Test\Common\Type;
|
||||
|
||||
use Generator;
|
||||
use Meritoo\Common\Test\Base\BaseTypeTestCase;
|
||||
use Meritoo\Common\Type\Base\BaseType;
|
||||
use Meritoo\Common\Type\OopVisibilityType;
|
||||
@@ -26,7 +27,7 @@ class OopVisibilityTypeTest extends BaseTypeTestCase
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function provideTypeToVerify(): ?\Generator
|
||||
public function provideTypeToVerify(): Generator
|
||||
{
|
||||
yield[
|
||||
'',
|
||||
@@ -39,27 +40,22 @@ class OopVisibilityTypeTest extends BaseTypeTestCase
|
||||
];
|
||||
|
||||
yield[
|
||||
-1,
|
||||
'-1',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
true,
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
1,
|
||||
'1',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
2,
|
||||
'2',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
3,
|
||||
'3',
|
||||
true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -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