• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 15394793169

02 Jun 2025 02:22PM UTC coverage: 21.851% (-0.03%) from 21.877%
15394793169

push

github

web-flow
chore: use type-info:^7.3 (#7185)

0 of 168 new or added lines in 12 files covered. (0.0%)

15 existing lines in 7 files now uncovered.

11381 of 52084 relevant lines covered (21.85%)

10.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Symfony/Tests/Validator/Metadata/Property/Restriction/PropertySchemaLessThanRestrictionTest.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\Symfony\Tests\Validator\Metadata\Property\Restriction;
15

16
use ApiPlatform\Metadata\ApiProperty;
17
use ApiPlatform\Symfony\Validator\Metadata\Property\Restriction\PropertySchemaLessThanRestriction;
18
use PHPUnit\Framework\Attributes\DataProvider;
19
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
20
use PHPUnit\Framework\TestCase;
21
use Prophecy\PhpUnit\ProphecyTrait;
22
use Symfony\Component\PropertyInfo\Type as LegacyType;
23
use Symfony\Component\TypeInfo\Type;
24
use Symfony\Component\Validator\Constraint;
25
use Symfony\Component\Validator\Constraints\LessThan;
26
use Symfony\Component\Validator\Constraints\Negative;
27
use Symfony\Component\Validator\Constraints\NegativeOrZero;
28

29
/**
30
 * @author Tomas Norkūnas <norkunas.tom@gmail.com>
31
 */
32
final class PropertySchemaLessThanRestrictionTest extends TestCase
33
{
34
    use ProphecyTrait;
35

36
    private PropertySchemaLessThanRestriction $propertySchemaLessThanRestriction;
37

38
    protected function setUp(): void
39
    {
40
        $this->propertySchemaLessThanRestriction = new PropertySchemaLessThanRestriction();
×
41
    }
42

43
    #[IgnoreDeprecations]
44
    public function testSupports(): void
45
    {
46
        foreach ($this->supportsProvider() as [$constraint, $propertyMetadata, $expectedResult]) {
×
47
            self::assertSame($expectedResult, $this->propertySchemaLessThanRestriction->supports($constraint, $propertyMetadata));
×
48
        }
49
    }
50

51
    #[DataProvider('supportsProviderWithNativeType')]
52
    public function testSupportsWithNativeType(Constraint $constraint, ApiProperty $propertyMetadata, bool $expectedResult): void
53
    {
54
        self::assertSame($expectedResult, $this->propertySchemaLessThanRestriction->supports($constraint, $propertyMetadata));
×
55
    }
56

57
    public static function supportsProvider(): \Generator
58
    {
NEW
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];
×
NEW
60
        yield 'supported int' => [new LessThan(value: 10), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), true];
×
NEW
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];
×
NEW
64
        yield 'not supported property path' => [new LessThan(propertyPath: 'greaterThanMe'), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)]), false];
×
65
    }
66

67
    public static function supportsProviderWithNativeType(): \Generator
68
    {
NEW
69
        yield 'native type: supported int/float with union types' => [new LessThan(value: 10), (new ApiProperty())->withNativeType(Type::union(Type::int(), Type::float())), true];
×
NEW
70
        yield 'native type: supported int' => [new LessThan(value: 10), (new ApiProperty())->withNativeType(Type::int()), true];
×
NEW
71
        yield 'native type: supported float' => [new LessThan(value: 10.99), (new ApiProperty())->withNativeType(Type::float()), true];
×
72
        yield 'native type: supported negative' => [new Negative(), (new ApiProperty())->withNativeType(Type::int()), true];
×
73
        yield 'native type: not supported negative or zero' => [new NegativeOrZero(), (new ApiProperty())->withNativeType(Type::int()), false];
×
NEW
74
        yield 'native type: not supported property path' => [new LessThan(propertyPath: 'greaterThanMe'), (new ApiProperty())->withNativeType(Type::int()), false];
×
75
    }
76

77
    #[IgnoreDeprecations]
78
    public function testCreate(): void
79
    {
80
        self::assertEquals([
×
81
            'exclusiveMaximum' => 10,
×
82
            'maximum' => 10,
×
NEW
83
        ], $this->propertySchemaLessThanRestriction->create(new LessThan(value: 10), (new ApiProperty())->withBuiltinTypes([new LegacyType(LegacyType::BUILTIN_TYPE_INT)])));
×
84
    }
85

86
    public function testCreateWithNativeType(): void
87
    {
88
        self::assertEquals([
×
89
            'exclusiveMaximum' => 10,
×
90
            'maximum' => 10,
×
NEW
91
        ], $this->propertySchemaLessThanRestriction->create(new LessThan(value: 10), (new ApiProperty())->withNativeType(Type::int())));
×
92

93
        self::assertEquals([
×
94
            'exclusiveMaximum' => 0,
×
95
            'maximum' => 0,
×
96
        ], $this->propertySchemaLessThanRestriction->create(new Negative(), (new ApiProperty())->withNativeType(Type::int())));
×
97

98
        self::assertEquals([
×
99
            'exclusiveMaximum' => 10.99,
×
100
            'maximum' => 10.99,
×
NEW
101
        ], $this->propertySchemaLessThanRestriction->create(new LessThan(value: 10.99), (new ApiProperty())->withNativeType(Type::float())));
×
102
    }
103
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc