Skip to content

Commit fa6a5e4

Browse files
committed
test(symfony): skip legacy type
1 parent f0b6bb6 commit fa6a5e4

8 files changed

+266
-220
lines changed

src/Symfony/Tests/Validator/Metadata/Property/Restriction/PropertySchemaChoiceRestrictionTest.php

Lines changed: 76 additions & 69 deletions
Large diffs are not rendered by default.

src/Symfony/Tests/Validator/Metadata/Property/Restriction/PropertySchemaGreaterThanOrEqualRestrictionTest.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,20 @@ protected function setUp(): void
4343
#[IgnoreDeprecations]
4444
public function testSupports(): void
4545
{
46-
foreach ($this->supportsProvider() as [$constraint, $propertyMetadata, $expectedResult]) {
46+
if (!class_exists(LegacyType::class)) {
47+
$this->markTestSkipped('symfony/property-info is not installed.');
48+
}
49+
50+
$cases = [
51+
'supported int/float with union types' => [new GreaterThanOrEqual(value: 10), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT), new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)]), true],
52+
'supported int' => [new GreaterThanOrEqual(value: 10), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), true],
53+
'supported float' => [new GreaterThanOrEqual(value: 10.99), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)]), true],
54+
'supported positive or zero' => [new PositiveOrZero(), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), true],
55+
'not supported positive' => [new Positive(), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), false],
56+
'not supported property path' => [new GreaterThanOrEqual(propertyPath: 'greaterThanMe'), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), false],
57+
];
58+
59+
foreach ($cases as [$constraint, $propertyMetadata, $expectedResult]) {
4760
self::assertSame($expectedResult, $this->propertySchemaGreaterThanOrEqualRestriction->supports($constraint, $propertyMetadata));
4861
}
4962
}
@@ -54,16 +67,6 @@ public function testSupportsWithNativeType(Constraint $constraint, ApiProperty $
5467
self::assertSame($expectedResult, $this->propertySchemaGreaterThanOrEqualRestriction->supports($constraint, $propertyMetadata));
5568
}
5669

57-
public static function supportsProvider(): \Generator
58-
{
59-
yield 'supported int/float with union types' => [new GreaterThanOrEqual(value: 10), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT), new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)]), true];
60-
yield 'supported int' => [new GreaterThanOrEqual(value: 10), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), true];
61-
yield 'supported float' => [new GreaterThanOrEqual(value: 10.99), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)]), true];
62-
yield 'supported positive or zero' => [new PositiveOrZero(), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), true];
63-
yield 'not supported positive' => [new Positive(), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), false];
64-
yield 'not supported property path' => [new GreaterThanOrEqual(propertyPath: 'greaterThanMe'), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), false];
65-
}
66-
6770
public static function supportsProviderWithNativeType(): \Generator
6871
{
6972
yield 'native type: supported int/float with union types' => [new GreaterThanOrEqual(value: 10), (new ApiProperty())->withNativeType(Type::union(Type::int(), Type::float())), true];
@@ -77,6 +80,10 @@ public static function supportsProviderWithNativeType(): \Generator
7780
#[IgnoreDeprecations]
7881
public function testCreate(): void
7982
{
83+
if (!class_exists(LegacyType::class)) {
84+
$this->markTestSkipped('symfony/property-info is not installed.');
85+
}
86+
8087
self::assertEquals(['minimum' => 10], $this->propertySchemaGreaterThanOrEqualRestriction->create(new GreaterThanOrEqual(value: 10), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)])));
8188
}
8289

src/Symfony/Tests/Validator/Metadata/Property/Restriction/PropertySchemaGreaterThanRestrictionTest.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,20 @@ protected function setUp(): void
4343
#[IgnoreDeprecations]
4444
public function testSupports(): void
4545
{
46-
foreach ($this->supportsProvider() as [$constraint, $propertyMetadata, $expectedResult]) {
46+
if (!class_exists(LegacyType::class)) {
47+
$this->markTestSkipped('symfony/property-info is not installed.');
48+
}
49+
50+
$cases = [
51+
'supported int/float with union types' => [new GreaterThan(value: 10), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT), new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)]), true],
52+
'supported int' => [new GreaterThan(value: 10), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), true],
53+
'supported float' => [new GreaterThan(value: 10.99), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)]), true],
54+
'supported positive' => [new Positive(), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), true],
55+
'not supported positive or zero' => [new PositiveOrZero(), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), false],
56+
'not supported property path' => [new GreaterThan(propertyPath: 'greaterThanMe'), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), false],
57+
];
58+
59+
foreach ($cases as [$constraint, $propertyMetadata, $expectedResult]) {
4760
self::assertSame($expectedResult, $this->propertySchemaGreaterThanRestriction->supports($constraint, $propertyMetadata));
4861
}
4962
}
@@ -54,16 +67,6 @@ public function testSupportsWithNativeType(Constraint $constraint, ApiProperty $
5467
self::assertSame($expectedResult, $this->propertySchemaGreaterThanRestriction->supports($constraint, $propertyMetadata));
5568
}
5669

