|
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
|
|
|
|