Passed
Push — master ( fc228a...3b7b3a )
by Jonathan
01:49
created

MemoryUsageTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testMemoryUsage() 0 23 2
A roundMemoryUsage() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Purl\Test;
6
7
use PHPUnit\Framework\TestCase;
8
use Purl\Url;
9
use function floor;
10
use function log;
11
use function memory_get_usage;
12
use function pow;
13
use function round;
14
15
class MemoryUsageTest extends TestCase
16
{
17
    public function testMemoryUsage() : void
18
    {
19
        $domains = [
20
            'http://google.de',
21
            'http://google.com',
22
            'http://google.it',
23
            'https://google.de',
24
            'https://google.com',
25
            'https://google.it',
26
            'http://www.google.de',
27
            'http://www.google.com',
28
            'http://www.google.it',
29
        ];
30
31
        $memoryStart = memory_get_usage(true);
32
33
        foreach ($domains as $key => $domain) {
34
            $purl[$key] = Url::parse($domain);
35
        }
36
37
        $memoryEnd = memory_get_usage(true);
38
39
        self::assertEquals($this->roundMemoryUsage($memoryStart), $this->roundMemoryUsage($memoryEnd));
40
    }
41
42
    private function roundMemoryUsage(float $size) : float
43
    {
44
        return round($size / pow(1024, $i = floor(log($size, 1024))));
45
    }
46
}
47