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

JBZoo / Codestyle / 18063683129

27 Sep 2025 06:57PM UTC coverage: 80.896% (-6.8%) from 87.66%
18063683129

push

github

web-flow
test(ci): Update PHP versions and fix workflow tests (#54)

- Update PHP versions in CI workflows from 8.1-8.3 to 8.2-8.4.
- Remove the unnecessary scheduled CI job.
- Adjust `TraitGithubActions` to validate the updated workflow
configuration.
- Fix badge line formatting in `TraitReadme` test.

4 of 4 new or added lines in 2 files covered. (100.0%)

79 existing lines in 7 files now uncovered.

542 of 670 relevant lines covered (80.9%)

10.91 hits per line

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

91.54
/src/PHPUnit/TraitGithubActions.php
1
<?php
2

3
/**
4
 * JBZoo Toolbox - Codestyle.
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/Codestyle
13
 */
14

15
declare(strict_types=1);
16

17
namespace JBZoo\Codestyle\PHPUnit;
18

19
use function JBZoo\Data\yml;
20
use function JBZoo\PHPUnit\isSame;
21

22
trait TraitGithubActions
23
{
24
    public static function testGithubActionsWorkflow(): void
25
    {
26
        $mailYmlPath = PROJECT_ROOT . '/.github/workflows/main.yml';
6✔
27
        $actual      = yml($mailYmlPath)->getArrayCopy();
6✔
28

29
        isSame(120, $actual['env']['COLUMNS']);
6✔
30
        isSame('Hyper', $actual['env']['TERM_PROGRAM']);
6✔
31
        unset($actual['env']);
6✔
32

33
        // General Parameters
34
        $expectedOs = 'ubuntu-latest';
6✔
35

36
        // Expected
37
        $expected = [
6✔
38
            'name' => 'CI',
6✔
39
            'on'   => [
6✔
40
                'pull_request' => ['branches' => ['*']],
6✔
41
                'push'         => ['branches' => ['master']],
6✔
42
            ],
6✔
43

44
            'jobs' => [
6✔
45
                'phpunit' => [
6✔
46
                    'name'     => 'PHPUnit',
6✔
47
                    'runs-on'  => $expectedOs,
6✔
48
                    'env'      => ['JBZOO_COMPOSER_UPDATE_FLAGS' => '${{ matrix.composer_flags }}'],
6✔
49
                    'strategy' => [
6✔
50
                        'matrix' => [
6✔
51
                            'php-version'    => static::phpVersions(),
6✔
52
                            'coverage'       => ['xdebug', 'none'],
6✔
53
                            'composer_flags' => ['--prefer-lowest', ''],
6✔
54
                        ],
6✔
55
                    ],
6✔
56
                    'steps' => [
6✔
57
                        static::checkoutStep('phpunit'),
6✔
58
                        static::setupPhpStep('phpunit'),
6✔
59
                        static::buildStep('phpunit'),
6✔
60
                        static::stepBeforeTests(),
6✔
61
                        [
6✔
62
                            'name' => '๐Ÿงช PHPUnit Tests',
6✔
63
                            'run'  => 'make test --no-print-directory',
6✔
64
                        ],
6✔
65
                        static::stepAfterTests(),
6✔
66
                        [
6✔
67
                            'name'              => 'Uploading coverage to coveralls',
6✔
68
                            'if'                => '${{ matrix.coverage == \'xdebug\' }}',
6✔
69
                            'continue-on-error' => true,
6✔
70
                            'env'               => ['COVERALLS_REPO_TOKEN' => '${{ secrets.GITHUB_TOKEN }}'],
6✔
71
                            'run'               => 'make report-coveralls --no-print-directory || true',
6✔
72
                        ],
6✔
73
                        static::uploadArtifactsStep('PHPUnit - ${{ matrix.php-version }} - ${{ matrix.coverage }}'),
6✔
74
                    ],
6✔
75
                ],
6✔
76
                'linters' => [
6✔
77
                    'name'     => 'Linters',
6✔
78
                    'runs-on'  => $expectedOs,
6✔
79
                    'strategy' => ['matrix' => ['php-version' => static::phpVersions()]],
6✔
80
                    'steps'    => [
6✔
81
                        static::checkoutStep('linters'),
6✔
82
                        static::setupPhpStep('linters'),
6✔
83
                        static::buildStep('linters'),
6✔
84
                        [
6✔
85
                            'name' => '๐Ÿ‘ Code Quality',
6✔
86
                            'run'  => 'make codestyle --no-print-directory',
6✔
87
                        ],
6✔
88
                        static::uploadArtifactsStep('Linters - ${{ matrix.php-version }}'),
6✔
89
                    ],
6✔
90
                ],
6✔
91
                'report' => [
6✔
92
                    'name'     => 'Reports',
6✔
93
                    'runs-on'  => $expectedOs,
6✔
94
                    'strategy' => ['matrix' => ['php-version' => static::phpVersions()]],
6✔
95
                    'steps'    => [
6✔
96
                        static::checkoutStep('report'),
6✔
97
                        static::setupPhpStep('report'),
6✔
98
                        static::buildStep('report'),
6✔
99
                        [
6✔
100
                            'name' => '๐Ÿ“ Build Reports',
6✔
101
                            'run'  => 'make report-all --no-print-directory',
6✔
102
                        ],
6✔
103
                        static::uploadArtifactsStep('Reports - ${{ matrix.php-version }}'),
6✔
104
                    ],
6✔
105
                ],
6✔
106
            ],
6✔
107
        ];
6✔
108

109
        $expectedYaml = self::toYaml($expected);
6✔
110
        $actualYaml   = self::toYaml($actual);
6✔
111

112
        if (!\str_contains($actualYaml, $expectedYaml)) {
6✔
113
            isSame(
×
UNCOV
114
                $expectedYaml,
×
UNCOV
115
                $actualYaml,
×
116
                \implode("\n", [
×
UNCOV
117
                    'Expected Yaml file:',
×
118
                    "See: {$mailYmlPath}",
×
UNCOV
119
                    '----------------------------------------',
×
UNCOV
120
                    $expectedYaml,
×
UNCOV
121
                    '----------------------------------------',
×
UNCOV
122
                ]),
×
UNCOV
123
            );
×
124
        }
125
    }
126

127
    protected static function stepBeforeTests(): ?array
128
    {
129
        return null;
6✔
130
    }
131

132
    protected static function stepAfterTests(): ?array
133
    {
134
        return null;
6✔
135
    }
136

137
    /**
138
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
139
     * @phan-suppress PhanUnusedProtectedNoOverrideMethodParameter
140
     * @psalm-suppress PossiblyUnusedParam
141
     */
142
    protected static function checkoutStep(string $jobName): array
143
    {
144
        return [
6✔
145
            'name' => 'Checkout code',
6✔
146
            'uses' => 'actions/checkout@v3',
6✔
147
            'with' => ['fetch-depth' => 0],
6✔
148
        ];
6✔
149
    }
150

151
    protected static function phpVersions(): array
152
    {
153
        return [8.2, 8.3, 8.4];
6✔
154
    }
155

156
    /**
157
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
158
     * @phan-suppress PhanUnusedProtectedNoOverrideMethodParameter
159
     * @psalm-suppress PossiblyUnusedParam
160
     */
161
    protected static function buildStep(string $jobName): array
162
    {
163
        return [
6✔
164
            'name' => 'Build the Project',
6✔
165
            'run'  => 'make update --no-print-directory',
6✔
166
        ];
6✔
167
    }
168

169
    protected static function setupPhpStep(string $jobName): array
170
    {
171
        $coverage = 'none';
6✔
172
        if ($jobName === 'phpunit') {
6✔
173
            $coverage = '${{ matrix.coverage }}';
6✔
174
        } elseif ($jobName === 'report') {
6✔
175
            $coverage = 'xdebug';
6✔
176
        }
177

178
        return [
6✔
179
            'name' => 'Setup PHP',
6✔
180
            'uses' => 'shivammathur/setup-php@v2',
6✔
181
            'with' => [
6✔
182
                'php-version' => '${{ matrix.php-version }}',
6✔
183
                'coverage'    => $coverage,
6✔
184
                'tools'       => 'composer',
6✔
185
                'extensions'  => 'ast',
6✔
186
            ],
6✔
187
        ];
6✔
188
    }
189

190
    protected static function uploadArtifactsStep(string $stepName): array
191
    {
192
        return [
6✔
193
            'name'              => 'Upload Artifacts',
6✔
194
            'uses'              => 'actions/upload-artifact@v4',
6✔
195
            'continue-on-error' => true,
6✔
196
            'with'              => ['name' => $stepName, 'path' => 'build/'],
6✔
197
        ];
6✔
198
    }
199

200
    private static function normalizeData(array $data): array
201
    {
202
        foreach ($data['jobs'] as $jobName => $job) {
6✔
203
            foreach ($job['steps'] as $stepIndex => $step) {
6✔
204
                if ($step === null) {
6✔
205
                    unset($data['jobs'][$jobName]['steps'][$stepIndex]);
6✔
206
                }
207
            }
208

209
            $data['jobs'][$jobName]['steps'] = \array_values($data['jobs'][$jobName]['steps']);
6✔
210
        }
211

212
        return $data;
6✔
213
    }
214

215
    private static function toYaml(array $data): string
216
    {
217
        return (string)yml(self::normalizeData($data));
6✔
218
    }
219
}
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