testStarterStartsWithPortByExtraArgs()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
namespace BeubiQA\tests\Unit;
4
5
use BeubiQA\Application\Selenium;
6
7
class StarterTest extends \PHPUnit_Framework_TestCase
8
{
9
    /** @var Selenium\SeleniumStarter */
10
    protected $starter;
11
12
    public function setup()
13
    {
14
        $this->process = $this->getMockBuilder('Symfony\Component\Process\Process')
15
            ->disableOriginalConstructor()
16
            ->getMock();
17
        $this->exeFinder = $this->getMockBuilder('Symfony\Component\Process\ExecutableFinder')->getMock();
18
        $this->httpClient = $this->getMockBuilder('GuzzleHttp\Client')->getMock();
19
        $this->waiter = $this->getMockBuilder('BeubiQA\Application\Lib\ResponseWaitter')
20
            ->disableOriginalConstructor()
21
            ->getMock();
22
        $this->seleniumOptions = $this->getMockBuilder('BeubiQA\Application\Selenium\Options\SeleniumStartOptions')->getMock();
23
        $this->starter = new Selenium\SeleniumStarter($this->seleniumOptions, $this->process, $this->waiter, $this->exeFinder);
24
    }
25
26
    /**
27
     * @expectedException LogicException
28
     * @expectedExceptionMessage Url, Query and Selenium Jar Location is mandatory and Jar Location should point to a .jar file.
29
     */
30
    public function testNoJarLocationThrowsException()
31
    {
32
        $this->starter->start();
33
    }
34
35
    /**
36
     * @expectedException LogicException
37
     * @expectedExceptionMessage Url, Query and Selenium Jar Location is mandatory and Jar Location should point to a .jar file.
38
     */
39 View Code Duplication
    public function testNoQueryThrowsException()
40
    {
41
        $jarLocation = __DIR__.'/../fixtures';
42
        $this->seleniumOptions->expects($this->any())->method('getSeleniumUrl')->willReturn('not_empty');
43
        $this->seleniumOptions->expects($this->any())->method('getSeleniumJarLocation')->willReturn($jarLocation);
44
        $this->starter->start();
45
    }
46
47
    /**
48
     * @expectedException LogicException
49
     * @expectedExceptionMessage Url, Query and Selenium Jar Location is mandatory and Jar Location should point to a .jar file.
50
     */
51 View Code Duplication
    public function testNoUrlThrowsException()
52
    {
53
        $jarLocation = __DIR__.'/../fixtures';
54
        $this->seleniumOptions->expects($this->any())->method('getSeleniumQuery')->willReturn('not_empty');
55
        $this->seleniumOptions->expects($this->any())->method('getSeleniumJarLocation')->willReturn($jarLocation);
56
        $this->starter->start();
57
    }
58
59
    /**
60
     * @expectedException RuntimeException
61
     * @expectedExceptionMessage Selenium jar is not a file
62
     */
63 View Code Duplication
    public function testNotAFileThrowsException()
64
    {
65
        $jarLocation = __DIR__.'/../fixtures';
66
        $this->seleniumOptions->expects($this->any())->method('getSeleniumQuery')->willReturn('not_empty');
67
        $this->seleniumOptions->expects($this->any())->method('getSeleniumUrl')->willReturn('not_empty');
68
        $this->seleniumOptions->expects($this->any())->method('getSeleniumJarLocation')->willReturn($jarLocation);
69
        $this->starter->start();
70
    }
71
72
    /**
73
     * @expectedException RuntimeException
74
     * @expectedExceptionMessage Selenium jar not readable
75
     */
76 View Code Duplication
    public function testNotReadableThrowsException()
77
    {
78
        $jarLocation = __DIR__.'/../fixtures/selenium-no-permissions.jar';
79
80
        chmod($jarLocation, 000);
81
82
        $this->seleniumOptions->expects($this->any())->method('getSeleniumQuery')->willReturn('not_empty');
83
        $this->seleniumOptions->expects($this->any())->method('getSeleniumUrl')->willReturn('not_empty');
84
        $this->seleniumOptions->expects($this->any())->method('getSeleniumJarLocation')->willReturn($jarLocation);
85
        $this->starter->start();
86
    }
87
88
    public function testStarterStarts()
89
    {
90
        $jarLocation = __DIR__.'/../fixtures/selenium-dummy.jar';
91
        $javaLocation = 'java-location';
92
        $this->exeFinder->expects($this->any())->method('find')->with('java')->willReturn($javaLocation);
93
        $this->seleniumOptions->expects($this->any())->method('getSeleniumQuery')->willReturn('not_empty');
94
        $this->seleniumOptions->expects($this->any())->method('getSeleniumUrl')->willReturn('not_empty');
95
        $this->seleniumOptions->expects($this->any())->method('getSeleniumJarLocation')->willReturn($jarLocation);
96
        $this->process->expects($this->any())->method('setCommandLine')->with($javaLocation.' -jar '.$jarLocation);
97
        $this->starter->start();
98
    }
99
100 View Code Duplication
    public function testStarterStartsWithXvfb()
101
    {
102
        $jarLocation = __DIR__.'/../fixtures/selenium-dummy.jar';
103
        $javaLocation = 'java-location';
104
        $this->exeFinder->expects($this->at(0))->method('find')->with('java')->willReturn($javaLocation);
105
        $this->seleniumOptions->expects($this->any())->method('getSeleniumQuery')->willReturn('not_empty');
106
        $this->seleniumOptions->expects($this->any())->method('getSeleniumUrl')->willReturn('not_empty');
107
        $this->seleniumOptions->expects($this->any())->method('getSeleniumJarLocation')->willReturn($jarLocation);
108
        $this->seleniumOptions->expects($this->any())->method('isXvfbEnabled')->willReturn(true);
109
        $exceptedCmd = 'DISPLAY=:21 '.$javaLocation.' -jar '.$jarLocation;
110
        $this->process->expects($this->any())->method('setCommandLine')->with($exceptedCmd);
111
        $this->starter->start();
112
    }
113
114 View Code Duplication
    public function testStarterStartsWithPortByExtraArgs()
115
    {
116
        $jarLocation = __DIR__.'/../fixtures/selenium-dummy.jar';
117
        $javaLocation = 'java-location';
118
        $port = 1234;
119
        $this->exeFinder->expects($this->any())->method('find')->with('java')->willReturn($javaLocation);
120
        $this->seleniumOptions->expects($this->any())->method('getSeleniumQuery')->willReturn('not_empty');
121
        $this->seleniumOptions->expects($this->any())->method('getSeleniumUrl')->willReturn('not_empty');
122
        $this->seleniumOptions->expects($this->any())->method('getSeleniumJarLocation')->willReturn($jarLocation);
123
        $this->seleniumOptions->expects($this->any())->method('getSeleniumExtraArguments')->willReturn(['port' => $port]);
124
        $this->process->expects($this->any())->method('setCommandLine')->with($javaLocation.' -jar '.$jarLocation.' -port '.$port);
125
        $this->starter->start();
126
    }
127
128 View Code Duplication
    public function testStarterStartsWithPortByOptions()
129
    {
130
        $jarLocation = __DIR__.'/../fixtures/selenium-dummy.jar';
131
        $javaLocation = 'java-location';
132
        $port = 1234;
133
        $this->exeFinder->expects($this->any())->method('find')->with('java')->willReturn($javaLocation);
134
        $this->seleniumOptions->expects($this->any())->method('getSeleniumQuery')->willReturn('not_empty');
135
        $this->seleniumOptions->expects($this->any())->method('getSeleniumUrl')->willReturn('not_empty');
136
        $this->seleniumOptions->expects($this->any())->method('getSeleniumJarLocation')->willReturn($jarLocation);
137
        $this->seleniumOptions->expects($this->any())->method('getSeleniumPort')->willReturn($port);
138
        $this->process->expects($this->any())->method('setCommandLine')->with($javaLocation.' -jar '.$jarLocation.' -port '.$port);
139
        $this->starter->start();
140
    }
141
}
142