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

JBZoo / PHPUnit / 5522653198

pending completion
5522653198

push

github

web-flow
Release v7 (#28)

170 of 252 relevant lines covered (67.46%)

4.98 hits per line

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

84.62
/src/functions/tools.php
1
<?php
2

3
/**
4
 * JBZoo Toolbox - PHPUnit.
5
 *
6
 * This file is part of the JBZoo Toolbox project.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT
11
 * @copyright  Copyright (C) JBZoo.com, All rights reserved.
12
 * @see        https://github.com/JBZoo/PHPUnit
13
 */
14

15
declare(strict_types=1);
16

17
namespace JBZoo\PHPUnit;
18

19
use JBZoo\HttpClient\HttpClient;
20
use JBZoo\HttpClient\Request;
21
use JBZoo\HttpClient\Response;
22
use JBZoo\Utils\Env;
23

24
/**
25
 * Check is current OS Windows.
26
 */
27
function isWin(): bool
28
{
29
    return \strncasecmp(\PHP_OS_FAMILY, 'WIN', 3) === 0;
4✔
30
}
31

32
function isTeamCity(): bool
33
{
34
    return Env::isExists('TEAMCITY_VERSION');
×
35
}
36

37
function isTravis(): bool
38
{
39
    return Env::isExists('TRAVIS');
×
40
}
41

42
function isPhpStorm(): bool
43
{
44
    return Env::isExists('IDE_PHPUNIT_CUSTOM_LOADER');
×
45
}
46

47
/**
48
 * Read file in binary save mode.
49
 */
50
function openFile(string $path): ?string
51
{
52
    $contents = null;
28✔
53

54
    $realPath = (string)\realpath($path);
28✔
55
    if ($realPath !== '' && \file_exists($realPath)) {
28✔
56
        $fileSize = (int)\filesize($realPath);
28✔
57

58
        if ($fileSize > 0) {
28✔
59
            $handle = \fopen($realPath, 'r');
28✔
60
            if ($handle !== false) {
28✔
61
                $contents = \fread($handle, $fileSize);
28✔
62
                \fclose($handle);
28✔
63
            }
64
        }
65
    }
66

67
    if ($contents === false) {
28✔
68
        $contents = null;
×
69
    }
70

71
    return $contents;
28✔
72
}
73

74
/**
75
 * @param null|array<mixed>|string $args
76
 * @param array<bool|int|string>   $options
77
 * @codeCoverageIgnore
78
 */
79
function httpRequest(
80
    string $url,
81
    array|string|null $args = null,
82
    string $method = Request::GET,
83
    array $options = [],
84
): Response {
85
    if (!\class_exists(HttpClient::class)) {
86
        throw new Exception('jbzoo/http-client is required for httpRequest() function');
87
    }
88

89
    if (\array_key_exists('timeout', $options)) {
90
        $options['timeout'] = 600; // For PHPUnit coverage
91
    }
92

93
    return (new HttpClient($options))->request($url, $args, $method, $options);
94
}
95

96
function getTestName(bool $withNamespace = false): ?string
97
{
98
    $objects = \debug_backtrace();
4✔
99
    $result  = null;
4✔
100

101
    foreach ($objects as $object) {
4✔
102
        if (isset($object['object']) && $object['object'] instanceof PHPUnit) {
4✔
103
            $result = \get_class($object['object']) . '__' . $object['function'];
4✔
104

105
            if (!$withNamespace) {
4✔
106
                $result = \str_replace(__NAMESPACE__ . '\\', '', $result);
4✔
107
            }
108

109
            if (\strpos($result, '__test') > 0) {
4✔
110
                break;
4✔
111
            }
112
        }
113
    }
114

115
    return $result;
4✔
116
}
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