Passed
Push — master ( 357712...2daa70 )
by Tim
01:54
created

TestSuiteInstance::invokeTest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SimpleSAML\Module\monitor\Test;
4
5
use \SimpleSAML\Module\monitor\State as State;
6
use \SimpleSAML\Module\monitor\TestData as TestData;
7
use \SimpleSAML\Module\monitor\TestResult as TestResult;
8
use \SimpleSAML\Module\monitor\TestConfiguration as TestConfiguration;
9
use \SimpleSAML\Module\monitor\TestSuiteFactory as TestSuiteFactory;
10
11
/**
12
 * Tests for TestSuiteFactory
13
 */
14
class TestSuiteFactoryTest extends \PHPUnit_Framework_TestCase
15
{
16
    public function testTestSuiteFactory()
17
    {
18
        $config = new TestConfiguration(
19
            [],
0 ignored issues
show
Bug introduced by
array() of type array is incompatible with the type SimpleSAML\Module\monitor\DependencyInjection expected by parameter $serverVars of SimpleSAML\Module\monito...guration::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

19
            /** @scrutinizer ignore-type */ [],
Loading history...
20
            [],
0 ignored issues
show
Bug introduced by
array() of type array is incompatible with the type SimpleSAML\Module\monitor\DependencyInjection expected by parameter $requestVars of SimpleSAML\Module\monito...guration::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

20
            /** @scrutinizer ignore-type */ [],
Loading history...
21
            \SimpleSAML_Configuration::loadFromArray(['metadata.sources' => []]),
22
            \SimpleSAML_Configuration::loadFromArray([]),
23
            \SimpleSAML_Configuration::loadFromArray([])
24
        );
25
        $testData = new TestData([]);
26
        $testSuite = new TestSuiteInstance($config, $testData);
27
        $results = $testSuite->prepareTests();
28
29
        $this->assertEquals($config, $testSuite->getConfiguration());
30
        $this->assertEquals($results, $testSuite->getTestResults());
31
        $this->assertEquals([
32
            ['state' => State::NOSTATE, 'category' => 'a', 'subject' => 'b', 'message' => ''],
33
            ['state' => State::NOSTATE, 'category' => 'c', 'subject' => 'd', 'message' => ''],
34
            ['state' => State::NOSTATE, 'category' => 'e', 'subject' => 'f', 'message' => ''],
35
        ], $testSuite->getArrayizeTestResults());
36
37
        $this->assertEquals('travis', $testSuite->getCategory());
38
        $this->assertEquals('travis', $testSuite->getSubject());
39
40
        $this->assertEquals(State::NOSTATE, $testSuite->calculateState());
41
        $testSuite->resetTestResults();
42
        $this->assertEquals(State::NOSTATE, $testSuite->calculateState());
43
    }
44
}
45
46
class TestSuiteInstance extends TestSuiteFactory
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
47
{
48
    public function resetTestResults()
49
    {
50
        $this->testResults = [];
0 ignored issues
show
Bug introduced by
The property testResults is declared private in SimpleSAML\Module\monitor\TestSuiteFactory and cannot be accessed from this context.
Loading history...
51
    }
52
53
    public function prepareTests()
54
    {
55
        $a = new TestResult('a', 'b');
56
        $b = new TestResult('c', 'd');
57
        $c = new TestResult('e', 'f');
58
59
        $this->addTestResults([$a, $b]);
60
        $this->addTestResult($c);
61
62
        return [$a, $b, $c];
63
    }
64
65
    public function invokeTest()
66
    {
67
        $this->setCategory('travis');
68
        $this->setSubject('travis');
69
    }
70
}
71