ContextTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 18
c 2
b 0
f 0
dl 0
loc 40
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testContextTop() 0 4 1
A testContextMiddle() 0 4 1
A testContextBottom() 0 4 1
A tearDown() 0 3 1
A setup() 0 13 3
1
<?php
2
3
namespace Tests;
4
5
use PHPUnit\Framework\TestCase;
6
7
class ContextTest extends TestCase
8
{
9
    protected $file;
10
11
    public function setup()
12
    {
13
        $this->file = tempnam(sys_get_temp_dir(), 'PHPUnitContext');
14
        $handle = fopen($this->file, 'w+');
15
        if (false === $handle) {
16
            throw new \ErrorException('Failed to open file: '.$this->file);
17
        }
18
        foreach (range(1, 40) as $line) {
19
            fwrite($handle, 'Line '.$line."\n");
20
        }
21
        $stat = fstat($handle);
22
        ftruncate($handle, $stat['size'] - 1);
23
        fclose($handle);
24
    }
25
26
    public function tearDown()
27
    {
28
        unlink($this->file);
29
    }
30
31
    public function testContextTop()
32
    {
33
        $context = new \Logfile\Inspection\Context($this->file, 1);
34
        $this->assertCount(5, $context->getPlaceInFile());
35
    }
36
37
    public function testContextMiddle()
38
    {
39
        $context = new \Logfile\Inspection\Context($this->file, 10);
40
        $this->assertCount(9, $context->getPlaceInFile());
41
    }
42
43
    public function testContextBottom()
44
    {
45
        $context = new \Logfile\Inspection\Context($this->file, 40);
46
        $this->assertCount(5, $context->getPlaceInFile());
47
    }
48
}
49