blob: 58b0d76f5bc02acdeefb1269ba984ded4ffc43e4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\TestRunner\Runner;
use \Net_SSH2;
class Remote
{
/**
* @var \Net_SSH2
*/
private $ssh;
public function __construct(Net_SSH2 $ssh)
{
$this->ssh = $ssh;
}
public function updatePiwik($gitHash)
{
$this->ssh->exec('git reset --hard');
$this->ssh->exec('git submodule update --init');
$this->ssh->exec('git submodule foreach --recursive git reset --hard');
$this->ssh->exec('git clean -d -f');
$this->ssh->exec('git submodule foreach git clean -f');
$this->ssh->exec('git fetch --all');
$this->ssh->exec('git checkout ' . trim($gitHash));
$this->ssh->exec('git submodule update --init');
$this->ssh->exec('git submodule update --recursive --force');
$this->ssh->exec('sudo composer.phar self-update');
$this->ssh->exec('composer.phar install');
}
public function replaceConfigIni($file)
{
$content = file_get_contents($file);
if (!empty($content)) {
$content = escapeshellarg($content);
$this->ssh->exec('echo ' . $content . ' > config/config.ini.php');
}
}
public function applyPatch($fileToApply)
{
$content = file_get_contents($fileToApply);
if (!empty($content)) {
$content = escapeshellarg($content);
$this->ssh->exec('echo ' . $content . ' | git apply - ');
}
}
public function runTests($host, $testSuite, array $arguments)
{
$this->prepareTestRun($host);
$this->printVersionInfo();
$this->doRunTests($testSuite, $arguments);
}
private function prepareTestRun($host)
{
$this->ssh->exec("sed -i 's/amazonAwsUrl/$host/g' ./config/config.ini.php");
}
private function printVersionInfo()
{
$this->ssh->exec('php --version');
$this->ssh->exec('mysql --version');
$this->ssh->exec('phantomjs --version');
}
private function doRunTests($testSuite, array $arguments)
{
$arguments = implode(' ', $arguments);
$this->ssh->exec("ps -ef | grep \"php console tests:run\" | grep -v grep | awk '{print $2}' | xargs kill -9");
if ('all' === $testSuite) {
$this->ssh->exec('php console tests:run --options="--colors" ' . $arguments);
} elseif ('ui' === $testSuite) {
$this->ssh->exec('php console tests:run-ui --persist-fixture-data --assume-artifacts ' . $arguments);
} else {
$this->ssh->exec('php console tests:run --options="--colors" --testsuite="unit" ' . $arguments);
$this->ssh->exec('php console tests:run --options="--colors" --testsuite="' . $testSuite . '" ' . $arguments);
}
if ('system' === $testSuite) {
$this->ssh->exec("tar -cjf tests/PHPUnit/System/processed/processed.tar.bz2 tests/PHPUnit/System/processed/ plugins/*/tests/System/processed/ --exclude='.gitkeep' --exclude='tests/PHPUnit/System/processed/processed.tar.bz2'");
}
}
}
|