BaseType::isCorrectType() method > make static

This commit is contained in:
Meritoo
2019-05-05 23:05:42 +02:00
parent dd5ac0f7e6
commit a6b2704c66
10 changed files with 86 additions and 79 deletions

View File

@@ -187,7 +187,7 @@ trait BaseTestCaseTrait
int $requiredArgumentsCount = 0
): void {
// Type of visibility is not correct?
if (!(new OopVisibilityType())->isCorrectType($visibilityType)) {
if (!OopVisibilityType::isCorrectType($visibilityType)) {
throw UnknownOopVisibilityTypeException::createException($visibilityType);
}

View File

@@ -33,14 +33,14 @@ trait BaseTypeTestCaseTrait
/**
* Verifies whether given type is correct or not
*
* @param null|string $type Type to verify
* @param bool $expected Information if given type is correct or not
* @param bool $isCorrect Information if processed type is correct
* @param bool $expected Expected information if processed type is correct
*
* @dataProvider provideTypeToVerify
*/
public function testIfGivenTypeIsCorrect(?string $type, bool $expected): void
public function testIfGivenTypeIsCorrect(bool $isCorrect, bool $expected): void
{
static::assertEquals($expected, $this->getTestedTypeInstance()->isCorrectType($type));
static::assertEquals($expected, $isCorrect);
}
/**

View File

@@ -26,6 +26,17 @@ abstract class BaseType
*/
private $all;
/**
* Returns information if given type is correct
*
* @param null|string $type The type to check
* @return bool
*/
public static function isCorrectType(?string $type): bool
{
return in_array($type, (new static())->getAll(), true);
}
/**
* Returns all types
*
@@ -39,15 +50,4 @@ abstract class BaseType
return $this->all;
}
/**
* Returns information if given type is correct
*
* @param null|string $type The type to check
* @return bool
*/
public function isCorrectType(?string $type): bool
{
return in_array($type, $this->getAll(), true);
}
}

View File

@@ -76,7 +76,7 @@ class Date
* Type of period is incorrect?
* Nothing to do
*/
if (!(new DatePeriod())->isCorrectType($period)) {
if (!DatePeriod::isCorrectType($period)) {
return null;
}

View File

@@ -94,7 +94,7 @@ class TestService
*/
public function getTranslatedType($type)
{
if ((new TestType())->isCorrectType($type)) {
if (TestType::isCorrectType($type)) {
return ucfirst(str_replace('_', ' ', $type));
}

View File

@@ -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,
];
}

View File

@@ -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,
];
}

View File

@@ -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,
];
}

View File

@@ -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,
];
}

View File

@@ -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(''));
}
/**