ContextTest::setup()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 2
b 0
f 0
nc 3
nop 0
dl 0
loc 13
rs 9.9666
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