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

api-platform / core / 15063570239

16 May 2025 07:56AM UTC coverage: 27.494% (-0.001%) from 27.495%
15063570239

push

github

web-flow
fix: error formats (#7148)

0 of 2 new or added lines in 2 files covered. (0.0%)

11139 existing lines in 371 files now uncovered.

13476 of 49015 relevant lines covered (27.49%)

74.77 hits per line

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

100.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
use SebastianBergmann\Exporter\Exporter;
18

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

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

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

66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function toString(): string
70
    {
UNCOV
71
        return 'has the subset '.(new Exporter())->export($this->subset);
4✔
72
    }
73

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

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

UNCOV
91
        return iterator_to_array($other);
2✔
92
    }
93
}
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