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

oradwell / covers-validator / 18176432811

01 Oct 2025 09:37PM UTC coverage: 96.377% (-2.0%) from 98.387%
18176432811

push

github

oradwell
Support for PHPUnit 10 (#50)

21 of 25 new or added lines in 5 files covered. (84.0%)

1 existing line in 1 file now uncovered.

133 of 138 relevant lines covered (96.38%)

6.31 hits per line

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

95.52
/src/Command/ValidateCommand.php
1
<?php
2

3
namespace OckCyp\CoversValidator\Command;
4

5
use OckCyp\CoversValidator\Handler\InputHandler;
6
use OckCyp\CoversValidator\Loader\TestSuiteLoader;
7
use OckCyp\CoversValidator\Validator\Validator;
8
use PHPUnit\Framework\TestCase;
9
use PHPUnit\Framework\WarningTestCase;
10
use Symfony\Component\Console\Command\Command;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Input\InputOption;
13
use Symfony\Component\Console\Output\OutputInterface;
14

15
class ValidateCommand extends Command
16
{
17
    /**
18
     * @var bool
19
     */
20
    protected $firstValidityWrite = true;
21

22
    /**
23
     * {@inheritdoc}
24
     */
25
    protected function configure()
26
    {
27
        $this->setName('validate')
11✔
28
            ->addOption(
11✔
29
                'configuration',
11✔
30
                'c',
11✔
31
                InputOption::VALUE_REQUIRED,
11✔
32
                'Read PHPUnit configuration from XML file.'
11✔
33
            )
11✔
34
            ->addUsage('-c app')
11✔
35
            ->addUsage('-c tests/configuration.xml')
11✔
36
            ->addOption(
11✔
37
                'bootstrap',
11✔
38
                null,
11✔
39
                InputOption::VALUE_REQUIRED,
11✔
40
                'A "bootstrap" PHP file that is run before the validation.'
11✔
41
            )
11✔
42
            ->addUsage('--bootstrap=tests/bootstrap.php');
11✔
43
    }
44

45
    /**
46
     * {@inheritdoc}
47
     */
48
    protected function execute(InputInterface $input, OutputInterface $output)
49
    {
50
        $output->writeln($this->getApplication()->getLongVersion());
11✔
51

52
        $configurationHolder = InputHandler::handleInput($input);
11✔
53
        if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
11✔
54
            $output->writeln(PHP_EOL.sprintf(
3✔
55
                'Configuration file loaded: %s',
3✔
56
                $configurationHolder->getFilename()
3✔
57
            ));
3✔
58
        }
59

60
        $testCollection = TestSuiteLoader::loadSuite($configurationHolder);
11✔
61
        if ($testCollection->isEmpty()) {
11✔
62
            $output->writeln(PHP_EOL.'No tests found to validate.');
4✔
63

64
            return 0;
4✔
65
        }
66

67
        $failedCount = 0;
7✔
68
        /** @var TestCase $suite */
69
        foreach ($testCollection as $suite) {
7✔
70
            if ($suite instanceof WarningTestCase) {
7✔
UNCOV
71
                continue;
×
72
            }
73

74
            $testClass = get_class($suite);
7✔
75
            if (method_exists($suite, 'getName')) {
7✔
76
                // PHPUnit < 10
NEW
77
                $testMethod = $suite->getName(false);
×
78
            } elseif (method_exists($suite, 'name')) {
7✔
79
                // PHPUnit >= 10.0
80
                $testMethod = $suite->name();
7✔
81
            } else {
NEW
82
                $testMethod = $suite->toString();
×
83
            }
84
            $testSignature = $testClass.'::'.$testMethod;
7✔
85

86
            if ($output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG) {
7✔
87
                $this->writeValidity($output, 'Validating '.$testSignature.'...');
2✔
88
            }
89

90
            $isValid = Validator::isValidMethod(
7✔
91
                $testClass,
7✔
92
                $testMethod
7✔
93
            );
7✔
94

95
            if (!$isValid) {
7✔
96
                ++$failedCount;
4✔
97
                $this->writeValidity($output, $testSignature, false);
4✔
98
            } elseif ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
4✔
99
                $this->writeValidity($output, $testSignature, true);
2✔
100
            }
101
        }
102

103
        $output->writeln('');
7✔
104

105
        if ($failedCount > 0) {
7✔
106
            $output->writeln(
4✔
107
                "There were {$failedCount} test(s) with invalid @covers tags."
4✔
108
            );
4✔
109

110
            return 1;
4✔
111
        }
112

113
        $output->writeln('Validation complete. All @covers tags are valid.');
3✔
114

115
        return 0;
3✔
116
    }
117

118
    /**
119
     * Write validity message for tests
120
     * The purpose of this method is to write a new line for the first
121
     * validity related message
122
     *
123
     * @param OutputInterface $output
124
     * @param string $message
125
     * @param bool|null $isValid
126
     */
127
    protected function writeValidity($output, $message, $isValid = null)
128
    {
129
        if ($this->firstValidityWrite) {
6✔
130
            $output->writeln('');
6✔
131
            $this->firstValidityWrite = false;
6✔
132
        }
133

134
        if (is_bool($isValid)) {
6✔
135
            $message = sprintf(
6✔
136
                '%s - %s',
6✔
137
                $isValid ? '<fg=green>Valid</>' : '<fg=red>Invalid</>',
6✔
138
                $message
6✔
139
            );
6✔
140
        }
141

142
        $output->writeln($message);
6✔
143
    }
144
}
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