Skip to content

Commit 8f14e1e

Browse files
author
Tasha Harrison
committed
Case 27689; Added two new commands for site:update and site:test:exec
1 parent ffc754f commit 8f14e1e

File tree

4 files changed

+206
-66
lines changed

4 files changed

+206
-66
lines changed

chain/chain-site-build-vm.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/Command/SiteSetupCommand.php

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Contains \DennisDigital\Drupal\Console\Command\SiteGruntCommand.
6+
*
7+
* Runs Grunt.
8+
*/
9+
10+
namespace DennisDigital\Drupal\Console\Command;
11+
12+
use Symfony\Component\Console\Input\InputArgument;
13+
use Symfony\Component\Console\Input\InputInterface;
14+
use Symfony\Component\Console\Output\OutputInterface;
15+
use DennisDigital\Drupal\Console\Exception\SiteCommandException;
16+
17+
/**
18+
* Class SiteTestCommand
19+
*
20+
* @package DennisDigital\Drupal\Console\Command
21+
*/
22+
class SiteTestExecCommand extends SiteBaseCommand {
23+
24+
/**
25+
* Stores the behat tags.
26+
*
27+
* @var string
28+
*/
29+
protected $behatTags = NULL;
30+
31+
/**
32+
* {@inheritdoc}
33+
*/
34+
protected function configure() {
35+
parent::configure();
36+
37+
$this->setName('site:test:exec')
38+
->setDescription('Runs Tests.');
39+
40+
$this->addArgument(
41+
'tags',
42+
InputArgument::REQUIRED,
43+
'Choose your tags'
44+
);
45+
46+
}
47+
48+
/**
49+
* {@inheritdoc}
50+
*/
51+
protected function interact(InputInterface $input, OutputInterface $output) {
52+
parent::interact($input, $output);
53+
54+
$behatTags = $input->getArgument('tags');
55+
56+
if (!$behatTags) {
57+
$tagoptions = array_values(array_unique(array_merge(
58+
['-n'],
59+
['--tags=smoke']
60+
)));
61+
62+
$behatTags = $this->io->choice(
63+
$this->trans('Select your tags'),
64+
$tagoptions,
65+
reset($tagoptions),
66+
TRUE
67+
);
68+
$input->setArgument('tags', reset($behatTags));
69+
}
70+
}
71+
72+
/**
73+
* {@inheritdoc}
74+
*/
75+
protected function execute(InputInterface $input, OutputInterface $output) {
76+
parent::execute($input, $output);
77+
78+
// Validate url.
79+
$this->_validateTags($input);
80+
81+
$this->io->comment(sprintf('Running Tests on %s',
82+
$this->destination
83+
));
84+
85+
$command = sprintf(
86+
'cd %stests && ' .
87+
'./behat %s && ' .
88+
'cd %s; ./vendor/bin/phpunit;',
89+
$this->shellPath($this->destination),
90+
$this->behatTags,
91+
$this->shellPath($this->destination)
92+
);
93+
94+
// Run.
95+
$shellProcess = $this->getShellProcess();
96+
97+
if ($shellProcess->exec($command, TRUE)) {
98+
$this->io->writeln($shellProcess->getOutput());
99+
$this->io->success('Tests Complete');
100+
}
101+
else {
102+
throw new SiteCommandException($shellProcess->getOutput());
103+
}
104+
}
105+
106+
/**
107+
* Helper to validate repo.
108+
*
109+
* @throws SiteCommandException
110+
*
111+
* @return string Behat tag(s)
112+
*/
113+
protected function _validateTags(InputInterface $input) {
114+
115+
$behatTags = $input->getArgument('tags');
116+
117+
if(!$behatTags) {
118+
119+
if ($input->hasArgument('tags') &&
120+
!is_null($input->getArgument('tags'))
121+
) {
122+
$this->behatTags = $input->getArgument('tags');
123+
}
124+
else {
125+
$this->behatTags = '-n';
126+
}
127+
}
128+
129+
$input->setArgument('tags', $behatTags);
130+
$this->behatTags = $behatTags;
131+
132+
return $this->behatTags;
133+
}
134+
}
135+

src/Command/SiteUpdateCommand.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Contains \DennisDigital\Drupal\Console\Command\SiteGruntCommand.
6+
*
7+
* Runs Grunt.
8+
*/
9+
10+
namespace DennisDigital\Drupal\Console\Command;
11+
12+
use Symfony\Component\Console\Input\InputInterface;
13+
use Symfony\Component\Console\Output\OutputInterface;
14+
use DennisDigital\Drupal\Console\Exception\SiteCommandException;
15+
16+
/**
17+
* Class SiteTestCommand
18+
*
19+
* @package DennisDigital\Drupal\Console\Command
20+
*/
21+
class SiteUpdateCommand extends SiteBaseCommand {
22+
23+
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
protected function configure() {
28+
parent::configure();
29+
30+
$this->setName('site:update')
31+
->setDescription('Update.');
32+
33+
}
34+
35+
protected function interact(InputInterface $input, OutputInterface $output) {
36+
parent::interact($input, $output);
37+
38+
}
39+
40+
/**
41+
* {@inheritdoc}
42+
*/
43+
protected function execute(InputInterface $input, OutputInterface $output) {
44+
parent::execute($input, $output);
45+
46+
47+
$this->io->comment(sprintf('Running Update on %s',
48+
$this->destination
49+
));
50+
51+
$command = sprintf(
52+
'cd %sweb; drush site-set @site; drush sset system.maintenance_mode 1;
53+
drush cr; drush updb -y; drush sset system.maintenance_mode 0;
54+
drush cr;',
55+
$this->shellPath($this->destination)
56+
);
57+
58+
// Run.
59+
$shellProcess = $this->getShellProcess();
60+
61+
if ($shellProcess->exec($command, TRUE)) {
62+
$this->io->writeln($shellProcess->getOutput());
63+
$this->io->success('Update Complete');
64+
}
65+
else {
66+
throw new SiteCommandException($shellProcess->getOutput());
67+
}
68+
}
69+
70+
}
71+

0 commit comments

Comments
 (0)