Completed
Push — wip-platform ( 03cba6...2999ab )
by
unknown
05:53 queued 02:49
created

BlastGeneratorTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 92
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 41 41 1
A tearDown() 3 3 1
B testAddResource() 24 24 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
/*
4
 *
5
 * Copyright (C) 2015-2017 Libre Informatique
6
 *
7
 * This file is licenced under the GNU LGPL v3.
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Blast\Bundle\CoreBundle\Tests\Unit\Generator;
13
14
use PHPUnit\Framework\TestCase;
15
use org\bovigo\vfs\vfsStream;
16
use Blast\Bundle\CoreBundle\Generator\BlastGenerator;
17
18 View Code Duplication
class BlastGeneratorTest extends 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...
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...
19
{
20
    /**
21
     * @var BlastGenerator
22
     */
23
    protected $object;
24
25
    private $blastFile;
26
    private $skeletonDirectory;
27
    private $modelManager;
28
29
    private $root;
30
    private $file;
31
32
    /**
33
     * @todo check if it is pertinent to cover __construct and do it(or not) in setUp
34
     * @covers \Blast\Bundle\CoreBundle\Generator\BlastGenerator::__construct
35
     */
36
    protected function setUp()
37
    {
38
        // As blast.yml is modified by the test
39
        $this->root = vfsStream::setup('BlastTestRessources');
40
        $this->file = vfsStream::newFile('blast.yml');
41
        $this->root->addChild($this->file);
42
43
        /*
44
         *   @todo test with and/or without original content
45
         */
46
        $this->file->setContent(file_get_contents('src/Resources/config/blast.yml'));
47
48
        $this->blastFile = vfsStream::url('BlastTestRessources/blast.yml');
49
50
        /*
51
         * @todo check if it should be tested with other skeleton
52
         */
53
54
        $this->skeletonDirectory = 'src/Resources/skeleton';
55
56
        // Sonata Model Manager is used to launch getExportFields
57
        // from the method addResource in Blast\Bundle\CoreBundle\Generator\BlastGenerator
58
        // $managerType =  'sonata.admin.manager.orm';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
59
        $modelManagerMock = $this->getMockForAbstractClass('Sonata\AdminBundle\Model\ModelManagerInterface');
60
61
        $map = [
62
            ['Model', ['foo', 'bar', 'not_an_id']],
63
            ['Ledom', ['id', 'zoo', 'rab']],
64
         ];
65
        $modelManagerMock
66
             ->expects($this->any())
67
             ->method('getExportFields')
68
             ->will($this->returnValueMap($map));
69
70
        $this->modelManager = $modelManagerMock;
71
        $this->object = new BlastGenerator(
72
             $this->blastFile,
73
             $this->modelManager,
74
             $this->skeletonDirectory
75
         );
76
    }
77
78
    protected function tearDown()
79
    {
80
    }
81
82
    /**
83
     * @covers \Blast\Bundle\CoreBundle\Generator\BlastGenerator::addResource
84
     */
85
    public function testAddResource()
86
    {
87
        $this->assertFileExists($this->blastFile);
88
89
        $this->object->AddResource('Model');
90
        $this->object->AddResource('Ledom');
91
92
        $content = $this->file->getContent();
93
94
        // Model
95
        $this->assertContains('blast', $content);
96
        $this->assertContains('foo: ~', $content);
97
        $this->assertContains('Model:', $content);
98
99
        // Ledom
100
        $this->assertContains('Ledom:', $content);
101
102
        /*
103
         * @todo should be test for '#id: ~' when content is generated by sequence like ORM\GeneratedValue(strategy="AUTO")
104
         */
105
        $this->assertContains('id: ~', $content);
106
107
        // echo  $this->file->getContent();
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
108
    }
109
}
110