Completed
Push — master ( 6e1259...c4a3c9 )
by Nikola
02:37
created

GzipArchiveProcessorTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 1
cbo 8
dl 46
loc 46
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B gzipAndCleanUp() 26 26 1
A couldNotProcessEmptyCollection() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/*
3
 * This file is part of the Backup package, an RunOpenCode project.
4
 *
5
 * (c) 2015 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * This project is fork of "kbond/php-backup", for full credits info, please
11
 * view CREDITS file that was distributed with this source code.
12
 */
13
namespace RunOpenCode\Backup\Tests\Processor;
14
15
use Psr\Log\NullLogger;
16
use RunOpenCode\Backup\Contract\FileInterface;
17
use RunOpenCode\Backup\Event\BackupEvent;
18
use RunOpenCode\Backup\Processor\GzipArchiveProcessor;
19
use RunOpenCode\Backup\Source\GlobSource;
20
use RunOpenCode\Backup\Tests\Mockup\NullProfile;
21
use Symfony\Component\EventDispatcher\EventDispatcher;
22
23 View Code Duplication
class GzipArchiveProcessorTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Duplication introduced by
This class 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...
24
{
25
    /**
26
     * @test
27
     */
28
    public function gzipAndCleanUp()
29
    {
30
        $source = new GlobSource(realpath(__DIR__ . '/../Fixtures/glob/globSet1') . '/*');
31
        $files = $source->fetch();
32
33
        $this->assertSame(3, count($files), 'There are 3 files to archive.');
34
35
        $processor = new GzipArchiveProcessor('-czvf', 'archive.tar.gz');
36
        $processor->setLogger(new NullLogger());
37
        $processor->setEventDispatcher($eventDispatcher = new EventDispatcher());
38
39
        $processedFiles = $processor->process($files);
40
41
        $this->assertSame(1, count($processedFiles), 'There is one compressed file');
42
43
        /**
44
         * @var FileInterface $processedFile
45
         */
46
        $processedFile = $processedFiles[0];
47
48
        $this->assertTrue(file_exists($processedFile->getPath()), 'Gzip archive exists.');
49
50
        $eventDispatcher->dispatch(BackupEvent::TERMINATE, new BackupEvent(new NullProfile()));
51
52
        $this->assertFalse(file_exists($processedFile->getPath()), 'Gzip archive is cleaned up.');
53
    }
54
55
    /**
56
     * @test
57
     *
58
     * @expectedException \RunOpenCode\Backup\Exception\ProcessorException
59
     */
60
    public function couldNotProcessEmptyCollection()
61
    {
62
        $processor = new GzipArchiveProcessor('-czvf', 'archive.tar.gz');
63
        $processor->setLogger(new NullLogger());
64
        $processor->setEventDispatcher($eventDispatcher = new EventDispatcher());
65
66
        $processor->process(array());
67
    }
68
}