-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathFeatureContext.php
More file actions
45 lines (37 loc) · 1.42 KB
/
FeatureContext.php
File metadata and controls
45 lines (37 loc) · 1.42 KB
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
<?php
namespace WP_CLI_Valet\Tests\Context;
use Exception;
use WP_CLI\Process;
class FeatureContext extends \WP_CLI\Tests\Context\FeatureContext
{
/**
* @Given /^a random string as \{(\w+)\}$/
*/
public function aRandomStringAs($name)
{
$this->variables[$name] = substr(uniqid('v'), 0, 8); // ensure the string starts with a letter
}
/**
* @Given /^a random project name as \{(\w+)\}$/
*/
public function aRandomProjectNameAs($name)
{
$this->variables[$name] = uniqid('valet-test-');
}
/**
* @Then /^the ([^\s]+) database should( not)? exist$/
*/
public function theGivenDatabaseShouldNotExist($database_name, $should_not_exist = false) {
$mysql_binary = $this->variables['MYSQL_BINARY'];
$database_name = $this->replace_variables($database_name);
$process = Process::create("$mysql_binary -e 'SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = \"$database_name\";' -uroot")
->run();
$exists = strlen(trim($process->stdout)) > 0;
$should_exist = ! $should_not_exist;
if ($exists && $should_not_exist) {
throw new Exception("Failed to assert that no database exists with the name '$database_name'");
} elseif (! $exists && $should_exist) {
throw new Exception("Failed to assert that a database exists with the name '$database_name'");
}
}
}