Skip to content

Commit 049ae22

Browse files
authored
Merge pull request #9 from Micro-PHP/1.6.1
1.6.1
2 parents fc14ffc + 235a8fa commit 049ae22

File tree

6 files changed

+41
-35
lines changed

6 files changed

+41
-35
lines changed

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@
2626
"ext-libxml": "*",
2727
"nette/php-generator": "^4",
2828
"psr/log": "^1 || ^2 || ^3",
29-
"symfony/intl": "^5 || ^6",
30-
"symfony/property-access": "^5 || ^6",
31-
"symfony/validator": "^5 || ^6"
29+
"symfony/intl": "^5.4 || ^6",
30+
"symfony/property-access": "^5.4 || ^6",
31+
"symfony/validator": "^5.4.15 || ^6"
3232
},
3333
"require-dev": {
3434
"ergebnis/composer-normalize": "^2.29",
3535
"friendsofphp/php-cs-fixer": "^3.13",
3636
"phpstan/phpstan": "^1.9",
3737
"phpunit/php-code-coverage": "^9.2",
3838
"phpunit/phpunit": "^9.5",
39-
"symfony/var-dumper": "^5 || ^6",
39+
"symfony/var-dumper": "^5.4 || ^6",
4040
"vimeo/psalm": "^5.2"
4141
},
4242
"autoload": {

src/Preparation/Processor/Property/Assert/UuidStrategy.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,22 @@
1717

1818
class UuidStrategy extends AbstractConstraintStrategy
1919
{
20-
public const ALLOWED_VERSIONS = [
21-
Uuid::V1_MAC,
22-
Uuid::V2_DCE,
23-
Uuid::V3_MD5,
24-
Uuid::V4_RANDOM,
25-
Uuid::V5_SHA1,
26-
Uuid::V6_SORTABLE,
27-
Uuid::V7_MONOTONIC,
28-
];
20+
/**
21+
* @return array<int>
22+
*/
23+
public function getAvailableVersions(): array
24+
{
25+
// Supports 5.4 version
26+
$constants = [
27+
'V1_MAC', 'V2_DCE', 'V3_MD5', 'V4_RANDOM', 'V5_SHA1', 'V6_SORTABLE', 'V7_MONOTONIC',
28+
];
29+
30+
return array_filter(array_map(function (string $constName) {
31+
$cName = sprintf('%s::%s', Uuid::class, $constName);
32+
33+
return \defined($cName) ? \constant($cName) : null;
34+
}, $constants));
35+
}
2936

3037
protected function generateArguments(array $config): array
3138
{
@@ -54,8 +61,9 @@ protected function getAttributeClassName(): string
5461
*/
5562
private function parseVersions(array|string $original): array
5663
{
64+
$availableVersions = $this->getAvailableVersions();
5765
if ('' === $original) {
58-
return self::ALLOWED_VERSIONS;
66+
return $availableVersions;
5967
}
6068

6169
$versions = $original;
@@ -64,11 +72,11 @@ private function parseVersions(array|string $original): array
6472
}
6573

6674
$versions = array_map('intval', $versions);
67-
$isValid = !array_diff($versions, self::ALLOWED_VERSIONS);
75+
$isValid = !array_diff($versions, $availableVersions);
6876
if ($isValid) {
6977
return $versions;
7078
}
7179

72-
throw new \InvalidArgumentException(sprintf('UUID versions is not allowed. Actual: `%s`, Available: `%s`', \is_array($original) ? implode(', ', $original) : $original, implode(',', self::ALLOWED_VERSIONS)));
80+
throw new \InvalidArgumentException(sprintf('UUID versions is not allowed. Actual: `%s`, Available: `%s`', \is_array($original) ? implode(', ', $original) : $original, implode(',', $availableVersions)));
7381
}
7482
}

src/Reader/XmlReader.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
/**
1919
* @TODO: Temporary solution. MVP
20-
*
2120
* @TODO: Get XSD api version
2221
*/
2322
class XmlReader implements ReaderInterface

src/Validator/ValidatorInterface.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ interface ValidatorInterface
2121
/**
2222
* @param AbstractDto $dto
2323
* @param string[]|string $groups
24-
*
25-
* @return ConstraintViolationListInterface
2624
*/
2725
public function validate(AbstractDto $dto, array|string $groups = 'Default'): ConstraintViolationListInterface;
2826
}

tests/Unit/Out/Simple/SimpleUserTransfer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ final class SimpleUserTransfer extends \Micro\Library\DTO\Object\AbstractDto
4444
protected string|null $json = null;
4545

4646
#[\Symfony\Component\Validator\Constraints\NotBlank(groups: ['Default'], allowNull: false)]
47-
#[\Symfony\Component\Validator\Constraints\Uuid(groups: ['Default'], versions: [1, 2, 3, 4, 5, 6, 7], strict: true)]
47+
#[\Symfony\Component\Validator\Constraints\Uuid(groups: ['Default'], versions: [1, 2, 3, 4, 5, 6], strict: true)]
4848
protected string|null $uuid = null;
4949

5050
#[\Symfony\Component\Validator\Constraints\DateTime(groups: ['Default'], format: 'Y-m-d H:i:s')]

tests/Unit/libraryTest.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function testSchemaFileNotFount(): void
6565
public function testValidateSuccessDto(): void
6666
{
6767
$validatorFacade = new ValidatorFacadeDefault();
68+
6869
$this->assertEquals(0, \count($validatorFacade->validate($this->createValidDto())));
6970
}
7071

@@ -89,21 +90,6 @@ public function testSerializeValid(): void
8990
$this->testSerialize($this->createValidDto(), $json);
9091
}
9192

92-
protected function testSerialize(AbstractDto $dtoTransfer, string $exceptedJson): void
93-
{
94-
$serializer = new SerializerFacadeDefault();
95-
96-
$json = $serializer->toJsonTransfer($dtoTransfer);
97-
$arrayTransfer = $serializer->toArrayTransfer($dtoTransfer);
98-
99-
$this->assertEquals($dtoTransfer, $serializer->fromArrayTransfer($arrayTransfer));
100-
101-
$simpleJson = $serializer->toJson($dtoTransfer);
102-
$this->assertEquals($exceptedJson, $simpleJson);
103-
104-
$this->assertEquals($dtoTransfer, $serializer->fromJsonTransfer($json));
105-
}
106-
10793
public function testIterableDto(): void
10894
{
10995
$simpleUser = new SimpleUserTransfer();
@@ -127,6 +113,21 @@ public function testIterableDto(): void
127113
$simpleUser[$invalidProperty];
128114
}
129115

116+
protected function testSerialize(AbstractDto $dtoTransfer, string $exceptedJson): void
117+
{
118+
$serializer = new SerializerFacadeDefault();
119+
120+
$json = $serializer->toJsonTransfer($dtoTransfer);
121+
$arrayTransfer = $serializer->toArrayTransfer($dtoTransfer);
122+
123+
$this->assertEquals($dtoTransfer, $serializer->fromArrayTransfer($arrayTransfer));
124+
125+
$simpleJson = $serializer->toJson($dtoTransfer);
126+
$this->assertEquals($exceptedJson, $simpleJson);
127+
128+
$this->assertEquals($dtoTransfer, $serializer->fromJsonTransfer($json));
129+
}
130+
130131
protected function createEmptyDto(): SimpleUserTransfer
131132
{
132133
return new SimpleUserTransfer();

0 commit comments

Comments
 (0)