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

api-platform / core / 15133993414

20 May 2025 09:30AM UTC coverage: 26.313% (-1.2%) from 27.493%
15133993414

Pull #7161

github

web-flow
Merge e2c03d45f into 5459ba375
Pull Request #7161: fix(metadata): infer parameter string type from schema

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

11019 existing lines in 363 files now uncovered.

12898 of 49018 relevant lines covered (26.31%)

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

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

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

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

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

UNCOV
91
        return iterator_to_array($other);
1✔
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