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

api-platform / core / 7142557150

08 Dec 2023 02:28PM UTC coverage: 36.003% (-1.4%) from 37.36%
7142557150

push

github

web-flow
fix(jsonld): remove link to ApiDocumentation when doc is disabled (#6029)

0 of 1 new or added line in 1 file covered. (0.0%)

2297 existing lines in 182 files now uncovered.

9992 of 27753 relevant lines covered (36.0%)

147.09 hits per line

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

48.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
    }
75✔
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);
75✔
42
        $this->subset = $this->toArray($this->subset);
75✔
43
        $patched = array_replace_recursive($other, $this->subset);
75✔
44
        if ($this->strict) {
75✔
UNCOV
45
            $result = $other === $patched;
×
46
        } else {
47
            $result = $other == $patched;
75✔
48
        }
49
        if ($returnResult) {
75✔
UNCOV
50
            return $result;
×
51
        }
52
        if ($result) {
75✔
53
            return null;
75✔
54
        }
55

UNCOV
56
        $f = new ComparisonFailure(
×
UNCOV
57
            $patched,
×
UNCOV
58
            $other,
×
UNCOV
59
            var_export($patched, true),
×
UNCOV
60
            var_export($other, true)
×
UNCOV
61
        );
×
UNCOV
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);
75✔
71
    }
72

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

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

UNCOV
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