1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Code-Insight library. |
4
|
|
|
* For the full copyright and license information, please view |
5
|
|
|
* the LICENSE file that was distributed with this source code. |
6
|
|
|
* |
7
|
|
|
* @copyright Alexander Obuhovich <[email protected]> |
8
|
|
|
* @link https://github.com/console-helpers/code-insight |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace ConsoleHelpers\CodeInsight\Command; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
17
|
|
|
use Symfony\Component\Finder\Finder; |
18
|
|
|
|
19
|
|
|
class MissingTestsCommand extends AbstractCommand |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* {@inheritdoc} |
24
|
|
|
*/ |
25
|
|
|
protected function configure() |
26
|
|
|
{ |
27
|
|
|
$this |
28
|
|
|
->setName('missing-tests') |
29
|
|
|
->setDescription('Shows classes without tests') |
30
|
|
|
->addArgument( |
31
|
|
|
'src-path', |
32
|
|
|
InputArgument::OPTIONAL, |
33
|
|
|
'Path to folder with source code', |
34
|
|
|
'src' |
35
|
|
|
) |
36
|
|
|
->addArgument( |
37
|
|
|
'tests-path', |
38
|
|
|
InputArgument::OPTIONAL, |
39
|
|
|
'Path to folder with tests', |
40
|
|
|
'tests' |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
48
|
|
|
{ |
49
|
|
|
$src_path = $this->getPath('src-path'); |
50
|
|
|
$tests_path = $this->getPath('tests-path'); |
51
|
|
|
|
52
|
|
|
$finder = new Finder(); |
53
|
|
|
$finder->files()->name('*.php')->notName('/^(I[A-Z]|Abstract[A-Z])/')->in($src_path); |
54
|
|
|
|
55
|
|
|
$missing_tests = array(); |
56
|
|
|
$src_path_parent_path = dirname($src_path) . '/'; |
57
|
|
|
|
58
|
|
|
foreach ( $finder as $source_file ) { |
59
|
|
|
$source_file_path = $source_file->getPathname(); |
60
|
|
|
$test_file_path = preg_replace( |
61
|
|
|
'/^' . preg_quote($src_path, '/') . '(.*)\.php$/', |
62
|
|
|
$tests_path . '$1Test.php', |
63
|
|
|
$source_file_path |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
if ( !file_exists($test_file_path) ) { |
67
|
|
|
$missing_tests[] = str_replace($src_path_parent_path, '', $source_file_path); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
if ( !$missing_tests ) { |
72
|
|
|
$this->io->writeln('<info>Tests for all source files are found.</info>'); |
73
|
|
|
} |
74
|
|
|
else { |
75
|
|
|
$this->io->writeln('<error>Tests for following source files are missing:</error>'); |
76
|
|
|
|
77
|
|
|
foreach ( $missing_tests as $missing_test ) { |
78
|
|
|
$this->io->writeln(' * ' . $missing_test); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
} |
84
|
|
|
|