• 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/PropertySchemaRegexRestrictionTest.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\PropertySchemaRegexRestriction;
18
use PHPUnit\Framework\TestCase;
19
use Prophecy\PhpUnit\ProphecyTrait;
20
use Symfony\Component\Validator\Constraint;
21
use Symfony\Component\Validator\Constraints\Positive;
22
use Symfony\Component\Validator\Constraints\Regex;
23

24
/**
25
 * @author Tomas Norkūnas <norkunas.tom@gmail.com>
26
 */
27
final class PropertySchemaRegexRestrictionTest extends TestCase
28
{
29
    use ProphecyTrait;
30

31
    private PropertySchemaRegexRestriction $propertySchemaRegexRestriction;
32

33
    protected function setUp(): void
34
    {
35
        $this->propertySchemaRegexRestriction = new PropertySchemaRegexRestriction();
×
36
    }
37

38
    #[\PHPUnit\Framework\Attributes\DataProvider('supportsProvider')]
39
    public function testSupports(Constraint $constraint, ApiProperty $propertyMetadata, bool $expectedResult): void
40
    {
41
        self::assertSame($expectedResult, $this->propertySchemaRegexRestriction->supports($constraint, $propertyMetadata));
×
42
    }
43

44
    public static function supportsProvider(): \Generator
45
    {
NEW
46
        yield 'supported' => [new Regex(pattern: '/^[0-9]+$/'), new ApiProperty(), true];
×
NEW
47
        yield 'supported too' => [new Regex(pattern: '/[0-9]/', match: false), new ApiProperty(), true];
×
UNCOV
48
        yield 'not supported' => [new Positive(), new ApiProperty(), false];
×
49
    }
50

51
    #[\PHPUnit\Framework\Attributes\DataProvider('createProvider')]
52
    public function testCreate(Regex $constraint, ApiProperty $propertyMetadata, array $expectedResult): void
53
    {
54
        self::assertSame($expectedResult, $this->propertySchemaRegexRestriction->create($constraint, $propertyMetadata));
×
55
    }
56

57
    public static function createProvider(): \Generator
58
    {
NEW
59
        yield 'anchored' => [new Regex(pattern: '/^[0-9]+$/'), new ApiProperty(), ['pattern' => '^([0-9]+)$']];
×
NEW
60
        yield 'not anchored' => [new Regex(pattern: '/[0-9]/'), new ApiProperty(), ['pattern' => '^(.*[0-9].*)$']];
×
NEW
61
        yield 'inverted' => [new Regex(pattern: '/[0-9]/', match: false), new ApiProperty(), ['pattern' => '^(((?![0-9]).)*)$']];
×
62

NEW
63
        yield 'with options' => [new Regex(pattern: '/^[a-z]+$/i'), new ApiProperty(), []];
×
NEW
64
        yield 'with options and manual htmlPattern' => [new Regex(pattern: '/^[a-z]+$/i', htmlPattern: '[a-zA-Z]+'), new ApiProperty(), ['pattern' => '^([a-zA-Z]+)$']];
×
65
    }
66
}
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