57-
public static function supportsProvider(): \Generator
58-
{
59-
yield 'supported int/float with union types' => [new GreaterThan(value: 10), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT), new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)]), true];
60-
yield 'supported int' => [new GreaterThan(value: 10), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), true];
61-
yield 'supported float' => [new GreaterThan(value: 10.99), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)]), true];
62-
yield 'supported positive' => [new Positive(), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), true];
63-
yield 'not supported positive or zero' => [new PositiveOrZero(), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), false];
64-
yield 'not supported property path' => [new GreaterThan(propertyPath: 'greaterThanMe'), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), false];
65-
}
66-
6770
public static function supportsProviderWithNativeType(): \Generator
6871
{
6972
yield 'native type: supported int/float with union types' => [new GreaterThan(value: 10), (new ApiProperty())->withNativeType(Type::union(Type::int(), Type::float())), true];
@@ -77,6 +80,10 @@ public static function supportsProviderWithNativeType(): \Generator
7780
#[IgnoreDeprecations]
7881
public function testCreate(): void
7982
{
83+
if (!class_exists(LegacyType::class)) {
84+
$this->markTestSkipped('symfony/property-info is not installed.');
85+
}
86+
8087
self::assertEquals([
8188
'exclusiveMinimum' => 10,
8289
'minimum' => 10,

src/Symfony/Tests/Validator/Metadata/Property/Restriction/PropertySchemaLessThanOrEqualRestrictionTest.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,20 @@ protected function setUp(): void
4343
#[IgnoreDeprecations]
4444
public function testSupports(): void
4545
{
46-
foreach ($this->supportsProvider() as [$constraint, $propertyMetadata, $expectedResult]) {
46+
if (!class_exists(LegacyType::class)) {
47+
$this->markTestSkipped('symfony/property-info is not installed.');
48+
}
49+
50+
$cases = [
51+
'supported int/float with union types' => [new LessThanOrEqual(value: 10), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT), new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)]), true],
52+
'supported int' => [new LessThanOrEqual(value: 10), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), true],
53+
'supported float' => [new LessThanOrEqual(value: 10.99), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)]), true],
54+
'supported negative or zero' => [new NegativeOrZero(), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), true],
55+
'not supported negative' => [new Negative(), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), false],
56+
'not supported property path' => [new LessThanOrEqual(propertyPath: 'greaterThanMe'), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), false],
57+
];
58+
59+
foreach ($cases as [$constraint, $propertyMetadata, $expectedResult]) {
4760
self::assertSame($expectedResult, $this->propertySchemaLessThanOrEqualRestriction->supports($constraint, $propertyMetadata));
4861
}
4962
}
@@ -54,16 +67,6 @@ public function testSupportsWithNativeType(Constraint $constraint, ApiProperty $
5467
self::assertSame($expectedResult, $this->propertySchemaLessThanOrEqualRestriction->supports($constraint, $propertyMetadata));
5568
}
5669

57-
public static function supportsProvider(): \Generator
58-
{
59-
yield 'supported int/float with union types' => [new LessThanOrEqual(value: 10), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT), new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)]), true];
60-
yield 'supported int' => [new LessThanOrEqual(value: 10), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), true];
61-
yield 'supported float' => [new LessThanOrEqual(value: 10.99), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)]), true];
62-
yield 'supported negative or zero' => [new NegativeOrZero(), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), true];
63-
yield 'not supported negative' => [new Negative(), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), false];
64-
yield 'not supported property path' => [new LessThanOrEqual(propertyPath: 'greaterThanMe'), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), false];
65-
}
66-
6770
public static function supportsProviderWithNativeType(): \Generator
6871
{
6972
yield 'native type: supported int/float with union types' => [new LessThanOrEqual(value: 10), (new ApiProperty())->withNativeType(Type::union(Type::int(), Type::float())), true];
@@ -77,6 +80,10 @@ public static function supportsProviderWithNativeType(): \Generator
7780
#[IgnoreDeprecations]
7881
public function testCreate(): void
7982
{
83+
if (!class_exists(LegacyType::class)) {
84+
$this->markTestSkipped('symfony/property-info is not installed.');
85+
}
86+
8087
self::assertEquals(['maximum' => 10], $this->propertySchemaLessThanOrEqualRestriction->create(new LessThanOrEqual(value: 10), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)])));
8188
}
8289

