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

api-platform / core / 3711198772

pending completion
3711198772

push

github

GitHub
fix(jsonschema): remove @id @type @context from input schema  (#5267)

2 of 2 new or added lines in 1 file covered. (100.0%)

7447 of 12203 relevant lines covered (61.03%)

82.13 hits per line

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

44.0
/src/Symfony/Bundle/Test/Constraint/ArraySubsetTrait.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\Bundle\Test\Constraint;
15

16
use SebastianBergmann\Comparator\ComparisonFailure;
17

18
/**
19
 * Constraint that asserts that the array it is evaluated for has a specified subset.
20
 *
21
 * Uses array_replace_recursive() to check if a key value subset is part of the
22
 * subject array.
23
 *
24
 * Imported from dms/phpunit-arraysubset-asserts, because the original constraint has been deprecated.
25
 *
26
 * @copyright Sebastian Bergmann <sebastian@phpunit.de>
27
 * @copyright Rafael Dohms <rdohms@gmail.com>
28
 *
29
 * @see https://github.com/sebastianbergmann/phpunit/issues/3494
30
 */
31
trait ArraySubsetTrait
32
{
33
    public function __construct(private iterable $subset, private readonly bool $strict = false)
34
    {
35
    }
23✔
36

37
    private function _evaluate($other, string $description = '', bool $returnResult = false): ?bool
38
    {
39
        // type cast $other & $this->subset as an array to allow
40
        // support in standard array functions.
41
        $other = $this->toArray($other);
23✔
42
        $this->subset = $this->toArray($this->subset);
23✔
43
        $patched = array_replace_recursive($other, $this->subset);
23✔
44
        if ($this->strict) {
23✔
45
            $result = $other === $patched;
×
46
        } else {
47
            $result = $other == $patched;
23✔
48
        }
49
        if ($returnResult) {
23✔
50
            return $result;
×
51
        }
52
        if ($result) {
23✔
53
            return null;
23✔
54
        }
55

56
        $f = new ComparisonFailure(
×
57
            $patched,
×
58
            $other,
×
59
            var_export($patched, true),
×
60
            var_export($other, true)
×
61
        );
×
62
        $this->fail($other, $description, $f);
×
63
    }
64

65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function toString(): string
69
    {
70
        return 'has the subset '.$this->exporter()->export($this->subset);
×
71
    }
72

73
    /**
74
     * {@inheritdoc}
75
     */
76
    protected function failureDescription($other): string
77
    {
78
        return 'an array '.$this->toString();
×
79
    }
80

81
    private function toArray(iterable $other): array
82
    {
83
        if (\is_array($other)) {
23✔
84
            return $other;
23✔
85
        }
86
        if ($other instanceof \ArrayObject) {
×
87
            return $other->getArrayCopy();
×
88
        }
89

90
        return iterator_to_array($other);
×
91
    }
92
}
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