forked from catchpoint/WebPageTest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtilTest.php
87 lines (80 loc) · 2.53 KB
/
UtilTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
declare(strict_types=1);
namespace WebPageTest;
use PHPUnit\Framework\TestCase;
use WebPageTest\Util;
use WebPageTest\Util\Cache;
final class UtilTest extends TestCase
{
public function testConstructorThrows(): void
{
$this->expectException(\Exception::class);
$util = new Util();
}
public function testGetSetting(): void
{
$override_settings_file = TESTS_PATH . '/fixtures/settings.ini';
$value = Util::getSetting('product', false, $override_settings_file);
$this->assertEquals('WebPagetest', $value);
}
public function testGetSettingWithNullDefault(): void
{
$override_settings_file = TESTS_PATH . '/fixtures/settings.ini';
$value = Util::getSetting('product', null, $override_settings_file);
$this->assertEquals('WebPagetest', $value);
}
public function testCacheFetch(): void
{
$value = 'silly-thing';
$key = 'oh-ok';
$cached = Cache::store($key, $value, 30);
$this->assertTrue($cached);
$fetched = Cache::fetch($key);
$this->assertEquals($value, $fetched);
}
public function testGetRunCountFirstViewOnly(): void
{
$runs = 1;
$fvonly = 1;
$lighthouse = 0;
$testtype = '';
$total_runs = Util::getRunCount($runs, $fvonly, $lighthouse, $testtype);
$this->assertEquals(1, $total_runs);
}
public function testGetRunCountFirstViewOnlyWithLighthouse(): void
{
$runs = 1;
$fvonly = 1;
$lighthouse = 1;
$testtype = '';
$total_runs = Util::getRunCount($runs, $fvonly, $lighthouse, $testtype);
$this->assertEquals(1, $total_runs);
}
public function testGetRunCountRepeatView(): void
{
$runs = 1;
$fvonly = 0;
$lighthouse = 0;
$testtype = '';
$total_runs = Util::getRunCount($runs, $fvonly, $lighthouse, $testtype);
$this->assertEquals(2, $total_runs);
}
public function testGetRunCountRepeatViewWithLighthouse(): void
{
$runs = 1;
$fvonly = 0;
$lighthouse = 1;
$testtype = '';
$total_runs = Util::getRunCount($runs, $fvonly, $lighthouse, $testtype);
$this->assertEquals(2, $total_runs);
}
public function testGetRunCountLighthouseTest(): void
{
$runs = 1;
$fvonly = 1;
$lighthouse = 1;
$testtype = 'lighthouse';
$total_runs = Util::getRunCount($runs, $fvonly, $lighthouse, $testtype);
$this->assertEquals(1, $total_runs);
}
}