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

leeqvip / php-apollo / 21220519821

21 Jan 2026 06:06PM UTC coverage: 52.632%. First build
21220519821

push

github

leeqvip
feat: first commit

110 of 209 new or added lines in 9 files covered. (52.63%)

110 of 209 relevant lines covered (52.63%)

6.2 hits per line

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

61.54
/src/Traits/FakeClient.php
1
<?php
2

3
namespace Leeqvip\Apollo\Traits;
4

5
use Psr\Http\Message\ResponseInterface;
6

7
trait FakeClient
8
{
9
    protected static array $fakes = [];
10

11
    public static function fake(string $url, array $options, ResponseInterface $response): void
12
    {
13
        self::$fakes = [
18✔
14
            $url => $response,
18✔
15
        ];
18✔
16
    }
17

18
    public static function fakeGet(string $url, array $options = []): ?ResponseInterface
19
    {
20
        if (empty(self::$fakes)) {
18✔
NEW
21
            return null;
×
22
        }
23

24
        foreach (self::$fakes as $fakeUrl => $response) {
18✔
25
            if (!self::is(self::start($fakeUrl, '*'), $url)) {
18✔
NEW
26
                continue;
×
27
            }
28
            return $response;
18✔
29
        }
30

NEW
31
        return null;
×
32
    }
33

34
    protected static function start($value, $prefix): string
35
    {
36
        $quoted = preg_quote($prefix, '/');
18✔
37

38
        return $prefix . preg_replace('/^(?:' . $quoted . ')+/u', '', $value);
18✔
39
    }
40

41
    protected static function is($pattern, $value, $ignoreCase = false): bool
42
    {
43
        $value = (string)$value;
18✔
44

45
        if (!is_iterable($pattern)) {
18✔
46
            $pattern = [$pattern];
18✔
47
        }
48

49
        foreach ($pattern as $pattern) {
18✔
50
            $pattern = (string)$pattern;
18✔
51

52
            // If the given value is an exact match we can of course return true right
53
            // from the beginning. Otherwise, we will translate asterisks and do an
54
            // actual pattern match against the two strings to see if they match.
55
            if ($pattern === '*' || $pattern === $value) {
18✔
56
                return true;
18✔
57
            }
58

NEW
59
            if ($ignoreCase && mb_strtolower($pattern) === mb_strtolower($value)) {
×
NEW
60
                return true;
×
61
            }
62

NEW
63
            $pattern = preg_quote($pattern, '#');
×
64

65
            // Asterisks are translated into zero-or-more regular expression wildcards
66
            // to make it convenient to check if the strings starts with the given
67
            // pattern such as "library/*", making any string check convenient.
NEW
68
            $pattern = str_replace('\*', '.*', $pattern);
×
69

NEW
70
            if (preg_match('#^' . $pattern . '\z#' . ($ignoreCase ? 'isu' : 'su'), $value) === 1) {
×
NEW
71
                return true;
×
72
            }
73
        }
74

NEW
75
        return false;
×
76
    }
77
}
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