FunctionalTest::test_Start_Cmd_XVFB()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace BeubiQA\tests;
4
5
use BeubiQA\Application\Command\DownloadSeleniumCommand;
6
use BeubiQA\Tests\SeleniumTestCase;
7
use Symfony\Component\Console\Tester\CommandTester;
8
9
class FunctionalTest extends SeleniumTestCase
10
{
11
    /**
12
     * @expectedException \RuntimeException
13
     * @expectedExceptionMessage Not enough permissions
14
     */
15
    public function test_Get_Without_Permissions()
16
    {
17
        $getCmdTester = new CommandTester(new DownloadSeleniumCommand($this->handler));
18
        $getCmdTester->execute([
19
                '-d' => '/opt/',
20
        ]);
21
    }
22
23
    /**
24
     * @expectedException \RuntimeException
25
     * @expectedExceptionMessage File already exists. ./bin/selenium-server-standalone.jar
26
     */
27
    public function test_Get_Will_Download_a_File()
28
    {
29
        is_file($this->seleniumJarLocation) ? unlink($this->seleniumJarLocation) : '';
30
        $output = $this->exeGetCmd();
31
        $this->assertFileExists($this->seleniumJarLocation);
32
        $this->assertEquals('b5f5a9c1589672dcc29f8b145c47aadf4f9cfc59', sha1_file($this->seleniumJarLocation));
33
        $this->assertContains('Done', $output);
34
35
        $output = $this->exeGetCmd();
36
        $this->assertFileExists($this->seleniumJarLocation);
37
        $this->assertContains('Skipping download as the file already exists.', $output);
38
        $this->assertContains('Done', $output);
39
    }
40
41
    /**
42
     * @expectedException \RuntimeException
43
     * @expectedExceptionMessage Selenium jar is not a file
44
     * @depends test_Get_Will_Download_a_File
45
     */
46
    public function test_Start_Does_Not_Exists()
47
    {
48
        $this->startSelenium([], ['-l' => 'no_selenium.jar']);
49
    }
50
51
    /**
52
     * @expectedException \RuntimeException
53
     * @expectedExceptionMessage Timeout
54
     * @depends test_Get_Will_Download_a_File
55
     */
56
    public function test_Start_Cmd_With_Short_Timeout()
57
    {
58
        $this->startSelenium(['-t' => 0]);
59
    }
60
61
    private function exeGetCmd()
62
    {
63
        $getCmd = new DownloadSeleniumCommand($this->handler);
64
        $getCmdTester = new CommandTester($getCmd);
65
        $getCmdTester->execute([
66
                '-d' => $this->seleniumJarDir,
67
        ]);
68
69
        return $getCmdTester->getDisplay();
70
    }
71
72
    /**
73
     * @depends test_Get_Will_Download_a_File
74
     */
75
    public function test_Start_Works()
76
    {
77
        $output = $this->startSelenium();
78
        $this->assertSeleniumIsRunning();
79
        $this->assertContains($this->seleniumBasicCommand.' > selenium.log 2> selenium.log', $output);
80
    }
81
82
    /**
83
     * @depends test_Get_Will_Download_a_File
84
     */
85
    public function test_Start_Cmd_XVFB()
86
    {
87
        $output = $this->startSelenium(['--xvfb' => true]);
88
        $this->assertContains('DISPLAY=:21 '.$this->seleniumBasicCommand, $output);
89
        $this->assertSeleniumIsRunning();
90
    }
91
}
92