AssetIsCached   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 33
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setAssetUrl() 0 4 1
A assert() 0 18 4
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
}