Completed
Push — develop ( f3c189...e92436 )
by Alejandro
08:55
created

AttachmentsOptionsTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 2
dl 23
loc 69
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testTotalFiles() 0 16 1
A setUp() 0 4 1
A testDefaultAttachmentsOptionsValues() 0 14 1
A testDireHasDefaultKeys() 11 11 1
A testDirNormalization() 12 12 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
namespace AcMailerTest\Options;
3
4
use AcMailer\Options\AttachmentsOptions;
5
use PHPUnit_Framework_TestCase as TestCase;
6
7
/**
8
 * Class AttachmentsOptionsTest
9
 * @author Alejandro Celaya Alastrué
10
 * @link http://www.alejandrocelaya.com
11
 */
12
class AttachmentsOptionsTest extends TestCase
13
{
14
    /**
15
     * @var AttachmentsOptions
16
     */
17
    private $attachmentsOptions;
18
19
    public function setUp()
20
    {
21
        $this->attachmentsOptions = new AttachmentsOptions();
22
    }
23
24
    public function testDefaultAttachmentsOptionsValues()
25
    {
26
        $this->assertTrue(is_array($this->attachmentsOptions->getFiles()));
27
        $this->assertCount(0, $this->attachmentsOptions->getFiles());
28
        $this->assertTrue(is_array($this->attachmentsOptions->getDir()));
29
        $this->assertArrayHasKey('recursive', $this->attachmentsOptions->getDir());
30
        $this->assertArrayHasKey('iterate', $this->attachmentsOptions->getDir());
31
        $this->assertArrayHasKey('path', $this->attachmentsOptions->getDir());
32
33
        $dir = $this->attachmentsOptions->getDir();
34
        $this->assertEquals(AttachmentsOptions::DEFAULT_PATH, $dir['path']);
35
        $this->assertEquals(AttachmentsOptions::DEFAULT_ITERATE, $dir['iterate']);
36
        $this->assertEquals(AttachmentsOptions::DEFAULT_RECURSIVE, $dir['recursive']);
37
    }
38
39 View Code Duplication
    public function testDireHasDefaultKeys()
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...
40
    {
41
        $this->attachmentsOptions->setDir(['recursive' => true]);
42
        $this->assertArrayHasKey('recursive', $this->attachmentsOptions->getDir());
43
        $this->assertArrayHasKey('iterate', $this->attachmentsOptions->getDir());
44
        $this->assertArrayHasKey('path', $this->attachmentsOptions->getDir());
45
        $dir = $this->attachmentsOptions->getDir();
46
        $this->assertEquals(AttachmentsOptions::DEFAULT_PATH, $dir['path']);
47
        $this->assertEquals(AttachmentsOptions::DEFAULT_ITERATE, $dir['iterate']);
48
        $this->assertEquals(true, $dir['recursive']);
49
    }
50
51
    public function testTotalFiles()
52
    {
53
        $this->assertCount(0, $this->attachmentsOptions->getFiles());
54
55
        $this->attachmentsOptions->setFiles(['file1', 'file2', 'file3']);
56
        $this->attachmentsOptions->addFiles(['file4', 'file5', 'file6']);
57
        $this->attachmentsOptions->addFile('file7');
58
        $this->attachmentsOptions->addFile('file8');
59
        $this->assertCount(8, $this->attachmentsOptions->getFiles());
60
61
        $this->attachmentsOptions->setFiles(['file1', 'file2', 'file3']);
62
        $this->assertCount(3, $this->attachmentsOptions->getFiles());
63
64
        $this->attachmentsOptions->addFiles(['file4', 'file5', 'file6']);
65
        $this->assertCount(6, $this->attachmentsOptions->getFiles());
66
    }
67
68 View Code Duplication
    public function testDirNormalization()
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...
69
    {
70
        $this->attachmentsOptions->setDir([]);
71
        $this->assertArrayHasKey('recursive', $this->attachmentsOptions->getDir());
72
        $this->assertArrayHasKey('iterate', $this->attachmentsOptions->getDir());
73
        $this->assertArrayHasKey('path', $this->attachmentsOptions->getDir());
74
75
        $dir = $this->attachmentsOptions->getDir();
76
        $this->assertEquals(AttachmentsOptions::DEFAULT_PATH, $dir['path']);
77
        $this->assertEquals(AttachmentsOptions::DEFAULT_ITERATE, $dir['iterate']);
78
        $this->assertEquals(AttachmentsOptions::DEFAULT_RECURSIVE, $dir['recursive']);
79
    }
80
}
81