CopyTest::testCopyCopiesAttributes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
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\Fuctional\Modify;
15
16
use Graze\DataFile\Modify\Compress\Gzip;
17
use Graze\DataFile\Node\LocalFile;
18
use Graze\DataFile\Test\AbstractFileTestCase;
19
use Mockery as m;
20
21
class CopyTest extends AbstractFileTestCase
22
{
23
    public function testCopyCreatesADuplicateFile()
24
    {
25
        $localFile = new LocalFile(static::$dir . 'copy_orig.test');
26
        $localFile->put('some random text');
27
28
        $newFile = $localFile->copy($localFile->getPath() . '.copy');
29
30
        static::assertTrue($newFile->exists());
31
        static::assertEquals($localFile->getPath() . '.copy', $newFile->getPath());
32
        static::assertEquals($localFile->getContents(), $newFile->getContents());
33
    }
34
35
    public function testCopyCopiesAttributes()
36
    {
37
        $localFile = (new LocalFile(static::$dir . 'copy_attributes.text'))
38
            ->setEncoding('ascii');
39
        $localFile->put('some ascii text');
40
41
        $newFile = $localFile->copy($localFile->getPath() . '.copy');
42
43
        static::assertEquals('ascii', $newFile->getEncoding());
44
45
        $gzip = new Gzip();
46
        $gzipped = $gzip->compress($newFile);
47
48
        static::assertEquals(Gzip::NAME, $gzipped->getCompression());
49
50
        $gzipCopy = $gzipped->copy($gzipped->getPath() . '.copy');
51
52
        static::assertEquals($gzipped->getCompression(), $gzipCopy->getCompression());
53
    }
54
55 View Code Duplication
    public function testCopyAppendsCopyWhenNoPathIsSpecified()
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...
56
    {
57
        $localFile = new LocalFile(static::$dir . 'copy_default_append.text');
58
        $localFile->put('some random text');
59
60
        $newFile = $localFile->copy();
61
62
        static::assertEquals($localFile->getPath() . '-copy', $newFile);
63
    }
64
}
65