src/Symfony/Tests/Validator/Metadata/Property/Restriction/PropertySchemaLessThanRestrictionTest.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,20 @@ protected function setUp(): void
4343
#[IgnoreDeprecations]
4444
public function testSupports(): void
4545
{
46-
foreach ($this->supportsProvider() as [$constraint, $propertyMetadata, $expectedResult]) {
46+
if (!class_exists(LegacyType::class)) {
47+
$this->markTestSkipped('symfony/property-info is not installed.');
48+
}
49+
50+
$cases = [
51+
'supported int/float with union types' => [new LessThan(value: 10), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT), new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)]), true],
52+
'supported int' => [new LessThan(value: 10), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), true],
53+
'supported float' => [new LessThan(value: 10.99), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)]), true],
54+
'supported negative' => [new Negative(), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), true],
55+
'not supported negative or zero' => [new NegativeOrZero(), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), false],
56+
'not supported property path' => [new LessThan(propertyPath: 'greaterThanMe'), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), false],
57+
];
58+
59+
foreach ($cases as [$constraint, $propertyMetadata, $expectedResult]) {
4760
self::assertSame($expectedResult, $this->propertySchemaLessThanRestriction->supports($constraint, $propertyMetadata));
4861
}
4962
}
@@ -54,16 +67,6 @@ public function testSupportsWithNativeType(Constraint $constraint, ApiProperty $
5467
self::assertSame($expectedResult, $this->propertySchemaLessThanRestriction->supports($constraint, $propertyMetadata));
5568
}
5669

57-
public static function supportsProvider(): \Generator
58-
{
59-
yield 'supported int/float with union types' => [new LessThan(value: 10), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT), new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)]), true];
60-
yield 'supported int' => [new LessThan(value: 10), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), true];
61-
yield 'supported float' => [new LessThan(value: 10.99), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_FLOAT)]), true];
62-
yield 'supported negative' => [new Negative(), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), true];
63-
yield 'not supported negative or zero' => [new NegativeOrZero(), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), false];
64-
yield 'not supported property path' => [new LessThan(propertyPath: 'greaterThanMe'), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), false];
65-
}
66-
6770
public static function supportsProviderWithNativeType(): \Generator
6871
{
6972
yield 'native type: supported int/float with union types' => [new LessThan(value: 10), (new ApiProperty())->withNativeType(Type::union(Type::int(), Type::float())), true];
@@ -77,6 +80,10 @@ public static function supportsProviderWithNativeType(): \Generator
7780
#[IgnoreDeprecations]
7881
public function testCreate(): void
7982
{
83+
if (!class_exists(LegacyType::class)) {
84+
$this->markTestSkipped('symfony/property-info is not installed.');
85+
}
86+
8087
self::assertEquals([
8188
'exclusiveMaximum' => 10,
8289
'maximum' => 10,

src/Symfony/Tests/Validator/Metadata/Property/Restriction/PropertySchemaOneOfRestrictionTest.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,18 @@ public static function supportsProviderWithNativeType(): \Generator
8383
#[IgnoreDeprecations]
8484
public function testCreate(): void
8585
{
86-
foreach ($this->createProvider() as [$constraint, $propertyMetadata, $expectedResult]) {
86+
if (!class_exists(LegacyType::class)) {
87+
$this->markTestSkipped('symfony/property-info is not installed.');
88+
}
89+
90+
$cases = [
91+
'not supported constraints' => [new AtLeastOneOf([new Positive(), new Length(min: 3)]), new ApiProperty(), []],
92+
'one supported constraint' => [new AtLeastOneOf([new Positive(), new Length(min: 3)]), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)]), [
93+
'oneOf' => [['minLength' => 3]],
94+
]],
95+
];
96+
97+
foreach ($cases as [$constraint, $propertyMetadata, $expectedResult]) {
8798
self::assertSame($expectedResult, $this->propertySchemaOneOfRestriction->create($constraint, $propertyMetadata));
8899
}
89100
}
@@ -94,14 +105,6 @@ public function testCreateWithNativeType(AtLeastOneOf $constraint, ApiProperty $
94105
self::assertSame($expectedResult, $this->propertySchemaOneOfRestriction->create($constraint, $propertyMetadata));
95106
}
96107

97-
public static function createProvider(): \Generator
98-
{
99-
yield 'not supported constraints' => [new AtLeastOneOf([new Positive(), new Length(min: 3)]), new ApiProperty(), []];
100-
yield 'one supported constraint' => [new AtLeastOneOf([new Positive(), new Length(min: 3)]), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)]), [
101-
'oneOf' => [['minLength' => 3]],
102-
]];
103-
}
104-
105108
public static function createProviderWithNativeType(): \Generator
106109
{
107110
yield 'native type: not supported constraints' => [new AtLeastOneOf([new Positive(), new Length(min: 3)]), new ApiProperty(), []];

0 commit comments

Comments
 (0)