DownloaderTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 59
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setup() 0 6 1
A testSeleniumUrlAndDestinationAreMandatory() 0 4 1
A testSeleniumUrlIsMandatory() 0 5 1
A testSeleniumDestinationIsMandatory() 0 5 1
A testDownloaderDownloads() 0 11 2
1
<?php
2
3
namespace BeubiQA\tests\Unit;
4
5
use BeubiQA\Application\Selenium;
6
7
class DownloaderTest extends \PHPUnit_Framework_TestCase
8
{
9
    /** @var Selenium\SeleniumDownloader  */
10
    private $downloader;
11
    private $httpClient;
12
    private $seleniumOptions;
13
14
    public function setup()
15
    {
16
        $this->httpClient = $this->getMockBuilder('GuzzleHttp\Client')->getMock();
17
        $this->seleniumOptions = $this->getMockBuilder('BeubiQA\Application\Selenium\Options\SeleniumDownloaderOptions')->getMock();
18
        $this->downloader = new Selenium\SeleniumDownloader($this->seleniumOptions, $this->httpClient);
19
    }
20
21
    /**
22
     * @expectedException LogicException
23
     * @expectedExceptionMessage Destination and Download Url are mandatory.
24
     */
25
    public function testSeleniumUrlAndDestinationAreMandatory()
26
    {
27
        $this->downloader->download();
28
    }
29
30
    /**
31
     * @expectedException LogicException
32
     * @expectedExceptionMessage Destination and Download Url are mandatory.
33
     */
34
    public function testSeleniumUrlIsMandatory()
35
    {
36
        $this->seleniumOptions->expects($this->any())->method('getSeleniumDownloadUrl')->willReturn('some_url');
37
        $this->downloader->download();
38
    }
39
40
    /**
41
     * @expectedException LogicException
42
     * @expectedExceptionMessage Destination and Download Url are mandatory.
43
     */
44
    public function testSeleniumDestinationIsMandatory()
45
    {
46
        $this->seleniumOptions->expects($this->any())->method('getSeleniumDestination')->willReturn('some_dest');
47
        $this->downloader->download();
48
    }
49
50
    /**
51
     * @expectedException RuntimeException
52
     * @expectedExceptionMessage  The selenium file does not exists. /tmp/selenium-server-standalone.jar
53
     */
54
    public function testDownloaderDownloads()
55
    {
56
        $destinationFolder = '/tmp';
57
        $destination = $destinationFolder.'/selenium-server-standalone.jar';
58
        is_file($destination) ? unlink($destination) : '';
59
        $downloadUrl = 'some_url';
60
        $this->seleniumOptions->expects($this->any())->method('getSeleniumDestination')->willReturn($destinationFolder);
61
        $this->seleniumOptions->expects($this->any())->method('getSeleniumDownloadUrl')->willReturn($downloadUrl);
62
        $this->httpClient->expects($this->any())->method('get')->with($downloadUrl, ['save_to' => $destination]);
63
        $this->downloader->download();
64
    }
65
}
66