testGetCommonPrefixReturnsNullIfThereIsNoCommonPrefix()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of graze/data-file
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/data-file/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/data-file
12
 */
13
14
namespace Graze\DataFile\Test\Unit\Node;
15
16
use Graze\DataFile\Node\FileNodeCollection;
17
use Graze\DataFile\Node\FileNodeInterface;
18
use Graze\DataFile\Test\TestCase;
19
use Graze\DataNode\NodeCollection;
20
use Graze\DataNode\NodeInterface;
21
use InvalidArgumentException;
22
use Mockery as m;
23
24
class FileNodeCollectionTest extends TestCase
25
{
26
    /**
27
     * @var FileNodeCollection
28
     */
29
    protected $collection;
30
31
    public function setUp()
32
    {
33
        $this->collection = new FileNodeCollection();
34
    }
35
36
    public function testIsDataNodeCollection()
37
    {
38
        static::assertInstanceOf(NodeCollection::class, $this->collection);
39
    }
40
41 View Code Duplication
    public function testGetCommonPrefixReturnsCommonPrefixOfFiles()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43
        $file1 = m::mock(FileNodeInterface::class);
44
        $file1->shouldReceive('getPath')->andReturn('some/common/path/to/file1.txt');
45
        $file2 = m::mock(FileNodeInterface::class);
46
        $file2->shouldReceive('getPath')->andReturn('some/common/path/to/file2.txt');
47
        $file3 = m::mock(FileNodeInterface::class);
48
        $file3->shouldReceive('getPath')->andReturn('some/common/path/to/file3.txt');
49
50
        $this->collection->add($file1);
51
        $this->collection->add($file2);
52
        $this->collection->add($file3);
53
54
        static::assertEquals('some/common/path/to/file', $this->collection->getCommonPrefix());
55
    }
56
57 View Code Duplication
    public function testGetCommonPrefixReturnsNullIfThereIsNoCommonPrefix()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
    {
59
        $file1 = m::mock(FileNodeInterface::class);
60
        $file1->shouldReceive('getPath')->andReturn('some/common/path/to/file1.txt');
61
        $file2 = m::mock(FileNodeInterface::class);
62
        $file2->shouldReceive('getPath')->andReturn('some/common/path/to/file2.txt');
63
        $file3 = m::mock(FileNodeInterface::class);
64
        $file3->shouldReceive('getPath')->andReturn('other/nonCommon/path/to/file3.txt');
65
66
        $this->collection->add($file1);
67
        $this->collection->add($file2);
68
        $this->collection->add($file3);
69
70
        static::assertNull($this->collection->getCommonPrefix());
71
    }
72
73
    public function testGetCommonPrefixReturnsNullIfThereAreNoItems()
74
    {
75
        static::assertNull($this->collection->getCommonPrefix());
76
    }
77
78
    public function testCanAddAFileNode()
79
    {
80
        $node = m::mock(FileNodeInterface::class);
81
        static::assertSame($this->collection, $this->collection->add($node));
82
    }
83
84
    public function testAddingANonDataNodeWillThrowAnException()
85
    {
86
        $node = m::mock(NodeInterface::class);
87
88
        $this->expectException(InvalidArgumentException::class);
89
90
        $this->collection->add($node);
91
    }
92
}
93