Completed
Pull Request — master (#22)
by Daryl
01:32
created

RoboFile::setTestConfig()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.2
c 0
b 0
f 0
cc 2
eloc 15
nc 2
nop 0
1
<?php
2
/**
3
 * This is project's console commands configuration for Robo task runner.
4
 *
5
 * @see http://robo.li/
6
 */
7
class RoboFile extends \Robo\Tasks
8
{
9
    // define public methods as commands
10
11
	function hello($opts = ['who' => 'unknown'])
12
	{
13
		print_r($opts);
14
		$this->say("Hello, " . $opts['who']);
15
	}
16
17
	function scripts() {
18
19
		$this->taskMinify('assets/maps.js')
20
			->to('dist/scripts/maps.min.js')
21
			->run();
22
23
	}
24
25
	function tests()
26
	{
27
28
		$this->taskExec('mysql -e "CREATE DATABASE IF NOT EXISTS test_db"')->run();
29
		$this->taskExec('mysql -e "GRANT ALL ON test_db.* to \'root\'@\'%\'"')->run();
30
		$this->taskSvnStack()
31
			->checkout('https://develop.svn.wordpress.org/tags/4.8.3 wp-tests')
32
			->run();
33
34
		$this->setTestConfig();
35
		$this->phpunit();
36
37
	}
38
39
	function phpunit()
40
	{
41
		$this->taskPhpUnit('vendor/bin/phpunit')
42
			->configFile('tests/phpunit.xml.dist')
43
			->envVars(array('WP_TESTS_DIR' => 'wp-tests'))
44
			->run();
45
	}
46
47
	private function setTestConfig()
48
	{
49
50
		if (file_exists('wp-tests/wp-tests-config-sample.php')) {
51
			copy('wp-tests/wp-tests-config-sample.php', 'wp-tests/wp-tests-config.php');
52
		}
53
54
		$this->taskReplaceInFile( 'wp-tests/wp-tests-config.php')
55
			->from('youremptytestdbnamehere')
56
			->to('test_db')
57
			->run();
58
59
		$this->taskReplaceInFile( 'wp-tests/wp-tests-config.php')
60
			->from('yourusernamehere')
61
			->to('root')
62
			->run();
63
64
		$this->taskReplaceInFile( 'wp-tests/wp-tests-config.php')
65
			->from('yourpasswordhere')
66
			->to('')
67
			->run();
68
	}
69
70
}