Test Failed
Push — master ( 9bf844...efe5ed )
by Waaaaaaaaaa
03:38
created

ContextTest::setup()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 0
loc 10
rs 10
c 0
b 0
f 0
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 = __DIR__.'/../tmp/context.txt';
14
        $handle = fopen($this->file, 'w+');
15
        foreach (range(1, 40) as $line) {
16
            fwrite($handle, 'Line '.$line."\n");
0 ignored issues
show
Bug introduced by
It seems like $handle can also be of type false; however, parameter $handle of fwrite() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

16
            fwrite(/** @scrutinizer ignore-type */ $handle, 'Line '.$line."\n");
Loading history...
17
        }
18
        $stat = fstat($handle);
0 ignored issues
show
Bug introduced by
It seems like $handle can also be of type false; however, parameter $handle of fstat() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

18
        $stat = fstat(/** @scrutinizer ignore-type */ $handle);
Loading history...
19
        ftruncate($handle, $stat['size'] - 1);
0 ignored issues
show
Bug introduced by
It seems like $handle can also be of type false; however, parameter $handle of ftruncate() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

19
        ftruncate(/** @scrutinizer ignore-type */ $handle, $stat['size'] - 1);
Loading history...
20
        fclose($handle);
0 ignored issues
show
Bug introduced by
It seems like $handle can also be of type false; however, parameter $handle of fclose() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

20
        fclose(/** @scrutinizer ignore-type */ $handle);
Loading history...
21
    }
22
23
    public function tearDown()
24
    {
25
        unlink($this->file);
26
    }
27
28
    public function testContextTop()
29
    {
30
        $context = new \Logfile\Context($this->file, 1);
31
        $this->assertCount(5, $context->getPlaceInFile());
32
    }
33
34
    public function testContextMiddle()
35
    {
36
        $context = new \Logfile\Context($this->file, 10);
37
        $this->assertCount(9, $context->getPlaceInFile());
38
    }
39
40
    public function testContextBottom()
41
    {
42
        $context = new \Logfile\Context($this->file, 40);
43
        $this->assertCount(5, $context->getPlaceInFile());
44
    }
45
}
46