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

jomweb / billplz / 22913593562

10 Mar 2026 04:42PM UTC coverage: 80.231% (-17.3%) from 97.537%
22913593562

Pull #59

github

web-flow
Merge 5383f00b4 into 7e55fdd4e
Pull Request #59: Release Billplz 6.0 with Money objects, bundled Codex internals, and updated CI

305 of 439 new or added lines in 24 files covered. (69.48%)

3 existing lines in 2 files now uncovered.

556 of 693 relevant lines covered (80.23%)

25.37 hits per line

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

27.59
/src/Internal/Codex/Testing/ArraySubset.php
1
<?php
2

3
namespace Laravie\Codex\Testing;
4

5
use ArrayObject;
6
use PHPUnit\Framework\Constraint\Constraint;
7
use PHPUnit\Runner\Version;
8
use SebastianBergmann\Comparator\ComparisonFailure;
9
use SebastianBergmann\Exporter\Exporter;
10
use Traversable;
11

12
if (class_exists(Version::class) && version_compare(Version::series(), '9.0', '>=')) {
1✔
13
    /**
14
     * @internal this class is not meant to be used or overwritten outside the framework itself
15
     */
16
    final class ArraySubset extends Constraint
17
    {
18
        /**
19
         * @var iterable
20
         */
21
        private $subset;
22

23
        /**
24
         * @var bool
25
         */
26
        private $strict;
27

28
        /**
29
         * Create a new array subset constraint instance.
30
         *
31
         * @return void
32
         */
33
        public function __construct(iterable $subset, bool $strict = false)
34
        {
35
            $this->strict = $strict;
2✔
36
            $this->subset = $subset;
2✔
37
        }
38

39
        /**
40
         * Evaluates the constraint for parameter $other.
41
         *
42
         * If $returnResult is set to false (the default), an exception is thrown
43
         * in case of a failure. null is returned otherwise.
44
         *
45
         * If $returnResult is true, the result of the evaluation is returned as
46
         * a boolean value instead: true in case of success, false in case of a
47
         * failure.
48
         *
49
         * @param  mixed  $other
50
         *
51
         * @throws \PHPUnit\Framework\ExpectationFailedException
52
         * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
53
         */
54
        public function evaluate($other, string $description = '', bool $returnResult = false): ?bool
55
        {
56
            // type cast $other & $this->subset as an array to allow
57
            // support in standard array functions.
58
            $other = $this->toArray($other);
1✔
59
            $this->subset = $this->toArray($this->subset);
1✔
60

61
            $patched = array_replace_recursive($other, $this->subset);
1✔
62

63
            if ($this->strict) {
1✔
NEW
64
                $result = $other === $patched;
×
65
            } else {
66
                $result = $other == $patched;
1✔
67
            }
68

69
            if ($returnResult) {
1✔
NEW
70
                return $result;
×
71
            }
72

73
            if (! $result) {
1✔
NEW
74
                $f = new ComparisonFailure(
×
NEW
75
                    $patched,
×
NEW
76
                    $other,
×
NEW
77
                    var_export($patched, true),
×
NEW
78
                    var_export($other, true)
×
NEW
79
                );
×
80

NEW
81
                $this->fail($other, $description, $f);
×
82
            }
83

84
            return null;
1✔
85
        }
86

87
        /**
88
         * Returns a string representation of the constraint.
89
         *
90
         *
91
         * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
92
         */
93
        public function toString(): string
94
        {
95
            return 'has the subset '.(new Exporter)->export($this->subset);
1✔
96
        }
97

98
        /**
99
         * Returns the description of the failure.
100
         *
101
         * The beginning of failure messages is "Failed asserting that" in most
102
         * cases. This method should return the second part of that sentence.
103
         *
104
         * @param  mixed  $other
105
         *
106
         * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
107
         */
108
        protected function failureDescription($other): string
109
        {
NEW
110
            return 'an array '.$this->toString();
×
111
        }
112

113
        /**
114
         * Returns the description of the failure.
115
         *
116
         * The beginning of failure messages is "Failed asserting that" in most
117
         * cases. This method should return the second part of that sentence.
118
         */
119
        private function toArray(iterable $other): array
120
        {
121
            if (\is_array($other)) {
1✔
122
                return $other;
1✔
123
            }
124

125
            if ($other instanceof ArrayObject) {
1✔
126
                return $other->getArrayCopy();
1✔
127
            }
128

NEW
129
            if ($other instanceof Traversable) {
×
NEW
130
                return iterator_to_array($other);
×
131
            }
132

133
            // Keep BC even if we know that array would not be the expected one
NEW
134
            return (array) $other;
×
135
        }
136
    }
NEW
137
} elseif (class_exists(Version::class) && version_compare(Version::series(), '8.0', '>=')) {
×
138
    /**
139
     * @internal this class is not meant to be used or overwritten outside the framework itself
140
     */
141
    final class ArraySubset extends Constraint
142
    {
143
        /**
144
         * @var iterable
145
         */
146
        private $subset;
147

148
        /**
149
         * @var bool
150
         */
151
        private $strict;
152

153
        /**
154
         * Create a new array subset constraint instance.
155
         *
156
         * @return void
157
         */
158
        public function __construct(iterable $subset, bool $strict = false)
159
        {
NEW
160
            $this->strict = $strict;
×
NEW
161
            $this->subset = $subset;
×
162
        }
163

164
        /**
165
         * Evaluates the constraint for parameter $other.
166
         *
167
         * If $returnResult is set to false (the default), an exception is thrown
168
         * in case of a failure. null is returned otherwise.
169
         *
170
         * If $returnResult is true, the result of the evaluation is returned as
171
         * a boolean value instead: true in case of success, false in case of a
172
         * failure.
173
         *
174
         * @param  mixed  $other
175
         *
176
         * @throws \PHPUnit\Framework\ExpectationFailedException
177
         * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
178
         */
179
        public function evaluate($other, string $description = '', bool $returnResult = false): ?bool
180
        {
181
            // type cast $other & $this->subset as an array to allow
182
            // support in standard array functions.
NEW
183
            $other = $this->toArray($other);
×
NEW
184
            $this->subset = $this->toArray($this->subset);
×
185

NEW
186
            $patched = array_replace_recursive($other, $this->subset);
×
187

NEW
188
            if ($this->strict) {
×
NEW
189
                $result = $other === $patched;
×
190
            } else {
NEW
191
                $result = $other == $patched;
×
192
            }
193

NEW
194
            if ($returnResult) {
×
NEW
195
                return $result;
×
196
            }
197

NEW
198
            if (! $result) {
×
NEW
199
                $f = new ComparisonFailure(
×
NEW
200
                    $patched,
×
NEW
201
                    $other,
×
NEW
202
                    var_export($patched, true),
×
NEW
203
                    var_export($other, true)
×
NEW
204
                );
×
205

NEW
206
                $this->fail($other, $description, $f);
×
207
            }
208

NEW
209
            return null;
×
210
        }
211

212
        /**
213
         * Returns a string representation of the constraint.
214
         *
215
         *
216
         * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
217
         */
218
        public function toString(): string
219
        {
NEW
220
            return 'has the subset '.(new Exporter)->export($this->subset);
×
221
        }
222

223
        /**
224
         * Returns the description of the failure.
225
         *
226
         * The beginning of failure messages is "Failed asserting that" in most
227
         * cases. This method should return the second part of that sentence.
228
         *
229
         * @param  mixed  $other
230
         *
231
         * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
232
         */
233
        protected function failureDescription($other): string
234
        {
NEW
235
            return 'an array '.$this->toString();
×
236
        }
237

238
        /**
239
         * Returns the description of the failure.
240
         *
241
         * The beginning of failure messages is "Failed asserting that" in most
242
         * cases. This method should return the second part of that sentence.
243
         */
244
        private function toArray(iterable $other): array
245
        {
NEW
246
            if (\is_array($other)) {
×
NEW
247
                return $other;
×
248
            }
249

NEW
250
            if ($other instanceof ArrayObject) {
×
NEW
251
                return $other->getArrayCopy();
×
252
            }
253

NEW
254
            if ($other instanceof Traversable) {
×
NEW
255
                return iterator_to_array($other);
×
256
            }
257

258
            // Keep BC even if we know that array would not be the expected one
NEW
259
            return (array) $other;
×
260
        }
261
    }
262
}
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