mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 09:31:51 +01:00
BaseType::isCorrectType() method > make static
This commit is contained in:
@@ -94,7 +94,7 @@ class TestService
|
||||
*/
|
||||
public function getTranslatedType($type)
|
||||
{
|
||||
if ((new TestType())->isCorrectType($type)) {
|
||||
if (TestType::isCorrectType($type)) {
|
||||
return ucfirst(str_replace('_', ' ', $type));
|
||||
}
|
||||
|
||||
|
||||
@@ -41,15 +41,25 @@ class BaseTypeTest extends BaseTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BaseType $type Type of something
|
||||
* @param string $toVerifyType Concrete type to verify (of given instance of type)
|
||||
* @param bool $isCorrect Expected information if given type is correct
|
||||
* @param string $toVerifyType Concrete type to verify
|
||||
* @param bool $isCorrect Expected information if given type is correct
|
||||
*
|
||||
* @dataProvider provideTypeWithConcreteType
|
||||
* @dataProvider provideTypeToVerifyUsingTestEmptyType
|
||||
*/
|
||||
public function testIsCorrectType(BaseType $type, $toVerifyType, $isCorrect)
|
||||
public function testIsCorrectTypeUsingTestEmptyType(?string $toVerifyType, bool $isCorrect): void
|
||||
{
|
||||
self::assertEquals($isCorrect, $type->isCorrectType($toVerifyType));
|
||||
self::assertEquals($isCorrect, TestEmptyType::isCorrectType($toVerifyType));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $toVerifyType Concrete type to verify
|
||||
* @param bool $isCorrect Expected information if given type is correct
|
||||
*
|
||||
* @dataProvider provideTypeToVerifyUsingTestType
|
||||
*/
|
||||
public function testIsCorrectTypeUsingTestType(?string $toVerifyType, bool $isCorrect): void
|
||||
{
|
||||
self::assertEquals($isCorrect, TestType::isCorrectType($toVerifyType));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,107 +88,108 @@ class BaseTypeTest extends BaseTestCase
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideTypeWithConcreteType()
|
||||
public function provideTypeToVerifyUsingTestEmptyType(): ?Generator
|
||||
{
|
||||
yield[
|
||||
new TestEmptyType(),
|
||||
null,
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
new TestEmptyType(),
|
||||
false,
|
||||
'null',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
new TestEmptyType(),
|
||||
true,
|
||||
'false',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'true',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
new TestEmptyType(),
|
||||
'',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
new TestEmptyType(),
|
||||
0,
|
||||
'0',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
new TestEmptyType(),
|
||||
1,
|
||||
'1',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
new TestEmptyType(),
|
||||
'lorem',
|
||||
false,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides type of something for testing the isCorrectType() method
|
||||
*
|
||||
* @return Generator
|
||||
*/
|
||||
public function provideTypeToVerifyUsingTestType(): ?Generator
|
||||
{
|
||||
yield[
|
||||
new TestType(),
|
||||
null,
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
new TestType(),
|
||||
false,
|
||||
'null',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
new TestType(),
|
||||
true,
|
||||
'false',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'true',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
new TestType(),
|
||||
'',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
new TestType(),
|
||||
0,
|
||||
'0',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
new TestType(),
|
||||
1,
|
||||
'1',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
new TestType(),
|
||||
'lorem',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
new TestType(),
|
||||
'test',
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
new TestType(),
|
||||
TestType::TEST_1,
|
||||
'test_1',
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
new TestType(),
|
||||
TestType::TEST_2,
|
||||
'test_2',
|
||||
true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -30,52 +30,52 @@ class DatePartTypeTest extends BaseTypeTestCase
|
||||
public function provideTypeToVerify(): Generator
|
||||
{
|
||||
yield[
|
||||
'',
|
||||
DatePartType::isCorrectType(''),
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
null,
|
||||
DatePartType::isCorrectType(null),
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'0',
|
||||
DatePartType::isCorrectType('0'),
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'1',
|
||||
DatePartType::isCorrectType('1'),
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'day',
|
||||
DatePartType::isCorrectType('day'),
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'hour',
|
||||
DatePartType::isCorrectType('hour'),
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'minute',
|
||||
DatePartType::isCorrectType('minute'),
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'month',
|
||||
DatePartType::isCorrectType('month'),
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'second',
|
||||
DatePartType::isCorrectType('second'),
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'year',
|
||||
DatePartType::isCorrectType('year'),
|
||||
true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -219,27 +219,27 @@ class DatePeriodTest extends BaseTypeTestCase
|
||||
public function provideTypeToVerify(): Generator
|
||||
{
|
||||
yield[
|
||||
'',
|
||||
DatePeriod::isCorrectType(''),
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'-1',
|
||||
DatePeriod::isCorrectType('-1'),
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'4',
|
||||
DatePeriod::isCorrectType('4'),
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'3',
|
||||
DatePeriod::isCorrectType('3'),
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'8',
|
||||
DatePeriod::isCorrectType('8'),
|
||||
true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -30,32 +30,32 @@ class OopVisibilityTypeTest extends BaseTypeTestCase
|
||||
public function provideTypeToVerify(): Generator
|
||||
{
|
||||
yield[
|
||||
'',
|
||||
OopVisibilityType::isCorrectType(''),
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
null,
|
||||
OopVisibilityType::isCorrectType(null),
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'-1',
|
||||
OopVisibilityType::isCorrectType('-1'),
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
'1',
|
||||
OopVisibilityType::isCorrectType('1'),
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'2',
|
||||
OopVisibilityType::isCorrectType('2'),
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
'3',
|
||||
OopVisibilityType::isCorrectType('3'),
|
||||
true,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -649,13 +649,9 @@ class DateTest extends BaseTestCase
|
||||
self::assertTrue($randomDate >= $intervalMinDate && $randomDate <= $intervalMaxDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $period Empty value, e.g. ""
|
||||
* @dataProvider provideEmptyScalarValue
|
||||
*/
|
||||
public function testGetDatesForPeriodUsingEmptyPeriod($period): void
|
||||
public function testGetDatesForPeriodUsingEmptyString(): void
|
||||
{
|
||||
self::assertNull(Date::getDatesForPeriod($period));
|
||||
self::assertNull(Date::getDatesForPeriod(''));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user