GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

TrefoilTestUpdateExpectedResultsCommand   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 140
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 11.59%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 5
dl 0
loc 140
ccs 8
cts 69
cp 0.1159
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 27 1
A interact() 0 11 1
A execute() 0 13 2
B processTestGroup() 0 75 7
1
<?php
2
/*
3
 * This file is part of the trefoil application.
4
 *
5
 * (c) Miguel Angel Gabriel <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Trefoil\Console\Command;
11
12
use Easybook\Console\Command\BaseCommand;
13
use Symfony\Component\Console\Helper\DialogHelper;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
use Symfony\Component\Filesystem\Filesystem;
17
use Symfony\Component\Finder\Finder;
18
use Symfony\Component\Finder\SplFileInfo;
19
20
class TrefoilTestUpdateExpectedResultsCommand extends BaseCommand
21
{
22
    protected $userConfirmed = false;
23
24
    /** @var  OutputInterface */
25
    protected $output;
26
27
    /** @var DialogHelper $dialog */
28
    protected $dialog;
29
30 1
    protected function configure()
31
    {
32 1
        $this->setDefinition(array())
33 1
             ->setName('test:update-expected-results')
34 1
             ->setDescription('Update expected results from debug output');
35
36
        $help = <<<HELP
37
The <info>test:update-expected-results</info> command updates the expected results for tests 
38
that generate a "book" as result. This kind of test can be easily affected when
39
the theme they use is modified by an unrelated code change, needing a tedious 
40
manual refresh of the fixture for each test expected results. 
41
42
Instructions: 
43
44
1. Run the tests in <info>debug</info> mode. This will leave the generated output of each test 
45
   in the <info>app/Cache</info> directory.
46
2. Manually review and check the actual results to ensure tests are failing as a 
47
   collateral effect of some other unrelated change and is OK to update them.
48
3. Run this command and confirm its execution. This will copy each test's actual
49
   results as the new expected results for future runs.
50
51 1
HELP;
52
53 1
        $this->setHelp(
54
            $help
55 1
        );
56 1
    }
57
58
    protected function interact(InputInterface $input, OutputInterface $output)
59
    {
60
        $this->dialog = $this->getHelperSet()->get('dialog');
61
62
        $this->userConfirmed =
63
            $this->dialog->askConfirmation(
64
                $output,
65
                '<question>Are you sure you want to continue?</question> [yN] ',
66
                false
67
            );
68
    }
69
70
    protected function execute(InputInterface $input, OutputInterface $output)
71
    {
72
        $this->output = $output;
73
74
        if (!$this->userConfirmed) {
75
            $output->writeln('Not executed');
76
77
            return;
78
        }
79
80
        $this->processTestGroup('Plugins');
81
        $this->processTestGroup('Functional');
82
    }
83
84
    protected function processTestGroup($group)
85
    {
86
        $cacheDir = $this->tmpDirBase = $this->app['app.dir.cache'] . '/' . 'phpunit_debug/';
87
        $groupTest = $group . 'Test';
88
        $groupTestDir = $cacheDir . $groupTest;
89
        $fixturesDir = $this->app['trefoil.app.dir.base'] . '/src/Trefoil/Tests/' . $group . '/fixtures';
90
91
        $this->output->writeln('');
92
        
93
        $this->output->writeln(
94
            sprintf('Processing Test Group <bg=green;fg=black>%s</>.', $group)
95
        );
96
        
97
        $this->output->writeln('');
98
99
        if (!is_dir($fixturesDir)) {
100
            $this->output->writeln(
101
                sprintf('<error> ERROR </error> No fixtures test directory found "%s".', $fixturesDir)
102
            );
103
104
            return;
105
        }
106
107
        if (!is_dir($groupTestDir)) {
108
            $this->output->writeln(sprintf('<error> ERROR </error> No tests output in %s directory.', $groupTestDir));
109
110
            return;
111
        }
112
113
        /** @var Filesystem $filesystem */
114
        $filesystem = $this->app['filesystem'];
115
116
        /** @var Finder $finder */
117
        $finder = $this->app['finder'];
118
119
        $tests = $finder->directories()
120
                        ->depth(0)
121
                        ->in($groupTestDir);
122
123
        if ($tests->count() === 0) {
124
            $this->output->writeln(sprintf('<error> ERROR </error> No %s Tests output found.', $groupTest));
125
126
            return;
127
        }
128
129
        $this->output->writeln(sprintf('Found the following %s Tests:', $group));
130
131
        /** @var SplFileInfo $test */
132
        foreach ($tests as $test) {
133
            $this->output->writeln('- ' . $test->getBasename());
134
        }
135
136
        if (!$this->dialog->askConfirmation(
137
            $this->output,
138
            sprintf('<question>Update these %s Tests?</question> [yN] ', $group),
139
            false
140
        )
141
        ) {
142
            $this->output->writeln(sprintf('<comment> OK </comment> %s Tests not updated', $group));
143
144
            return;
145
        }
146
147
        /** @var SplFileInfo $test */
148
        foreach ($tests as $test) {
149
            $this->output->writeln('- ' . $test->getBasename());
150
151
            $actualResultsDir = $test->getRealPath() . '/Output';
152
            $expectedResultsDir = $fixturesDir . '/' . $test->getBasename() . '/expected';
153
154
            $filesystem->mirror($actualResultsDir, $expectedResultsDir);
155
        }
156
157
        $this->output->writeln(sprintf('<info> OK </info> %s Tests updated', $group));
158
    }
159
}
160