Completed
Pull Request — master (#62)
by Jason
17:50 queued 02:52
created

AccordionBlockTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 37
loc 37
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetPluralName() 5 5 1
A testGetCMSFields() 7 7 1
A testGetPanelList() 6 6 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
namespace Dynamic\DynamicBlocks\Test;
4
5
use Dynamic\DynamicBlocks\Block\AccordionBlock;
6
use Dynamic\DynamicBlocks\Block\AccordionBlockController;
7
use SilverStripe\Core\Config\Config;
8
use SilverStripe\Dev\FunctionalTest;
9
use SilverStripe\Dev\SapphireTest;
10
use SilverStripe\Forms\FieldList;
11
12 View Code Duplication
class AccordionBlockTest extends SapphireTest
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...
13
{
14
    /**
15
     * @var string
16
     */
17
    protected static $fixture_file = 'dynamic-blocks/tests/Fixtures.yml';
18
19
    /**
20
     *
21
     */
22
    public function testGetPluralName()
23
    {
24
        $object = singleton(AccordionBlock::class);
25
        $this->assertEquals('Accordion Blocks', $object->plural_name());
26
    }
27
28
    /**
29
     *
30
     */
31
    public function testGetCMSFields()
32
    {
33
        $object = $this->objFromFixture(AccordionBlock::class, 'one');
34
        $fields = $object->getCMSFields();
35
        $this->assertInstanceOf(FieldList::class, $fields);
36
        $this->assertNotNull($fields->dataFieldByName('Panels'));
37
    }
38
39
    /**
40
     *
41
     */
42
    public function testGetPanelList()
43
    {
44
        $object = $this->objFromFixture(AccordionBlock::class, 'one');
45
        $panels = $object->Panels()->sort('Sort');
46
        $this->assertEquals($panels, $object->getPanelList());
47
    }
48
}
49
50
class AccordionBlockControllerTest extends FunctionalTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
51
{
52
    /**
53
     *
54
     */
55
    public function testAccordionClass()
56
    {
57
        $object = singleton(AccordionBlockController::class);
58
        $expected = Config::inst()->get(AccordionBlockController::class, 'accordion_class');
59
        $this->assertEquals($object->AccordionClass(), $expected);
60
    }
61
}
62