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

api-platform / core / 10315659289

09 Aug 2024 07:49AM UTC coverage: 7.841% (-0.006%) from 7.847%
10315659289

push

github

soyuka
style: cs fixes

70 of 529 new or added lines in 176 files covered. (13.23%)

160 existing lines in 58 files now uncovered.

12688 of 161818 relevant lines covered (7.84%)

26.86 hits per line

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

0.0
/tests/Symfony/Bundle/Test/Constraint/ArraySubsetTest.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\Tests\Symfony\Bundle\Test\Constraint;
15

16
use ApiPlatform\Symfony\Bundle\Test\Constraint\ArraySubset;
17
use ApiPlatform\Tests\Fixtures\ArrayAccessible;
18
use PHPUnit\Framework\ExpectationFailedException;
19
use PHPUnit\Framework\SelfDescribing;
20
use PHPUnit\Framework\TestCase;
21

22
/**
23
 * Imported from dms/phpunit-arraysubset-asserts, because the original constraint has been deprecated.
24
 *
25
 * @copyright Sebastian Bergmann <sebastian@phpunit.de>
26
 * @copyright Rafael Dohms <rdohms@gmail.com>
27
 *
28
 * @see https://github.com/sebastianbergmann/phpunit/issues/3494
29
 */
30
class ArraySubsetTest extends TestCase
31
{
32
    public static function evaluateDataProvider(): array
33
    {
34
        return [
×
35
            'loose array subset and array other' => [
×
36
                'expected' => true,
×
37
                'subset' => ['bar' => 0],
×
38
                'other' => ['foo' => '', 'bar' => '0'],
×
39
                'strict' => false,
×
40
            ],
×
41
            'strict array subset and array other' => [
×
42
                'expected' => false,
×
43
                'subset' => ['bar' => 0],
×
44
                'other' => ['foo' => '', 'bar' => '0'],
×
45
                'strict' => true,
×
46
            ],
×
47
            'loose array subset and ArrayObject other' => [
×
48
                'expected' => true,
×
49
                'subset' => ['bar' => 0],
×
50
                'other' => new \ArrayObject(['foo' => '', 'bar' => '0']),
×
51
                'strict' => false,
×
52
            ],
×
53
            'strict ArrayObject subset and array other' => [
×
54
                'expected' => true,
×
55
                'subset' => new \ArrayObject(['bar' => 0]),
×
56
                'other' => ['foo' => '', 'bar' => 0],
×
57
                'strict' => true,
×
58
            ],
×
59
        ];
×
60
    }
61

62
    #[\PHPUnit\Framework\Attributes\DataProvider('evaluateDataProvider')]
63
    public function testEvaluate(bool $expected, iterable $subset, iterable $other, bool $strict): void
64
    {
65
        $constraint = new ArraySubset($subset, $strict);
×
66

67
        $this->assertSame($expected, $constraint->evaluate($other, '', true));
×
68
    }
69

70
    public function testEvaluateWithArrayAccess(): void
71
    {
72
        $arrayAccess = new ArrayAccessible(['foo' => 'bar']);
×
73

74
        $constraint = new ArraySubset(['foo' => 'bar']);
×
75

76
        $this->assertTrue($constraint->evaluate($arrayAccess, '', true));
×
77
    }
78

79
    public function testEvaluateFailMessage(): void
80
    {
81
        $constraint = new ArraySubset(['foo' => 'bar']);
×
82

83
        try {
84
            $constraint->evaluate(['baz' => 'bar'], '', false);
×
NEW
85
            $this->fail(\sprintf('Expected %s to be thrown.', ExpectationFailedException::class));
×
86
        } catch (ExpectationFailedException $expectedException) {
×
87
            $comparisonFailure = $expectedException->getComparisonFailure();
×
88
            $this->assertNotNull($comparisonFailure);
×
89
            $this->assertStringContainsString("'foo' => 'bar'", $comparisonFailure->getExpectedAsString());
×
90
            $this->assertStringContainsString("'baz' => 'bar'", $comparisonFailure->getActualAsString());
×
91
        }
92
    }
93

94
    public function testIsCountable(): void
95
    {
96
        $reflection = new \ReflectionClass(ArraySubset::class);
×
97

98
        $this->assertTrue(
×
99
            $reflection->implementsInterface(\Countable::class),
×
NEW
100
            \sprintf(
×
101
                'Failed to assert that ArraySubset implements "%s".',
×
102
                \Countable::class
×
103
            )
×
104
        );
×
105
    }
106

107
    public function testIsSelfDescribing(): void
108
    {
109
        $reflection = new \ReflectionClass(ArraySubset::class);
×
110

111
        $this->assertTrue(
×
112
            $reflection->implementsInterface(SelfDescribing::class),
×
NEW
113
            \sprintf(
×
114
                'Failed to assert that Array implements "%s".',
×
115
                SelfDescribing::class
×
116
            )
×
117
        );
×
118
    }
119
}
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

© 2026 Coveralls, Inc