Completed
Push — master ( a7b092...3bee99 )
by Michaël
02:47
created

TextFileTest::testOpenExisting()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 12
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace TextFile\Tests;
4
5
use TextFile\TextFile;
6
7
/**
8
 * Class TextFileTest
9
 *
10
 * @package TextFile\Tests
11
 */
12
class TextFileTest extends TextFileTestCase
13
{
14
    /**
15
     * @covers TextFile\TextFile::open
16
     * @covers TextFile\TextFile::__construct
17
     * @covers TextFile\TextFile::getSplFileObject
18
     */
19
    public function testOpenNonExisting()
20
    {
21
        $filePath = $this->workspace . DIRECTORY_SEPARATOR . mt_rand(0, 1000) . '.txt';
22
23
        $this->assertFalse($this->filesystem->exists($filePath));
24
25
        $textFile = new TextFile($filePath);
26
27
        $this->assertTrue($this->filesystem->exists($filePath));
28
        $this->assertInstanceOf('\SplFileObject', $textFile->getSplFileObject());
29
        $this->assertSame($filePath, $textFile->getSplFileObject()->getRealPath());
30
    }
31
32
    /**
33
     * @covers TextFile\TextFile::open
34
     * @covers TextFile\TextFile::__construct
35
     * @covers TextFile\TextFile::getSplFileObject
36
     */
37
    public function testOpenExisting()
38
    {
39
        $filePath = $this->createTestFileFromFixtures('simple_multiline_file.txt');
40
41
        $this->assertTrue($this->filesystem->exists($filePath));
42
43
        $textFile = new TextFile($filePath);
44
45
        $this->assertTrue($this->filesystem->exists($filePath));
46
        $this->assertInstanceOf('\SplFileObject', $textFile->getSplFileObject());
47
        $this->assertSame($filePath, $textFile->getSplFileObject()->getRealPath());
48
    }
49
}
50