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

api-platform / core / 7047458607

30 Nov 2023 01:53PM UTC coverage: 37.263% (+0.002%) from 37.261%
7047458607

push

github

soyuka
Merge 3.2

20 of 35 new or added lines in 12 files covered. (57.14%)

10 existing lines in 3 files now uncovered.

10295 of 27628 relevant lines covered (37.26%)

21.04 hits per line

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

0.0
/src/Metadata/Tests/Property/PropertyInfoPropertyNameCollectionFactoryTest.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\Metadata\Tests\Property;
15

16
use ApiPlatform\Metadata\Property\Factory\PropertyInfoPropertyNameCollectionFactory;
17
use ApiPlatform\Metadata\Tests\Fixtures\ApiResource\DummyIgnoreProperty;
18
use ApiPlatform\Metadata\Tests\Fixtures\ApiResource\DummyObjectWithOnlyPrivateProperty;
19
use ApiPlatform\Metadata\Tests\Fixtures\ApiResource\DummyObjectWithOnlyPublicProperty;
20
use ApiPlatform\Metadata\Tests\Fixtures\ApiResource\DummyObjectWithoutProperty;
21
use ApiPlatform\Metadata\Tests\Fixtures\ApiResource\DummyObjectWithPublicAndPrivateProperty;
22
use PHPUnit\Framework\TestCase;
23
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
24
use Symfony\Component\PropertyInfo\Extractor\SerializerExtractor;
25
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
26
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
27
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
28

29
/**
30
 * @author Oskar Stark <oskarstark@googlemail.com>
31
 */
32
class PropertyInfoPropertyNameCollectionFactoryTest extends TestCase
33
{
34
    public function testCreateMethodReturnsEmptyPropertyNameCollectionForObjectWithOnlyPrivateProperty(): void
35
    {
36
        $factory = new PropertyInfoPropertyNameCollectionFactory(new PropertyInfoExtractor([
×
37
            new ReflectionExtractor(),
×
38
        ]));
×
39

40
        $collection = $factory->create(DummyObjectWithOnlyPrivateProperty::class);
×
41

42
        self::assertCount(0, $collection->getIterator());
×
43
    }
44

45
    public function testCreateMethodReturnsEmptyPropertyNameCollectionForObjectWithoutProperties(): void
46
    {
47
        $factory = new PropertyInfoPropertyNameCollectionFactory(new PropertyInfoExtractor([
×
48
            new ReflectionExtractor(),
×
49
        ]));
×
50

51
        $collection = $factory->create(DummyObjectWithoutProperty::class);
×
52

53
        self::assertCount(0, $collection->getIterator());
×
54
    }
55

56
    public function testCreateMethodReturnsProperPropertyNameCollectionForObjectWithPublicAndPrivateProperty(): void
57
    {
58
        $factory = new PropertyInfoPropertyNameCollectionFactory(new PropertyInfoExtractor([
×
59
            new ReflectionExtractor(),
×
60
        ]));
×
61

62
        $collection = $factory->create(DummyObjectWithPublicAndPrivateProperty::class);
×
63

64
        self::assertCount(1, $collection->getIterator());
×
65
    }
66

67
    public function testCreateMethodReturnsProperPropertyNameCollectionForObjectWithPublicProperty(): void
68
    {
69
        $factory = new PropertyInfoPropertyNameCollectionFactory(new PropertyInfoExtractor([
×
70
            new ReflectionExtractor(),
×
71
        ]));
×
72

73
        $collection = $factory->create(DummyObjectWithOnlyPublicProperty::class);
×
74

75
        self::assertCount(1, $collection->getIterator());
×
76
    }
77

78
    public function testCreateMethodReturnsProperPropertyNameCollectionForObjectWithIgnoredProperties(): void
79
    {
80
        $factory = new PropertyInfoPropertyNameCollectionFactory(
×
81
            new PropertyInfoExtractor([
×
82
                new SerializerExtractor(
×
83
                    new ClassMetadataFactory(
×
NEW
84
                        new AttributeLoader(
×
85
                        )
×
86
                    )
×
87
                ),
×
88
            ])
×
89
        );
×
90

91
        $this->assertTrue((new \ReflectionObject(new DummyIgnoreProperty()))->hasProperty('ignored'));
×
92

93
        $collection = $factory->create(DummyIgnoreProperty::class, ['serializer_groups' => ['dummy']]);
×
94

95
        self::assertCount(1, $collection);
×
96
        self::assertNotContains('ignored', (array) $collection);
×
97

98
        $collection = $factory->create(DummyIgnoreProperty::class);
×
99

100
        self::assertCount(2, $collection);
×
101
        self::assertNotContains('ignored', (array) $collection);
×
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