Completed
Push — master ( e090e4...18d79e )
by Damian
02:26
created

tests/EnvironmentCheckerTest.php (5 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
class EnvironmentCheckerTest extends SapphireTest {
0 ignored issues
show
As per PSR2, the opening brace for this class should be on a new line.
Loading history...
3
4
	public function setUpOnce() {
5
		parent::setUpOnce();
6
7
		Phockito::include_hamcrest();
8
	}
9
10
	public function setUp() {
11
		parent::setUp();
12
13
		Config::nest();
14
	}
15
16
	public function tearDown() {
17
		Config::unnest();
18
19
		parent::tearDown();
20
	}
21
22
	public function testOnlyLogsWithErrors() {
23
		Config::inst()->update('EnvironmentChecker', 'log_results_warning', true);
24
		Config::inst()->update('EnvironmentChecker', 'log_results_error', true);
25
		EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckNoErrors());
26
		$checker = Phockito::spy(
27
			'EnvironmentChecker', 
28
			'test suite',
29
			'test'
30
		);
31
32
		$response = $checker->index();
33
		Phockito::verify($checker, 0)->log(anything(), anything());
34
		EnvironmentCheckSuite::reset();
35
	}
36
37 View Code Duplication
	public function testLogsWithWarnings() {
38
		Config::inst()->update('EnvironmentChecker', 'log_results_warning', true);
39
		Config::inst()->update('EnvironmentChecker', 'log_results_error', false);
40
		EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckWarnings());
41
		EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckErrors());
42
		$checker = Phockito::spy(
43
			'EnvironmentChecker',
44
			'test suite',
45
			'test'
46
		);
47
48
		$response = $checker->index();
49
		Phockito::verify($checker, 1)->log(containsString('warning'), anything());
50
		Phockito::verify($checker, 0)->log(containsString('error'), anything());
51
		EnvironmentCheckSuite::reset();
52
	}
53
54 View Code Duplication
	public function testLogsWithErrors() {
55
		Config::inst()->update('EnvironmentChecker', 'log_results_error', false);
56
		Config::inst()->update('EnvironmentChecker', 'log_results_error', true);
57
		EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckWarnings());
58
		EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckErrors());
59
		$checker = Phockito::spy(
60
			'EnvironmentChecker',
61
			'test suite',
62
			'test'
63
		);
64
65
		$response = $checker->index();
66
		Phockito::verify($checker, 0)->log(containsString('warning'), anything());
67
		Phockito::verify($checker, 1)->log(containsString('error'), anything());
68
		EnvironmentCheckSuite::reset();
69
	}
70
71
}
0 ignored issues
show
According to PSR2, the closing brace of classes should be placed on the next line directly after the body.

Below you find some examples:

// Incorrect placement according to PSR2
class MyClass
{
    public function foo()
    {

    }
    // This blank line is not allowed.

}

// Correct
class MyClass
{
    public function foo()
    {

    } // No blank lines after this line.
}
Loading history...
72
73
class EnvironmentCheckerTest_CheckNoErrors implements EnvironmentCheck, TestOnly{
0 ignored issues
show
As per PSR2, the opening brace for this class should be on a new line.
Loading history...
74
	public function check() {
75
		return array(EnvironmentCheck::OK, '');
76
	}
77
}
78
79
class EnvironmentCheckerTest_CheckWarnings implements EnvironmentCheck, TestOnly{
0 ignored issues
show
As per PSR2, the opening brace for this class should be on a new line.
Loading history...
80
	public function check() {
81
		return array(EnvironmentCheck::WARNING, "test warning");
82
	}
83
}
84
85
class EnvironmentCheckerTest_CheckErrors implements EnvironmentCheck, TestOnly{
0 ignored issues
show
As per PSR2, the opening brace for this class should be on a new line.
Loading history...
86
	public function check() {
87
		return array(EnvironmentCheck::ERROR, "test error");
88
	}
89
}