diff --git a/CHANGELOG.md b/CHANGELOG.md index b27e33d..982b928 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,26 @@ Common and useful classes, methods, exceptions etc. +# 1.3.2 + +1. All the `*Type` classes, that extend `Meritoo\Common\Type\Base\BaseType` class, have been replaced by enumerations + + | Before | After | + |-----------------------------------------|----------------------------------------| + | `Meritoo\Common\Type\DatePartType` | `Meritoo\Common\Enums\Date\DatePart` | + | `Meritoo\Common\Type\DatePeriod` | `Meritoo\Common\Enums\Date\DatePeriod` | + | `Meritoo\Common\Type\OopVisibilityType` | `Meritoo\Common\Enums\OopVisibility` | + +2. Other than that: + +- The `Meritoo\Common\Type\DatePartType` class has been moved to `Meritoo\Common\ValueObject\DatePeriod` +- Exceptions that extend `Meritoo\Common\Exception\Base\UnknownTypeException` has been removed as not needed anymore +- The following classes have been removed as not needed anymore: + - `Meritoo\Common\Exception\Base\UnknownTypeException` + - `Meritoo\Common\Test\Base\BaseTypeTestCase` + - `Meritoo\Common\Traits\Test\Base\BaseTypeTestCaseTrait` + - `Meritoo\Common\Type\Base\BaseType` + # 1.3.1 1. Arguments passed to the `Meritoo\Common\Utilities\Miscellaneous::concatenatePaths()` should be `string`s. The method diff --git a/VERSION b/VERSION index 3a3cd8c..1892b92 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.3.1 +1.3.2 diff --git a/docs/Exceptions.md b/docs/Exceptions.md index ccbb022..5867cb7 100644 --- a/docs/Exceptions.md +++ b/docs/Exceptions.md @@ -11,48 +11,10 @@ used to create instance of the exception. Example: ```php use Meritoo\Common\Exception\Bundle\IncorrectBundleNameException; -throw IncorrectBundleNameException::create('RisusIpsum'); -``` - -### Base exception for unknown type of something - -##### Short description - -It's a `Meritoo\Common\Exception\Base\UnknownTypeException` class. Related to `Meritoo\Common\Type\Base\BaseType` class -that represents type of something, e.g. type of button, order. - -##### Usage - -You can extend `Meritoo\Common\Exception\Base\UnknownTypeException` class and create your own static method, -e.g. `createException()`, which will be used create instance of the exception. Inside the `createException()` method you -can call `parent::create()` method. -##### Example +// ... -```php - - * @copyright Meritoo - */ -abstract class UnknownTypeException extends Exception -{ - /** - * Creates exception - * - * @param mixed $unknownType The unknown type of something (value of constant) - * @param BaseType $typeInstance An instance of class that contains type of the something - * @param string $typeName Name of the something - * @return UnknownTypeException - */ - protected static function createMessage($unknownType, BaseType $typeInstance, string $typeName): string - { - $template = 'The \'%s\' type of %s is unknown. Probably doesn\'t exist or there is a typo. You should use one' - .' of these types: %s.'; - - $allTypes = $typeInstance->getAll(); - $types = Arrays::values2string($allTypes, '', ', ') ?? '[types not found]'; - - return sprintf($template, $unknownType, $typeName, $types); - } -} diff --git a/src/Exception/Date/InvalidDatePartException.php b/src/Exception/Date/InvalidDatePartException.php new file mode 100644 index 0000000..2811e96 --- /dev/null +++ b/src/Exception/Date/InvalidDatePartException.php @@ -0,0 +1,27 @@ +value, + $value, + ); + + parent::__construct($message); + } +} diff --git a/src/Exception/Reflection/TooManyChildClassesException.php b/src/Exception/Reflection/TooManyChildClassesException.php index 33074c2..0f56eab 100644 --- a/src/Exception/Reflection/TooManyChildClassesException.php +++ b/src/Exception/Reflection/TooManyChildClassesException.php @@ -22,15 +22,15 @@ class TooManyChildClassesException extends Exception /** * Creates exception * - * @param array|object|string $parentClass Class that has more than one child class, but it shouldn't. An array - * of objects, strings, object or string. - * @param array $childClasses Child classes + * @param object|string $parentClass Class that has more than one child class, but it shouldn't + * @param array $childClasses Child classes + * * @return TooManyChildClassesException */ - public static function create($parentClass, array $childClasses): TooManyChildClassesException + public static function create(object|string $parentClass, array $childClasses): TooManyChildClassesException { - $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?"; + $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?"; $parentClassName = Reflection::getClassName($parentClass) ?? '[unknown class]'; $message = sprintf($template, $parentClassName, implode("\n- ", $childClasses), $parentClassName); diff --git a/src/Exception/Type/UnknownDatePartTypeException.php b/src/Exception/Type/UnknownDatePartTypeException.php deleted file mode 100644 index 363f317..0000000 --- a/src/Exception/Type/UnknownDatePartTypeException.php +++ /dev/null @@ -1,39 +0,0 @@ - - * @copyright Meritoo - */ -class UnknownDatePartTypeException extends UnknownTypeException -{ - /** - * Creates exception - * - * @param string $unknownDatePart Unknown type of date part - * @param string $value Incorrect value - * @return UnknownDatePartTypeException - */ - public static function createException(string $unknownDatePart, string $value): UnknownDatePartTypeException - { - $message = parent::createMessage( - $unknownDatePart, - new DatePartType(), - sprintf('date part (with value %s)', $value), - ); - - return new self($message); - } -} diff --git a/src/Exception/Type/UnknownOopVisibilityTypeException.php b/src/Exception/Type/UnknownOopVisibilityTypeException.php deleted file mode 100644 index e998ef0..0000000 --- a/src/Exception/Type/UnknownOopVisibilityTypeException.php +++ /dev/null @@ -1,34 +0,0 @@ - - * @copyright Meritoo - */ -class UnknownOopVisibilityTypeException extends UnknownTypeException -{ - /** - * Creates exception - * - * @param string $unknownType Unknown visibility of a property, a method or (as of PHP 7.1.0) a constant - * @return UnknownOopVisibilityTypeException - */ - public static function createException(string $unknownType): UnknownOopVisibilityTypeException - { - $message = parent::createMessage($unknownType, new OopVisibilityType(), 'OOP-related visibility'); - - return new self($message); - } -} diff --git a/src/Test/Base/BaseTypeTestCase.php b/src/Test/Base/BaseTypeTestCase.php deleted file mode 100644 index caba26c..0000000 --- a/src/Test/Base/BaseTypeTestCase.php +++ /dev/null @@ -1,22 +0,0 @@ - - * @copyright Meritoo - */ -abstract class BaseTypeTestCase extends BaseTestCase -{ - use BaseTypeTestCaseTrait; -} diff --git a/src/Traits/Test/Base/BaseTestCaseTrait.php b/src/Traits/Test/Base/BaseTestCaseTrait.php index a46f143..8e2d207 100644 --- a/src/Traits/Test/Base/BaseTestCaseTrait.php +++ b/src/Traits/Test/Base/BaseTestCaseTrait.php @@ -12,9 +12,8 @@ use DateTime; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Exception\Reflection\ClassWithoutConstructorException; -use Meritoo\Common\Exception\Type\UnknownOopVisibilityTypeException; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\Common\Utilities\Miscellaneous; use ReflectionClass; use ReflectionMethod; @@ -137,17 +136,17 @@ public function provideNotExistingFilePath(): ?Generator /** * Verifies visibility and arguments of class constructor * - * @param string $className Fully-qualified name of class that contains constructor to verify - * @param string $visibilityType Expected visibility of verified method. One of OopVisibilityType class - * constants. - * @param int $argumentsCount (optional) Expected count/amount of arguments of the verified method - * @param int $requiredArgumentsCount (optional) Expected count/amount of required arguments of the verified - * method + * @param string $className Fully-qualified name of class that contains constructor to verify + * @param OopVisibility $visibilityType Expected visibility of verified method + * @param int $argumentsCount (optional) Expected count/amount of arguments of the verified method + * @param int $requiredArgumentsCount (optional) Expected count/amount of required arguments of the verified method + * * @throws ClassWithoutConstructorException + * @throws \ReflectionException */ protected static function assertConstructorVisibilityAndArguments( string $className, - string $visibilityType, + OopVisibility $visibilityType, int $argumentsCount = 0, int $requiredArgumentsCount = 0 ): void { @@ -196,29 +195,21 @@ protected static function assertMethodArgumentsCount( /** * Verifies visibility of method * - * @param ReflectionMethod $method Name of method or just the method to verify - * @param string $visibilityType Expected visibility of verified method. One of OopVisibilityType - * class constants. - * @throws UnknownOopVisibilityTypeException - * @throws RuntimeException + * @param ReflectionMethod $method Name of method or just the method to verify + * @param OopVisibility $visibilityType Expected visibility of verified method */ - protected static function assertMethodVisibility(ReflectionMethod $method, string $visibilityType): void + protected static function assertMethodVisibility(ReflectionMethod $method, OopVisibility $visibilityType): void { - // Type of visibility is not correct? - if (!(new OopVisibilityType())->isCorrectType($visibilityType)) { - throw UnknownOopVisibilityTypeException::createException($visibilityType); - } - switch ($visibilityType) { - case OopVisibilityType::IS_PUBLIC: + case OopVisibility::Public: static::assertTrue($method->isPublic()); break; - case OopVisibilityType::IS_PROTECTED: + case OopVisibility::Protected: static::assertTrue($method->isProtected()); break; - case OopVisibilityType::IS_PRIVATE: + case OopVisibility::Private: static::assertTrue($method->isPrivate()); break; diff --git a/src/Traits/Test/Base/BaseTypeTestCaseTrait.php b/src/Traits/Test/Base/BaseTypeTestCaseTrait.php deleted file mode 100644 index 7c1d85f..0000000 --- a/src/Traits/Test/Base/BaseTypeTestCaseTrait.php +++ /dev/null @@ -1,68 +0,0 @@ - - * @copyright Meritoo - */ -trait BaseTypeTestCaseTrait -{ - /** - * Provides type to verify and information if it's correct - * - * @return Generator - */ - abstract public function provideTypeToVerify(): Generator; - - /** - * Verifies availability of all types - */ - public function testAvailabilityOfAllTypes(): void - { - $available = $this->getTestedTypeInstance()->getAll(); - $all = $this->getAllExpectedTypes(); - - static::assertEquals($all, $available); - } - - /** - * Verifies whether 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(bool $isCorrect, bool $expected): void - { - static::assertEquals($expected, $isCorrect); - } - - /** - * Returns all expected types of the tested type - * - * @return array - */ - abstract protected function getAllExpectedTypes(): array; - - /** - * Returns instance of the tested type - * - * @return BaseType - */ - abstract protected function getTestedTypeInstance(): BaseType; -} diff --git a/src/Type/Base/BaseType.php b/src/Type/Base/BaseType.php deleted file mode 100644 index f610a35..0000000 --- a/src/Type/Base/BaseType.php +++ /dev/null @@ -1,37 +0,0 @@ - - * @copyright Meritoo - */ -abstract class BaseType -{ - private ?array $all = null; - - public function getAll(): ?array - { - if (null === $this->all) { - $this->all = Reflection::getConstants($this); - } - - return $this->all; - } - - public function isCorrectType(null|string|int $type): bool - { - return in_array($type, $this->getAll(), true); - } -} diff --git a/src/Type/DatePartType.php b/src/Type/DatePartType.php deleted file mode 100644 index abaecdc..0000000 --- a/src/Type/DatePartType.php +++ /dev/null @@ -1,27 +0,0 @@ - - * @copyright Meritoo - */ -class DatePartType extends BaseType -{ - public const DAY = 'day'; - public const HOUR = 'hour'; - public const MINUTE = 'minute'; - public const MONTH = 'month'; - public const SECOND = 'second'; - public const YEAR = 'year'; -} diff --git a/src/Type/OopVisibilityType.php b/src/Type/OopVisibilityType.php deleted file mode 100644 index 4738f86..0000000 --- a/src/Type/OopVisibilityType.php +++ /dev/null @@ -1,26 +0,0 @@ - - * @copyright Meritoo - * - * @see http://php.net/manual/en/language.oop5.visibility.php - */ -class OopVisibilityType extends BaseType -{ - public const IS_PRIVATE = '3'; - public const IS_PROTECTED = '2'; - public const IS_PUBLIC = '1'; -} diff --git a/src/Utilities/Date.php b/src/Utilities/Date.php index e4abedf..fbafc27 100644 --- a/src/Utilities/Date.php +++ b/src/Utilities/Date.php @@ -11,9 +11,10 @@ use DateInterval; use DateTime; use Exception; -use Meritoo\Common\Exception\Type\UnknownDatePartTypeException; -use Meritoo\Common\Type\DatePartType; -use Meritoo\Common\Type\DatePeriod; +use Meritoo\Common\Enums\Date\DatePart; +use Meritoo\Common\Enums\Date\DatePeriod as DatePeriodEnum; +use Meritoo\Common\Exception\Date\InvalidDatePartException; +use Meritoo\Common\ValueObject\DatePeriod; /** * Useful date methods @@ -116,7 +117,7 @@ public static function generateRandomTime(string $format = self::TIME_FORMAT): ? * Returns current day of week * * @return int - * @throws UnknownDatePartTypeException + * @throws InvalidDatePartException */ public static function getCurrentDayOfWeek(): int { @@ -444,25 +445,19 @@ public static function getDatesCollection( /** * Returns date's period (that contains start and end date) for given period * - * @param string $period The period, type of period. One of DatePeriod class constants, e.g. DatePeriod::LAST_WEEK. + * @param DatePeriodEnum $period The date period + * * @return null|DatePeriod - * @throws Exception + * @throws \DateInvalidOperationException + * @throws \DateMalformedStringException */ - public static function getDatesForPeriod(string $period): ?DatePeriod + public static function getDatesForPeriod(DatePeriodEnum $period): ?DatePeriod { - /* - * Type of period is incorrect? - * Nothing to do - */ - if (!(new DatePeriod())->isCorrectType($period)) { - return null; - } - $dateStart = null; $dateEnd = null; switch ($period) { - case DatePeriod::LAST_WEEK: + case DatePeriodEnum::LastWeek: $thisWeekStart = new DateTime('this week'); $dateStart = clone $thisWeekStart; @@ -472,14 +467,14 @@ public static function getDatesForPeriod(string $period): ?DatePeriod $dateEnd->sub(new DateInterval('P1D')); break; - case DatePeriod::THIS_WEEK: + case DatePeriodEnum::ThisWeek: $dateStart = new DateTime('this week'); $dateEnd = clone $dateStart; $dateEnd->add(new DateInterval('P6D')); break; - case DatePeriod::NEXT_WEEK: + case DatePeriodEnum::NextWeek: $dateStart = new DateTime('this week'); $dateStart->add(new DateInterval('P7D')); @@ -487,14 +482,14 @@ public static function getDatesForPeriod(string $period): ?DatePeriod $dateEnd->add(new DateInterval('P6D')); break; - case DatePeriod::LAST_MONTH: + case DatePeriodEnum::LastMonth: $dateStart = new DateTime('first day of last month'); $dateEnd = new DateTime('last day of last month'); break; - case DatePeriod::THIS_MONTH: - $lastMonth = self::getDatesForPeriod(DatePeriod::LAST_MONTH); - $nextMonth = self::getDatesForPeriod(DatePeriod::NEXT_MONTH); + case DatePeriodEnum::ThisMonth: + $lastMonth = self::getDatesForPeriod(DatePeriodEnum::LastMonth); + $nextMonth = self::getDatesForPeriod(DatePeriodEnum::NextMonth); if (null !== $lastMonth) { $dateStart = $lastMonth->getEndDate(); @@ -513,26 +508,26 @@ public static function getDatesForPeriod(string $period): ?DatePeriod } break; - case DatePeriod::NEXT_MONTH: + case DatePeriodEnum::NextMonth: $dateStart = new DateTime('first day of next month'); $dateEnd = new DateTime('last day of next month'); break; - case DatePeriod::LAST_YEAR: - case DatePeriod::THIS_YEAR: - case DatePeriod::NEXT_YEAR: + case DatePeriodEnum::LastYear: + case DatePeriodEnum::ThisYear: + case DatePeriodEnum::NextYear: $dateStart = new DateTime(); $dateEnd = new DateTime(); $yearPeriod = [ - DatePeriod::LAST_YEAR, - DatePeriod::NEXT_YEAR, + DatePeriodEnum::LastYear, + DatePeriodEnum::NextYear, ]; if (in_array($period, $yearPeriod, true)) { $yearDifference = 1; - if (DatePeriod::LAST_YEAR === $period) { + if (DatePeriodEnum::LastYear === $period) { $yearDifference *= -1; } @@ -571,13 +566,13 @@ public static function getDatesForPeriod(string $period): ?DatePeriod * @param int $day The day value * * @return int - * @throws UnknownDatePartTypeException + * @throws InvalidDatePartException */ public static function getDayOfWeek(int $year, int $month, int $day): int { - static::validateYear($year); - static::validateMonth($month); - static::validateDay($day); + self::validateYear($year); + self::validateMonth($month); + self::validateDay($day); if ($month < 3) { $count = 0; @@ -706,47 +701,47 @@ public static function isValidDateFormat(string $format): bool * Verifies/validates given day * * @param int $day Day to verify/validate - * @throws UnknownDatePartTypeException + * + * @throws InvalidDatePartException */ private static function validateDay(int $day): void { - // Oops, given day is incorrect if ($day >= 1 && $day <= 31) { return; } - throw UnknownDatePartTypeException::createException(DatePartType::DAY, $day); + throw new InvalidDatePartException(DatePart::Day, $day); } /** * Verifies/validates given month * * @param int $month Month to verify/validate - * @throws UnknownDatePartTypeException + * + * @throws InvalidDatePartException */ private static function validateMonth(int $month): void { - // Oops, given month is incorrect if ($month >= 1 && $month <= 12) { return; } - throw UnknownDatePartTypeException::createException(DatePartType::MONTH, $month); + throw new InvalidDatePartException(DatePart::Month, $month); } /** * Verifies/validates given year * * @param int $year Year to verify/validate - * @throws UnknownDatePartTypeException + * + * @throws InvalidDatePartException */ private static function validateYear(int $year): void { - // Oops, given year is incorrect if ($year >= 0) { return; } - throw UnknownDatePartTypeException::createException(DatePartType::YEAR, $year); + throw new InvalidDatePartException(DatePart::Year, $year); } } diff --git a/src/Type/DatePeriod.php b/src/ValueObject/DatePeriod.php similarity index 63% rename from src/Type/DatePeriod.php rename to src/ValueObject/DatePeriod.php index bf5a004..d285d02 100644 --- a/src/Type/DatePeriod.php +++ b/src/ValueObject/DatePeriod.php @@ -6,10 +6,11 @@ * file that was distributed with this source code. */ -namespace Meritoo\Common\Type; +declare(strict_types=1); + +namespace Meritoo\Common\ValueObject; use DateTime; -use Meritoo\Common\Type\Base\BaseType; use Meritoo\Common\Utilities\Date; /** @@ -19,24 +20,10 @@ * @author Meritoo * @copyright Meritoo */ -class DatePeriod extends BaseType +class DatePeriod { - public const LAST_MONTH = '4'; - public const LAST_WEEK = '1'; - public const LAST_YEAR = '7'; - public const NEXT_MONTH = '6'; - public const NEXT_WEEK = '3'; - public const NEXT_YEAR = '9'; - public const THIS_MONTH = '5'; - public const THIS_WEEK = '2'; - public const THIS_YEAR = '8'; - private ?DateTime $startDate; - private ?DateTime $endDate; - - public function __construct(?DateTime $startDate = null, ?DateTime $endDate = null) + public function __construct(private ?DateTime $startDate = null, private ?DateTime $endDate = null) { - $this->startDate = $startDate; - $this->endDate = $endDate; } public function getEndDate(): ?DateTime @@ -51,13 +38,25 @@ public function setEndDate(?DateTime $endDate = null): self return $this; } + public function getStartDate(): ?DateTime + { + return $this->startDate; + } + + public function setStartDate(?DateTime $startDate = null): self + { + $this->startDate = $startDate; + + return $this; + } + public function getFormattedDate(string $format, bool $startDate = true): string { - $date = $this->getEndDate(); + $date = $this->endDate; // Start date should be formatted? if ($startDate) { - $date = $this->getStartDate(); + $date = $this->startDate; } // Unknown date or format is invalid? @@ -68,16 +67,4 @@ public function getFormattedDate(string $format, bool $startDate = true): string return $date->format($format); } - - public function getStartDate(): ?DateTime - { - return $this->startDate; - } - - public function setStartDate(?DateTime $startDate = null): self - { - $this->startDate = $startDate; - - return $this; - } } diff --git a/tests/Collection/BaseCollectionTest.php b/tests/Collection/BaseCollectionTest.php index f1dc8d2..26fb344 100644 --- a/tests/Collection/BaseCollectionTest.php +++ b/tests/Collection/BaseCollectionTest.php @@ -15,8 +15,8 @@ use Meritoo\Common\Collection\DateTimeCollection; use Meritoo\Common\Collection\StringCollection; use Meritoo\Common\Contract\Collection\CollectionInterface; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\Test\Common\Collection\BaseCollection\FirstNamesCollection; use Meritoo\Test\Common\Collection\BaseCollection\User; use ReflectionClass; @@ -511,7 +511,7 @@ public function testExistsVisibilityAndArguments(): void $reflectionClass = new ReflectionClass(BaseCollection::class); $method = $reflectionClass->getMethod('exists'); - static::assertMethodVisibility($method, OopVisibilityType::IS_PRIVATE); + static::assertMethodVisibility($method, OopVisibility::Private); static::assertMethodArgumentsCount($method, 1, 1); } diff --git a/tests/Collection/DateTimeCollectionTest.php b/tests/Collection/DateTimeCollectionTest.php index e7767d9..db4984c 100644 --- a/tests/Collection/DateTimeCollectionTest.php +++ b/tests/Collection/DateTimeCollectionTest.php @@ -13,8 +13,8 @@ use DateTime; use Generator; use Meritoo\Common\Collection\DateTimeCollection; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; /** * Test case of the collection of DateTime instances @@ -69,7 +69,7 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( DateTimeCollection::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, 1 ); } diff --git a/tests/Collection/IntegerCollectionTest.php b/tests/Collection/IntegerCollectionTest.php index 8915b1b..2fb1b3b 100644 --- a/tests/Collection/IntegerCollectionTest.php +++ b/tests/Collection/IntegerCollectionTest.php @@ -12,8 +12,8 @@ use Generator; use Meritoo\Common\Collection\IntegerCollection; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; /** * Test case of the collection of integers @@ -69,7 +69,7 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( IntegerCollection::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, 1 ); } diff --git a/tests/Collection/StringCollectionTest.php b/tests/Collection/StringCollectionTest.php index 2f53f40..9bcd925 100644 --- a/tests/Collection/StringCollectionTest.php +++ b/tests/Collection/StringCollectionTest.php @@ -12,8 +12,8 @@ use Generator; use Meritoo\Common\Collection\StringCollection; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; /** * Test case of the collection of strings @@ -70,7 +70,7 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( StringCollection::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, 1 ); } diff --git a/tests/Collection/TemplatesTest.php b/tests/Collection/TemplatesTest.php index 7f48ebd..43d2b97 100644 --- a/tests/Collection/TemplatesTest.php +++ b/tests/Collection/TemplatesTest.php @@ -6,13 +6,15 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\Collection; use Generator; use Meritoo\Common\Collection\Templates; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Exception\ValueObject\Template\TemplateNotFoundException; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\Common\ValueObject\Template; /** @@ -126,7 +128,7 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( Templates::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, 1 ); } diff --git a/tests/Exception/Base/UnknownTypeExceptionTest.php b/tests/Exception/Base/UnknownTypeExceptionTest.php deleted file mode 100644 index 9f05518..0000000 --- a/tests/Exception/Base/UnknownTypeExceptionTest.php +++ /dev/null @@ -1,105 +0,0 @@ - - * @copyright Meritoo - * - * @internal - * @covers \Meritoo\Common\Exception\Base\UnknownTypeException - */ -class UnknownTypeExceptionTest extends BaseTestCase -{ - public function testConstructorVisibilityAndArguments() - { - static::assertConstructorVisibilityAndArguments(UnknownTypeException::class, OopVisibilityType::IS_PUBLIC, 3); - } - - public function testTheException() - { - $this->expectException(UnknownTestTypeException::class); - self::assertEmpty((new TestService())->getTranslatedType('test_3')); - } - - public function testWithoutException() - { - self::assertEquals('Test 2', (new TestService())->getTranslatedType('test_2')); - } -} - -/** - * Type of something (for testing purposes) - * - * @author Meritoo - * @copyright Meritoo - */ -class TestType extends BaseType -{ - public const TEST_1 = 'test_1'; - - public const TEST_2 = 'test_2'; -} - -/** - * An exception used while type of something is unknown (for testing purposes) - * - * @author Meritoo - * @copyright Meritoo - * - * @internal - * @covers \Meritoo\Common\Exception\Base\UnknownTypeException - */ -class UnknownTestTypeException extends UnknownTypeException -{ - /** - * Creates exception - * - * @param string $unknownType The unknown type of something (for testing purposes) - * @return UnknownTestTypeException - */ - public static function createException(string $unknownType): UnknownTestTypeException - { - $message = parent::createMessage($unknownType, new TestType(), 'type of something used for testing'); - - return new self($message); - } -} - -/** - * Service used together with type of something (for testing purposes) - * - * @author Meritoo - * @copyright Meritoo - */ -class TestService -{ - /** - * Returns translated type (for testing purposes) - * - * @param string $type Type of something (for testing purposes) - * @return string - * @throws UnknownTestTypeException - */ - public function getTranslatedType(string $type): string - { - if ((new TestType())->isCorrectType($type)) { - return ucfirst(str_replace('_', ' ', $type)); - } - - throw UnknownTestTypeException::createException($type); - } -} diff --git a/tests/Exception/Bundle/IncorrectBundleNameExceptionTest.php b/tests/Exception/Bundle/IncorrectBundleNameExceptionTest.php index d862480..431afda 100644 --- a/tests/Exception/Bundle/IncorrectBundleNameExceptionTest.php +++ b/tests/Exception/Bundle/IncorrectBundleNameExceptionTest.php @@ -6,12 +6,14 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\Exception\Bundle; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Exception\Bundle\IncorrectBundleNameException; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; /** * Test case of an exception used while name of bundle is incorrect @@ -52,7 +54,7 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( IncorrectBundleNameException::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, 3 ); } diff --git a/tests/Exception/Date/UnknownDatePartTypeExceptionTest.php b/tests/Exception/Date/UnknownDatePartTypeExceptionTest.php deleted file mode 100644 index 4bc5b7b..0000000 --- a/tests/Exception/Date/UnknownDatePartTypeExceptionTest.php +++ /dev/null @@ -1,74 +0,0 @@ - - * @copyright Meritoo - * - * @internal - * @covers \Meritoo\Common\Exception\Type\UnknownDatePartTypeException - */ -class UnknownDatePartTypeExceptionTest extends BaseTestCase -{ - /** - * Provides type of date part, incorrect value and expected exception's message - * - * @return Generator - */ - public function provideDatePartAndValue() - { - $template = 'The \'%s\' type of date part (with value %s) is unknown. Probably doesn\'t exist or there is a' - .' typo. You should use one of these types: day, hour, minute, month, second, year.'; - - yield [ - DatePartType::DAY, - '44', - sprintf($template, DatePartType::DAY, '44'), - ]; - - yield [ - DatePartType::MONTH, - '22', - sprintf($template, DatePartType::MONTH, '22'), - ]; - - yield [ - DatePartType::MINUTE, - '77', - sprintf($template, DatePartType::MINUTE, '77'), - ]; - } - - public function testConstructorVisibilityAndArguments() - { - static::assertConstructorVisibilityAndArguments(UnknownDatePartTypeException::class, OopVisibilityType::IS_PUBLIC, 3); - } - - /** - * @param string $unknownDatePart Type of date part, e.g. "year". One of DatePartType class constants. - * @param string $value Incorrect value - * @param string $expectedMessage Expected exception's message - * - * @dataProvider provideDatePartAndValue - */ - public function testMessage($unknownDatePart, $value, $expectedMessage) - { - $exception = UnknownDatePartTypeException::createException($unknownDatePart, $value); - static::assertSame($expectedMessage, $exception->getMessage()); - } -} diff --git a/tests/Exception/File/EmptyFileExceptionTest.php b/tests/Exception/File/EmptyFileExceptionTest.php index 0825b32..d1a49c3 100644 --- a/tests/Exception/File/EmptyFileExceptionTest.php +++ b/tests/Exception/File/EmptyFileExceptionTest.php @@ -6,12 +6,14 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\Exception\File; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Exception\File\EmptyFileException; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; /** * Test case of an exception used while file with given path is empty (has no content) @@ -46,7 +48,7 @@ public function providePathOfFile() public function testConstructorVisibilityAndArguments() { - static::assertConstructorVisibilityAndArguments(EmptyFileException::class, OopVisibilityType::IS_PUBLIC, 3); + static::assertConstructorVisibilityAndArguments(EmptyFileException::class, OopVisibility::Public, 3); } /** diff --git a/tests/Exception/File/EmptyFilePathExceptionTest.php b/tests/Exception/File/EmptyFilePathExceptionTest.php index 560351c..301d93d 100644 --- a/tests/Exception/File/EmptyFilePathExceptionTest.php +++ b/tests/Exception/File/EmptyFilePathExceptionTest.php @@ -6,11 +6,13 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\Exception\File; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Exception\File\EmptyFilePathException; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; /** * Test case of an exception used while path of given file is empty @@ -31,6 +33,6 @@ public function testConstructorMessage() public function testConstructorVisibilityAndArguments() { - static::assertConstructorVisibilityAndArguments(EmptyFilePathException::class, OopVisibilityType::IS_PUBLIC, 3); + static::assertConstructorVisibilityAndArguments(EmptyFilePathException::class, OopVisibility::Public, 3); } } diff --git a/tests/Exception/File/NotExistingFileExceptionTest.php b/tests/Exception/File/NotExistingFileExceptionTest.php index b8c6cb6..48198ac 100644 --- a/tests/Exception/File/NotExistingFileExceptionTest.php +++ b/tests/Exception/File/NotExistingFileExceptionTest.php @@ -6,12 +6,14 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\Exception\File; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Exception\File\NotExistingFileException; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; /** * Test case of an exception used while file with given path does not exist @@ -58,6 +60,6 @@ public function testConstructorMessage($notExistingFilePath, $expectedMessage) public function testConstructorVisibilityAndArguments() { - static::assertConstructorVisibilityAndArguments(NotExistingFileException::class, OopVisibilityType::IS_PUBLIC, 3); + static::assertConstructorVisibilityAndArguments(NotExistingFileException::class, OopVisibility::Public, 3); } } diff --git a/tests/Exception/Method/DisabledMethodExceptionTest.php b/tests/Exception/Method/DisabledMethodExceptionTest.php index 18af361..7f29521 100644 --- a/tests/Exception/Method/DisabledMethodExceptionTest.php +++ b/tests/Exception/Method/DisabledMethodExceptionTest.php @@ -6,12 +6,14 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\Exception\Method; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Exception\Method\DisabledMethodException; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; /** * Test case of an exception used while method cannot be called, because is disabled @@ -63,6 +65,6 @@ public function testConstructorMessage($disabledMethod, $alternativeMethod, $exp public function testConstructorVisibilityAndArguments() { - static::assertConstructorVisibilityAndArguments(DisabledMethodException::class, OopVisibilityType::IS_PUBLIC, 3); + static::assertConstructorVisibilityAndArguments(DisabledMethodException::class, OopVisibility::Public, 3); } } diff --git a/tests/Exception/Reflection/CannotResolveClassNameExceptionTest.php b/tests/Exception/Reflection/CannotResolveClassNameExceptionTest.php index 059b8c3..2ee7b46 100644 --- a/tests/Exception/Reflection/CannotResolveClassNameExceptionTest.php +++ b/tests/Exception/Reflection/CannotResolveClassNameExceptionTest.php @@ -6,12 +6,14 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\Exception\Reflection; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Exception\Reflection\CannotResolveClassNameException; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use stdClass; /** @@ -56,7 +58,7 @@ public function testConstructorVisibilityAndArguments(): void { static::assertConstructorVisibilityAndArguments( CannotResolveClassNameException::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, 3 ); } diff --git a/tests/Exception/Reflection/ClassWithoutConstructorExceptionTest.php b/tests/Exception/Reflection/ClassWithoutConstructorExceptionTest.php index 13e9eff..b5090d0 100644 --- a/tests/Exception/Reflection/ClassWithoutConstructorExceptionTest.php +++ b/tests/Exception/Reflection/ClassWithoutConstructorExceptionTest.php @@ -6,12 +6,14 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\Exception\Reflection; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Exception\Reflection\ClassWithoutConstructorException; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\Common\Utilities\Arrays; /** @@ -46,7 +48,7 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( ClassWithoutConstructorException::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, 3 ); } diff --git a/tests/Exception/Reflection/MissingChildClassesExceptionTest.php b/tests/Exception/Reflection/MissingChildClassesExceptionTest.php index abe4ca8..56a3dd7 100644 --- a/tests/Exception/Reflection/MissingChildClassesExceptionTest.php +++ b/tests/Exception/Reflection/MissingChildClassesExceptionTest.php @@ -6,12 +6,14 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\Exception\Reflection; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Exception\Reflection\MissingChildClassesException; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use stdClass; /** @@ -45,7 +47,7 @@ public function testConstructorVisibilityAndArguments(): void { static::assertConstructorVisibilityAndArguments( MissingChildClassesException::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, 3 ); } diff --git a/tests/Exception/Reflection/NotExistingPropertyExceptionTest.php b/tests/Exception/Reflection/NotExistingPropertyExceptionTest.php index 256a75c..e8f6bbd 100644 --- a/tests/Exception/Reflection/NotExistingPropertyExceptionTest.php +++ b/tests/Exception/Reflection/NotExistingPropertyExceptionTest.php @@ -6,12 +6,14 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\Exception\Reflection; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Exception\Reflection\NotExistingPropertyException; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use stdClass; /** @@ -62,7 +64,7 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( NotExistingPropertyException::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, 3 ); } diff --git a/tests/Exception/Reflection/TooManyChildClassesExceptionTest.php b/tests/Exception/Reflection/TooManyChildClassesExceptionTest.php index 9d0c58d..68d9e97 100644 --- a/tests/Exception/Reflection/TooManyChildClassesExceptionTest.php +++ b/tests/Exception/Reflection/TooManyChildClassesExceptionTest.php @@ -6,12 +6,15 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\Exception\Reflection; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Exception\Reflection\TooManyChildClassesException; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; +use Meritoo\Test\Common\ValueObject\AddressTest; use stdClass; /** @@ -33,19 +36,18 @@ class TooManyChildClassesExceptionTest extends BaseTestCase */ 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?"; - yield [ BaseTestCase::class, [ stdClass::class, - OopVisibilityType::class, + AddressTest::class, ], - sprintf($template, BaseTestCase::class, implode("\n- ", [ - stdClass::class, - OopVisibilityType::class, - ]), BaseTestCase::class), + "The Meritoo\Common\Test\Base\BaseTestCase class requires one child class at most who will extend her," + ." but more than one child class was found:\n" + ."- stdClass\n" + ."- Meritoo\Test\Common\ValueObject\AddressTest\n" + ."\n" + ."Why did you create more than one classes that extend Meritoo\Common\Test\Base\BaseTestCase class?", ]; yield [ @@ -53,7 +55,11 @@ public function provideParentAndChildClasses(): ?Generator [ stdClass::class, ], - sprintf($template, TooManyChildClassesException::class, implode("\n- ", [stdClass::class]), TooManyChildClassesException::class), + "The Meritoo\Common\Exception\Reflection\TooManyChildClassesException class requires one child class at most who will extend her," + ." but more than one child class was found:\n" + ."- stdClass\n" + ."\n" + ."Why did you create more than one classes that extend Meritoo\Common\Exception\Reflection\TooManyChildClassesException class?", ]; } @@ -61,20 +67,13 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( TooManyChildClassesException::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, 3 ); } - /** - * @param array|object|string $parentClass Class that has more than one child class, but it shouldn't. An array - * of objects, strings, object or string. - * @param array $childClasses Child classes - * @param string $expectedMessage Expected exception's message - * - * @dataProvider provideParentAndChildClasses - */ - public function testCreate($parentClass, array $childClasses, string $expectedMessage): void + /** @dataProvider provideParentAndChildClasses */ + public function testCreate(object|string $parentClass, array $childClasses, string $expectedMessage): void { $exception = TooManyChildClassesException::create($parentClass, $childClasses); static::assertSame($expectedMessage, $exception->getMessage()); diff --git a/tests/Exception/Regex/IncorrectColorHexLengthExceptionTest.php b/tests/Exception/Regex/IncorrectColorHexLengthExceptionTest.php index 754f8ab..de7934d 100644 --- a/tests/Exception/Regex/IncorrectColorHexLengthExceptionTest.php +++ b/tests/Exception/Regex/IncorrectColorHexLengthExceptionTest.php @@ -6,12 +6,14 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\Exception\Regex; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Exception\Regex\IncorrectColorHexLengthException; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; /** * Test case of an exception used while length of given hexadecimal value of color is incorrect @@ -58,6 +60,10 @@ public function testConstructorMessage($color, $expectedMessage) public function testConstructorVisibilityAndArguments() { - static::assertConstructorVisibilityAndArguments(IncorrectColorHexLengthException::class, OopVisibilityType::IS_PUBLIC, 3); + static::assertConstructorVisibilityAndArguments( + IncorrectColorHexLengthException::class, + OopVisibility::Public, + 3, + ); } } diff --git a/tests/Exception/Regex/InvalidColorHexValueExceptionTest.php b/tests/Exception/Regex/InvalidColorHexValueExceptionTest.php index 38b4cf0..4981e89 100644 --- a/tests/Exception/Regex/InvalidColorHexValueExceptionTest.php +++ b/tests/Exception/Regex/InvalidColorHexValueExceptionTest.php @@ -6,12 +6,14 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\Exception\Regex; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Exception\Regex\InvalidColorHexValueException; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; /** * Test case of an exception used while given hexadecimal value of color is invalid @@ -58,6 +60,10 @@ public function testConstructorMessage($color, $expectedMessage) public function testConstructorVisibilityAndArguments() { - static::assertConstructorVisibilityAndArguments(InvalidColorHexValueException::class, OopVisibilityType::IS_PUBLIC, 3); + static::assertConstructorVisibilityAndArguments( + InvalidColorHexValueException::class, + OopVisibility::Public, + 3, + ); } } diff --git a/tests/Exception/Regex/InvalidHtmlAttributesExceptionTest.php b/tests/Exception/Regex/InvalidHtmlAttributesExceptionTest.php index 799169d..3bde2a5 100644 --- a/tests/Exception/Regex/InvalidHtmlAttributesExceptionTest.php +++ b/tests/Exception/Regex/InvalidHtmlAttributesExceptionTest.php @@ -6,12 +6,14 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\Exception\Regex; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Exception\Regex\InvalidHtmlAttributesException; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; /** * Test case of an exception used while html attributes are invalid @@ -63,6 +65,10 @@ public function testConstructorMessage($htmlAttributes, $expectedMessage) public function testConstructorVisibilityAndArguments() { - static::assertConstructorVisibilityAndArguments(InvalidHtmlAttributesException::class, OopVisibilityType::IS_PUBLIC, 3); + static::assertConstructorVisibilityAndArguments( + InvalidHtmlAttributesException::class, + OopVisibility::Public, + 3, + ); } } diff --git a/tests/Exception/Regex/InvalidUrlExceptionTest.php b/tests/Exception/Regex/InvalidUrlExceptionTest.php index cee47d9..ca51f4e 100644 --- a/tests/Exception/Regex/InvalidUrlExceptionTest.php +++ b/tests/Exception/Regex/InvalidUrlExceptionTest.php @@ -6,12 +6,14 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\Exception\Regex; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Exception\Regex\InvalidUrlException; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; /** * Test case of an exception used while url is invalid @@ -58,6 +60,6 @@ public function testConstructorMessage($url, $expectedMessage) public function testConstructorVisibilityAndArguments() { - static::assertConstructorVisibilityAndArguments(InvalidUrlException::class, OopVisibilityType::IS_PUBLIC, 3); + static::assertConstructorVisibilityAndArguments(InvalidUrlException::class, OopVisibility::Public, 3); } } diff --git a/tests/Exception/Type/UnknownOopVisibilityTypeExceptionTest.php b/tests/Exception/Type/UnknownOopVisibilityTypeExceptionTest.php deleted file mode 100644 index fb71f5b..0000000 --- a/tests/Exception/Type/UnknownOopVisibilityTypeExceptionTest.php +++ /dev/null @@ -1,71 +0,0 @@ - - * @copyright Meritoo - * - * @internal - * @covers \Meritoo\Common\Exception\Type\UnknownOopVisibilityTypeException - */ -class UnknownOopVisibilityTypeExceptionTest extends BaseTestCase -{ - /** - * Provides path of the empty file and expected exception's message - * - * @return Generator - */ - public function provideUnknownType(): Generator - { - $allTypes = (new OopVisibilityType())->getAll(); - - $template = 'The \'%s\' type of OOP-related visibility is unknown. Probably doesn\'t exist or there is a typo.' - .' You should use one of these types: %s.'; - - yield [ - '', - sprintf($template, '', implode(', ', $allTypes)), - ]; - - yield [ - 123, - sprintf($template, 123, implode(', ', $allTypes)), - ]; - } - - /** - * @param string $unknownType Unknown OOP-related visibility - * @param string $expectedMessage Expected exception's message - * - * @dataProvider provideUnknownType - */ - public function testConstructorMessage($unknownType, $expectedMessage): void - { - $exception = UnknownOopVisibilityTypeException::createException($unknownType); - static::assertSame($expectedMessage, $exception->getMessage()); - } - - public function testConstructorVisibilityAndArguments(): void - { - static::assertConstructorVisibilityAndArguments( - UnknownOopVisibilityTypeException::class, - OopVisibilityType::IS_PUBLIC, - 3 - ); - } -} diff --git a/tests/Exception/ValueObject/InvalidSizeDimensionsExceptionTest.php b/tests/Exception/ValueObject/InvalidSizeDimensionsExceptionTest.php index 6487c98..6d6117d 100644 --- a/tests/Exception/ValueObject/InvalidSizeDimensionsExceptionTest.php +++ b/tests/Exception/ValueObject/InvalidSizeDimensionsExceptionTest.php @@ -6,11 +6,13 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\Exception\ValueObject; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Exception\ValueObject\InvalidSizeDimensionsException; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; /** * Test case of an exception used while dimensions of size, passed to the instance of Size class, are invalid @@ -50,7 +52,7 @@ public function testConstructorVisibilityAndArguments() { static::assertConstructorVisibilityAndArguments( InvalidSizeDimensionsException::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, 3 ); } diff --git a/tests/Exception/ValueObject/Template/InvalidContentExceptionTest.php b/tests/Exception/ValueObject/Template/InvalidContentExceptionTest.php index 6392407..df65392 100644 --- a/tests/Exception/ValueObject/Template/InvalidContentExceptionTest.php +++ b/tests/Exception/ValueObject/Template/InvalidContentExceptionTest.php @@ -6,12 +6,14 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\Exception\ValueObject\Template; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Exception\ValueObject\Template\InvalidContentException; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; /** * Test case of an exception used while content of template is invalid @@ -51,7 +53,7 @@ public function testConstructorVisibilityAndArguments(): void { static::assertConstructorVisibilityAndArguments( InvalidContentException::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, 3 ); } diff --git a/tests/Exception/ValueObject/Template/MissingPlaceholdersInValuesExceptionTest.php b/tests/Exception/ValueObject/Template/MissingPlaceholdersInValuesExceptionTest.php index 86a6602..beefceb 100644 --- a/tests/Exception/ValueObject/Template/MissingPlaceholdersInValuesExceptionTest.php +++ b/tests/Exception/ValueObject/Template/MissingPlaceholdersInValuesExceptionTest.php @@ -6,12 +6,14 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\Exception\ValueObject\Template; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Exception\ValueObject\Template\MissingPlaceholdersInValuesException; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; /** * Test case of an exception used while there are missing values required to fill all placeholders in template @@ -61,7 +63,7 @@ public function testConstructorVisibilityAndArguments(): void { static::assertConstructorVisibilityAndArguments( MissingPlaceholdersInValuesException::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, 3 ); } diff --git a/tests/Exception/ValueObject/Template/TemplateNotFoundExceptionTest.php b/tests/Exception/ValueObject/Template/TemplateNotFoundExceptionTest.php index 4616f7a..2002a6c 100644 --- a/tests/Exception/ValueObject/Template/TemplateNotFoundExceptionTest.php +++ b/tests/Exception/ValueObject/Template/TemplateNotFoundExceptionTest.php @@ -6,12 +6,14 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\Exception\ValueObject\Template; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Exception\ValueObject\Template\TemplateNotFoundException; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; /** * Test case of an exception used while template with given index was not found @@ -51,7 +53,7 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( TemplateNotFoundException::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, 3 ); } diff --git a/tests/Test/Base/BaseTestCaseTest.php b/tests/Test/Base/BaseTestCaseTest.php index b592661..d60cf7f 100644 --- a/tests/Test/Base/BaseTestCaseTest.php +++ b/tests/Test/Base/BaseTestCaseTest.php @@ -6,12 +6,14 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\Test\Base; use DateTime; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\Common\Utilities\GeneratorUtility; /** @@ -57,7 +59,7 @@ public function provideFileNameAndDirectoryPath() public function testConstructor() { - static::assertConstructorVisibilityAndArguments(BaseTestCase::class, OopVisibilityType::IS_PUBLIC, 3); + static::assertConstructorVisibilityAndArguments(BaseTestCase::class, OopVisibility::Public, 3); } /** diff --git a/tests/Traits/Test/Base/BaseTestCaseTraitTest.php b/tests/Traits/Test/Base/BaseTestCaseTraitTest.php index 3ea02cc..9196f16 100644 --- a/tests/Traits/Test/Base/BaseTestCaseTraitTest.php +++ b/tests/Traits/Test/Base/BaseTestCaseTraitTest.php @@ -11,10 +11,9 @@ namespace Meritoo\Test\Common\Traits\Test\Base; use DateTime; -use Meritoo\Common\Exception\Type\UnknownOopVisibilityTypeException; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Test\Base\BaseTestCase; use Meritoo\Common\Traits\Test\Base\BaseTestCaseTrait; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\Common\Utilities\Reflection; use Meritoo\Test\Common\Traits\Test\Base\BaseTestCaseTrait\SimpleTestCase; use ReflectionMethod; @@ -37,27 +36,19 @@ class BaseTestCaseTraitTest extends BaseTestCase public function testAssertConstructorVisibilityAndArgumentsUsingClassWithoutConstructor(): void { - static::assertConstructorVisibilityAndArguments(SimpleTestCase::class, OopVisibilityType::IS_PUBLIC, 3); + static::assertConstructorVisibilityAndArguments(SimpleTestCase::class, OopVisibility::Public, 3); } public function testAssertMethodVisibility(): void { $method = new ReflectionMethod(SimpleTestCase::class, 'assertMethodVisibility'); - static::assertMethodVisibility($method, OopVisibilityType::IS_PROTECTED); - } - - public function testAssertMethodVisibilityUsingIncorrectVisibility(): void - { - $this->expectException(UnknownOopVisibilityTypeException::class); - - $method = new ReflectionMethod(SimpleTestCase::class, 'assertMethodVisibility'); - static::assertMethodVisibility($method, '4'); + static::assertMethodVisibility($method, OopVisibility::Protected); } public function testAssertMethodVisibilityUsingPrivate(): void { $method = new ReflectionMethod(SimpleTestCase::class, 'thePrivateMethod'); - static::assertMethodVisibility($method, OopVisibilityType::IS_PRIVATE); + static::assertMethodVisibility($method, OopVisibility::Private); } public function testSetTestsDataDirPath(): void diff --git a/tests/Traits/Test/Base/BaseTypeTestCaseTrait/SimpleTestCase.php b/tests/Traits/Test/Base/BaseTypeTestCaseTrait/SimpleTestCase.php deleted file mode 100644 index d8c2393..0000000 --- a/tests/Traits/Test/Base/BaseTypeTestCaseTrait/SimpleTestCase.php +++ /dev/null @@ -1,51 +0,0 @@ - 'a', - 'B' => 'b', - ]; - } - - protected function getTestedTypeInstance(): BaseType - { - return new TestedType(); - } -} diff --git a/tests/Traits/Test/Base/BaseTypeTestCaseTrait/TestedType.php b/tests/Traits/Test/Base/BaseTypeTestCaseTrait/TestedType.php deleted file mode 100644 index 63a525a..0000000 --- a/tests/Traits/Test/Base/BaseTypeTestCaseTrait/TestedType.php +++ /dev/null @@ -1,23 +0,0 @@ - - * @copyright Meritoo - * - * @internal - * @covers \Meritoo\Common\Traits\Test\Base\BaseTypeTestCaseTrait - */ -class BaseTypeTestCaseTraitTest extends BaseTestCase -{ - private SimpleTestCase $instance; - - public function testProvideTypeToVerify(): void - { - foreach ($this->instance->provideTypeToVerify() as $value) { - self::assertIsString($value[0]); - } - } - - public function testTestAvailabilityOfAllTypes(): void - { - $this->instance->testAvailabilityOfAllTypes(); - } - - public function testTestIfGivenTypeIsCorrect(): void - { - $this->instance->testIfGivenTypeIsCorrect(true, true); - } - - protected function setUp(): void - { - parent::setUp(); - $this->instance = new SimpleTestCase(); - } -} diff --git a/tests/Type/Base/BaseTypeTest.php b/tests/Type/Base/BaseTypeTest.php deleted file mode 100644 index 8becd8e..0000000 --- a/tests/Type/Base/BaseTypeTest.php +++ /dev/null @@ -1,242 +0,0 @@ - - * @copyright Meritoo - * - * @internal - * @covers \Meritoo\Common\Type\Base\BaseType - */ -class BaseTypeTest extends BaseTestCase -{ - /** - * Provides type of something for testing the getAll() method - * - * @return Generator - */ - public function provideType(): ?Generator - { - yield [ - new TestEmptyType(), - [], - ]; - - yield [ - new TestType(), - [ - 'TEST_1' => TestType::TEST_1, - 'TEST_2' => TestType::TEST_2, - 'TEST_3' => 3, - 'TEST_4' => 4, - ], - ]; - } - - /** - * Provides type of something for testing the isCorrectType() method - * - * @return Generator - */ - public function provideTypeToVerifyUsingTestEmptyType(): ?Generator - { - yield [ - null, - false, - ]; - - yield [ - 'null', - false, - ]; - - yield [ - 'false', - false, - ]; - - yield [ - 'true', - false, - ]; - - yield [ - '', - false, - ]; - - yield [ - '0', - false, - ]; - - yield [ - 0, - false, - ]; - - yield [ - '1', - false, - ]; - - yield [ - 1, - false, - ]; - - yield [ - 'lorem', - false, - ]; - } - - /** - * Provides type of something for testing the isCorrectType() method - * - * @return Generator - */ - public function provideTypeToVerifyUsingTestType(): ?Generator - { - yield [ - null, - false, - ]; - - yield [ - 'null', - false, - ]; - - yield [ - 'false', - false, - ]; - - yield [ - 'true', - false, - ]; - - yield [ - '', - false, - ]; - - yield [ - '0', - false, - ]; - - yield [ - '1', - false, - ]; - - yield [ - 'lorem', - false, - ]; - - yield [ - 'test', - false, - ]; - - yield [ - 'test_1', - true, - ]; - - yield [ - 'test_2', - true, - ]; - - yield [ - 3, - true, - ]; - - yield [ - 4, - true, - ]; - } - - public function testConstructor(): void - { - static::assertHasNoConstructor(BaseType::class); - } - - /** - * @param BaseType $type Type of something - * @param array $expectedTypes Expected concrete types of given instance of type - * - * @dataProvider provideType - */ - public function testGetAll(BaseType $type, array $expectedTypes): void - { - $all = $type->getAll(); - self::assertEquals($expectedTypes, $all); - } - - /** - * @param string $toVerifyType Concrete type to verify - * @param bool $isCorrect Expected information if given type is correct - * - * @dataProvider provideTypeToVerifyUsingTestEmptyType - */ - public function testIsCorrectTypeUsingTestEmptyType(null|string|int $toVerifyType, bool $isCorrect): void - { - self::assertEquals($isCorrect, (new 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(null|string|int $toVerifyType, bool $isCorrect): void - { - self::assertEquals($isCorrect, (new TestType())->isCorrectType($toVerifyType)); - } -} - -/** - * Empty type of something used for testing - * - * @author Meritoo - * @copyright Meritoo - */ -class TestEmptyType extends BaseType -{ -} - -/** - * Type of something used for testing - * - * @author Meritoo - * @copyright Meritoo - */ -class TestType extends BaseType -{ - public const TEST_1 = 'test_1'; - public const TEST_2 = 'test_2'; - public const TEST_3 = 3; - public const TEST_4 = 4; -} diff --git a/tests/Type/DatePartTypeTest.php b/tests/Type/DatePartTypeTest.php deleted file mode 100644 index 2c8daa4..0000000 --- a/tests/Type/DatePartTypeTest.php +++ /dev/null @@ -1,105 +0,0 @@ - - * @copyright Meritoo - * - * @internal - * @covers \Meritoo\Common\Type\DatePartType - */ -class DatePartTypeTest extends BaseTypeTestCase -{ - /** - * {@inheritdoc} - */ - public function provideTypeToVerify(): Generator - { - yield [ - (new DatePartType())->isCorrectType(''), - false, - ]; - - yield [ - (new DatePartType())->isCorrectType(null), - false, - ]; - - yield [ - (new DatePartType())->isCorrectType('0'), - false, - ]; - - yield [ - (new DatePartType())->isCorrectType('1'), - false, - ]; - - yield [ - (new DatePartType())->isCorrectType('day'), - true, - ]; - - yield [ - (new DatePartType())->isCorrectType('hour'), - true, - ]; - - yield [ - (new DatePartType())->isCorrectType('minute'), - true, - ]; - - yield [ - (new DatePartType())->isCorrectType('month'), - true, - ]; - - yield [ - (new DatePartType())->isCorrectType('second'), - true, - ]; - - yield [ - (new DatePartType())->isCorrectType('year'), - true, - ]; - } - - /** - * {@inheritdoc} - */ - protected function getAllExpectedTypes(): array - { - return [ - 'DAY' => 'day', - 'HOUR' => 'hour', - 'MINUTE' => 'minute', - 'MONTH' => 'month', - 'SECOND' => 'second', - 'YEAR' => 'year', - ]; - } - - /** - * {@inheritdoc} - */ - protected function getTestedTypeInstance(): BaseType - { - return new DatePartType(); - } -} diff --git a/tests/Type/OopVisibilityTypeTest.php b/tests/Type/OopVisibilityTypeTest.php deleted file mode 100644 index 4cd817a..0000000 --- a/tests/Type/OopVisibilityTypeTest.php +++ /dev/null @@ -1,82 +0,0 @@ - - * @copyright Meritoo - * - * @internal - * @covers \Meritoo\Common\Type\OopVisibilityType - */ -class OopVisibilityTypeTest extends BaseTypeTestCase -{ - /** - * {@inheritdoc} - */ - public function provideTypeToVerify(): Generator - { - yield [ - (new OopVisibilityType())->isCorrectType(''), - false, - ]; - - yield [ - (new OopVisibilityType())->isCorrectType(null), - false, - ]; - - yield [ - (new OopVisibilityType())->isCorrectType('-1'), - false, - ]; - - yield [ - (new OopVisibilityType())->isCorrectType('1'), - true, - ]; - - yield [ - (new OopVisibilityType())->isCorrectType('2'), - true, - ]; - - yield [ - (new OopVisibilityType())->isCorrectType('3'), - true, - ]; - } - - /** - * {@inheritdoc} - */ - protected function getAllExpectedTypes(): array - { - return [ - 'IS_PRIVATE' => 3, - 'IS_PROTECTED' => 2, - 'IS_PUBLIC' => 1, - ]; - } - - /** - *{@inheritdoc} - */ - protected function getTestedTypeInstance(): BaseType - { - return new OopVisibilityType(); - } -} diff --git a/tests/Utilities/DateTest.php b/tests/Utilities/DateTest.php index 515e423..6b7d0f1 100644 --- a/tests/Utilities/DateTest.php +++ b/tests/Utilities/DateTest.php @@ -11,11 +11,12 @@ use DateInterval; use DateTime; use Generator; -use Meritoo\Common\Exception\Type\UnknownDatePartTypeException; +use Meritoo\Common\Enums\Date\DatePeriod as DatePeriodEnum; +use Meritoo\Common\Exception\Date\InvalidDatePartException; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\DatePeriod; use Meritoo\Common\Utilities\Date; use Meritoo\Common\Utilities\Locale; +use Meritoo\Common\ValueObject\DatePeriod; /** * Test case of the Date methods (only static functions) @@ -36,7 +37,7 @@ class DateTest extends BaseTestCase public function provideCorrectPeriod() { yield [ - DatePeriod::LAST_WEEK, + DatePeriodEnum::LastWeek, new DatePeriod( (new DateTime('this week'))->sub(new DateInterval('P7D'))->setTime(0, 0, 0), (new DateTime('this week'))->sub(new DateInterval('P1D'))->setTime(23, 59, 59) @@ -44,7 +45,7 @@ public function provideCorrectPeriod() ]; yield [ - DatePeriod::THIS_WEEK, + DatePeriodEnum::ThisWeek, new DatePeriod( (new DateTime('this week'))->setTime(0, 0, 0), (new DateTime('this week'))->add(new DateInterval('P6D'))->setTime(23, 59, 59) @@ -52,7 +53,7 @@ public function provideCorrectPeriod() ]; yield [ - DatePeriod::NEXT_WEEK, + DatePeriodEnum::NextWeek, new DatePeriod( (new DateTime('this week'))->add(new DateInterval('P7D'))->setTime(0, 0, 0), (new DateTime('this week'))->add(new DateInterval('P7D')) @@ -62,7 +63,7 @@ public function provideCorrectPeriod() ]; yield [ - DatePeriod::LAST_MONTH, + DatePeriodEnum::LastMonth, new DatePeriod( (new DateTime('first day of last month'))->setTime(0, 0, 0), (new DateTime('last day of last month'))->setTime(23, 59, 59) @@ -70,13 +71,13 @@ public function provideCorrectPeriod() ]; yield [ - DatePeriod::THIS_MONTH, + DatePeriodEnum::ThisMonth, new DatePeriod( - Date::getDatesForPeriod(DatePeriod::LAST_MONTH) + Date::getDatesForPeriod(DatePeriodEnum::LastMonth) ->getEndDate() ->add(new DateInterval('P1D')) ->setTime(0, 0, 0), - Date::getDatesForPeriod(DatePeriod::NEXT_MONTH) + Date::getDatesForPeriod(DatePeriodEnum::NextMonth) ->getStartDate() ->sub(new DateInterval('P1D')) ->setTime(23, 59, 59) @@ -84,7 +85,7 @@ public function provideCorrectPeriod() ]; yield [ - DatePeriod::NEXT_MONTH, + DatePeriodEnum::NextMonth, new DatePeriod( (new DateTime('first day of next month'))->setTime(0, 0, 0), (new DateTime('last day of next month'))->setTime(23, 59, 59) @@ -96,7 +97,7 @@ public function provideCorrectPeriod() $year = $lastYearStart->format('Y'); yield [ - DatePeriod::LAST_YEAR, + DatePeriodEnum::LastYear, new DatePeriod( $lastYearStart->setDate($year, 1, 1)->setTime(0, 0, 0), $lastYearEnd->setDate($year, 12, 31)->setTime(23, 59, 59) @@ -106,7 +107,7 @@ public function provideCorrectPeriod() $year = (new DateTime())->format('Y'); yield [ - DatePeriod::THIS_YEAR, + DatePeriodEnum::ThisYear, new DatePeriod( (new DateTime())->setDate($year, 1, 1)->setTime(0, 0, 0), (new DateTime())->setDate($year, 12, 31)->setTime(23, 59, 59) @@ -118,7 +119,7 @@ public function provideCorrectPeriod() $year = $nextYearStart->format('Y'); yield [ - DatePeriod::NEXT_YEAR, + DatePeriodEnum::NextYear, new DatePeriod( $nextYearStart->setDate($year, 1, 1)->setTime(0, 0, 0), $nextYearEnd->setDate($year, 12, 31)->setTime(23, 59, 59) @@ -251,18 +252,6 @@ public function provideIncorrectDateTimeValue() yield ['2015-16-01']; } - /** - * Provides incorrect period - * - * @return Generator - */ - public function provideIncorrectPeriod() - { - yield [-1]; - yield [0]; - yield [10]; - } - /** * Provides incorrect values of year, month and day * @@ -274,30 +263,40 @@ public function provideIncorrectYearMonthDay(): Generator 0, 0, 0, + 'month', + 0, ]; yield [ -1, -1, -1, + 'year', + -1, ]; yield [ 5000, 50, 50, + 'month', + 50, ]; yield [ 2000, 13, 01, + 'month', + 13, ]; yield [ 2000, 01, 40, + 'day', + 40, ]; } @@ -846,32 +845,12 @@ public function testGetDatesCollectionInvalidInterval($invalidInterval): void self::assertEquals([], Date::getDatesCollection(new DateTime(), 2, '%d')); } - /** - * @param int $period The period, type of period. One of DatePeriod class constants, e.g. - * DatePeriod::LAST_WEEK. - * @param DatePeriod $expected Expected start and end date for given period - * - * @dataProvider provideCorrectPeriod - */ - public function testGetDatesForPeriod($period, DatePeriod $expected): void + /** @dataProvider provideCorrectPeriod */ + public function testGetDatesForPeriod(DatePeriodEnum $period, DatePeriod $expected): void { self::assertEquals($expected, Date::getDatesForPeriod($period)); } - public function testGetDatesForPeriodUsingEmptyString(): void - { - self::assertNull(Date::getDatesForPeriod('')); - } - - /** - * @param int $period Incorrect period to verify - * @dataProvider provideIncorrectPeriod - */ - public function testGetDatesForPeriodUsingIncorrectPeriod($period): void - { - self::assertNull(Date::getDatesForPeriod($period)); - } - /** * @param int $year The year value * @param int $month The month value @@ -884,16 +863,17 @@ public function testGetDayOfWeek(int $year, int $month, int $day): void self::assertMatchesRegularExpression('/^[0-6]{1}$/', (string) Date::getDayOfWeek($year, $month, $day)); } - /** - * @param int $year The year value - * @param int $month The month value - * @param int $day The day value - * - * @dataProvider provideIncorrectYearMonthDay - */ - public function testGetDayOfWeekIncorrectValues(int $year, int $month, int $day): void - { - $this->expectException(UnknownDatePartTypeException::class); + /** @dataProvider provideIncorrectYearMonthDay */ + public function testGetDayOfWeekIncorrectValues( + int $year, + int $month, + int $day, + string $invalidDatePart, + int $invalidValue, + ): void { + $this->expectException(InvalidDatePartException::class); + $this->expectExceptionMessage('Value of the \''.$invalidDatePart.'\' date part is invalid: '.$invalidValue); + self::assertEmpty(Date::getDayOfWeek($year, $month, $day)); } diff --git a/tests/ValueObject/AddressTest.php b/tests/ValueObject/AddressTest.php index 63981e7..956904f 100644 --- a/tests/ValueObject/AddressTest.php +++ b/tests/ValueObject/AddressTest.php @@ -6,10 +6,12 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\ValueObject; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\Common\ValueObject\Address; /** @@ -42,7 +44,7 @@ public function testConstructor() { static::assertConstructorVisibilityAndArguments( Address::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, 5, 4 ); diff --git a/tests/ValueObject/BankAccountTest.php b/tests/ValueObject/BankAccountTest.php index 52277be..44e2617 100644 --- a/tests/ValueObject/BankAccountTest.php +++ b/tests/ValueObject/BankAccountTest.php @@ -6,10 +6,12 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\ValueObject; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\Common\ValueObject\BankAccount; /** @@ -37,7 +39,7 @@ public function testConstructor() { static::assertConstructorVisibilityAndArguments( BankAccount::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, 2, 2 ); diff --git a/tests/ValueObject/CompanyTest.php b/tests/ValueObject/CompanyTest.php index dcd66c7..ea1d4ae 100644 --- a/tests/ValueObject/CompanyTest.php +++ b/tests/ValueObject/CompanyTest.php @@ -6,10 +6,12 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\ValueObject; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\Common\ValueObject\Address; use Meritoo\Common\ValueObject\BankAccount; use Meritoo\Common\ValueObject\Company; @@ -39,7 +41,7 @@ public function testConstructor() { static::assertConstructorVisibilityAndArguments( Company::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, 3, 2 ); diff --git a/tests/Type/DatePeriodTest.php b/tests/ValueObject/DatePeriodTest.php similarity index 76% rename from tests/Type/DatePeriodTest.php rename to tests/ValueObject/DatePeriodTest.php index bb2614c..a3e4ce6 100644 --- a/tests/Type/DatePeriodTest.php +++ b/tests/ValueObject/DatePeriodTest.php @@ -6,14 +6,15 @@ * file that was distributed with this source code. */ -namespace Meritoo\Test\Common\Type; +declare(strict_types=1); + +namespace Meritoo\Test\Common\ValueObject; 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; +use Meritoo\Common\Enums\OopVisibility; +use Meritoo\Common\Test\Base\BaseTestCase; +use Meritoo\Common\ValueObject\DatePeriod; /** * Test case of date's period @@ -22,9 +23,9 @@ * @copyright Meritoo * * @internal - * @covers \Meritoo\Common\Type\DatePeriod + * @covers \Meritoo\Common\ValueObject\DatePeriod */ -class DatePeriodTest extends BaseTypeTestCase +class DatePeriodTest extends BaseTestCase { /** * Provides the start and end date of date period @@ -163,11 +164,6 @@ public function provideDatePeriodAndDateFormatUsingStartDateOnly(): Generator ]; } - /** - * Provides period and incorrect format of date to verify - * - * @return Generator - */ public function provideDatePeriodAndIncorrectDateFormat(): Generator { $startDate = new DateTime('2001-01-01'); @@ -180,7 +176,12 @@ public function provideDatePeriodAndIncorrectDateFormat(): Generator yield [ new DatePeriod($startDate, $endDate), - false, + 'false', + ]; + + yield [ + new DatePeriod($startDate, $endDate), + 'xyz', ]; } @@ -213,37 +214,6 @@ public function provideDatePeriodAndUnknownDate(): ?Generator ]; } - /** - * {@inheritdoc} - */ - public function provideTypeToVerify(): Generator - { - yield [ - (new DatePeriod())->isCorrectType(''), - false, - ]; - - yield [ - (new DatePeriod())->isCorrectType('-1'), - false, - ]; - - yield [ - (new DatePeriod())->isCorrectType('4'), - true, - ]; - - yield [ - (new DatePeriod())->isCorrectType('3'), - true, - ]; - - yield [ - (new DatePeriod())->isCorrectType('8'), - true, - ]; - } - /** * @param DateTime $startDate (optional) Start date of period * @param DateTime $endDate (optional) End date of period @@ -262,7 +232,7 @@ public function testConstructorVisibilityAndArguments(): void { static::assertConstructorVisibilityAndArguments( DatePeriod::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, 2 ); } @@ -280,13 +250,8 @@ public function testGetFormattedDate(DatePeriod $period, $format, $startDate, $e self::assertEquals($expected, $period->getFormattedDate($format, $startDate)); } - /** - * @param DatePeriod $period The date period to verify - * @param string $format Format used to format the date - * - * @dataProvider provideDatePeriodAndIncorrectDateFormat - */ - public function testGetFormattedDateUsingIncorrectDateFormat(DatePeriod $period, $format): void + /** @dataProvider provideDatePeriodAndIncorrectDateFormat */ + public function testGetFormattedDateUsingIncorrectDateFormat(DatePeriod $period, string $format): void { self::assertEquals('', $period->getFormattedDate($format)); } @@ -315,12 +280,7 @@ public function testGetFormattedDateUsingUnknownDate(DatePeriod $period, $format self::assertEquals('', $period->getFormattedDate($format, $startDate)); } - /** - * @param DateTime $startDate (optional) Start date of period - * @param DateTime $endDate (optional) End date of period - * - * @dataProvider provideDatePeriod - */ + /** @dataProvider provideDatePeriod */ public function testGettersAndSetters(DateTime $startDate = null, DateTime $endDate = null): void { $period = new DatePeriod(); @@ -331,32 +291,4 @@ public function testGettersAndSetters(DateTime $startDate = null, DateTime $endD $period->setEndDate($endDate); self::assertEquals($endDate, $period->getEndDate()); } - - /** - * Returns all expected types of the tested type - * - * @return array - */ - protected function getAllExpectedTypes(): array - { - return [ - '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(): BaseType - { - return new DatePeriod(); - } } diff --git a/tests/ValueObject/HumanTest.php b/tests/ValueObject/HumanTest.php index c8d9ef8..f25d172 100644 --- a/tests/ValueObject/HumanTest.php +++ b/tests/ValueObject/HumanTest.php @@ -6,11 +6,13 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\ValueObject; use DateTime; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\Common\ValueObject\Human; /** @@ -58,7 +60,7 @@ public function testConstructor() { static::assertConstructorVisibilityAndArguments( Human::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, 4, 2 ); diff --git a/tests/ValueObject/SizeTest.php b/tests/ValueObject/SizeTest.php index a92f76d..e664fe7 100644 --- a/tests/ValueObject/SizeTest.php +++ b/tests/ValueObject/SizeTest.php @@ -9,9 +9,9 @@ namespace Meritoo\Test\Common\ValueObject; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Exception\ValueObject\InvalidSizeDimensionsException; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\Common\ValueObject\Size; /** @@ -857,7 +857,7 @@ public function testConstructor() { static::assertConstructorVisibilityAndArguments( Size::class, - OopVisibilityType::IS_PRIVATE, + OopVisibility::Private, 3 ); } diff --git a/tests/ValueObject/TemplateTest.php b/tests/ValueObject/TemplateTest.php index 8dc8f7c..7f778d2 100644 --- a/tests/ValueObject/TemplateTest.php +++ b/tests/ValueObject/TemplateTest.php @@ -6,13 +6,15 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\ValueObject; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Exception\ValueObject\Template\InvalidContentException; use Meritoo\Common\Exception\ValueObject\Template\MissingPlaceholdersInValuesException; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\Common\Utilities\Reflection; use Meritoo\Common\ValueObject\Template; @@ -208,7 +210,7 @@ public function testConstructor(): void { static::assertConstructorVisibilityAndArguments( Template::class, - OopVisibilityType::IS_PUBLIC, + OopVisibility::Public, 1, 1 ); diff --git a/tests/ValueObject/VersionTest.php b/tests/ValueObject/VersionTest.php index 210374f..c50c3bd 100644 --- a/tests/ValueObject/VersionTest.php +++ b/tests/ValueObject/VersionTest.php @@ -6,11 +6,13 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace Meritoo\Test\Common\ValueObject; use Generator; +use Meritoo\Common\Enums\OopVisibility; use Meritoo\Common\Test\Base\BaseTestCase; -use Meritoo\Common\Type\OopVisibilityType; use Meritoo\Common\Utilities\Reflection; use Meritoo\Common\ValueObject\Version; @@ -143,7 +145,7 @@ public function provideConvertedToString() public function testConstructor() { - static::assertConstructorVisibilityAndArguments(Version::class, OopVisibilityType::IS_PUBLIC, 3, 3); + static::assertConstructorVisibilityAndArguments(Version::class, OopVisibility::Public, 3, 3); } /**