Completed
Push — master ( 751b72...5449f6 )
by Kevin
06:38 queued 03:35
created

AssetIsCached::setAssetUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Magium\Assertions\Browser;
4
5
use Magium\Assertions\AbstractAssertion;
6
7
class AssetIsCached extends AbstractAssertion
8
{
9
10
    const ASSERTION = 'Browser\AssetIsCached';
11
12
    protected $url;
13
    
14
    public function setAssetUrl($url)
15
    {
16
        $this->url = $url;
17
    }
18
19
20
    public function assert()
21
    {
22
        if (!$this->url) {
23
            $this->testCase->fail('Assertion requires a URL');
24
        }
25
26
        $assets = $this->webDriver->executeScript('return window.performance.getEntries()');
27
        $foundAsset = false;
28
29
        foreach ($assets as $asset) {
30
            if (strpos($asset['name'], $this->url) !== false) {
31
                $this->testCase->assertEquals(0, $asset['duration'], 'Asset was not cached: ' . $asset['name']);
32
                $foundAsset = true;
33
            }
34
        }
35
36
        $this->testCase->assertTrue($foundAsset, 'Unable to find asset: ' . $this->url);
37
    }
38
39
}