DDDGeneratorTest::testGenerateDDDOnVfs()   B
last analyzed

Complexity

Conditions 5
Paths 12

Size

Total Lines 74
Code Lines 43

Duplication

Lines 5
Ratio 6.76 %

Importance

Changes 0
Metric Value
dl 5
loc 74
rs 8.4878
c 0
b 0
f 0
cc 5
eloc 43
nc 12
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Yoghi\Bundle\MaddaBundle\Finder;
4
5
/*
6
 * This file is part of the MADDA project.
7
 *
8
 * (c) Stefano Tamagnini <>
9
 *
10
 * This source file is subject to the GPLv3 license that is bundled
11
 * with this source code in the file LICENSE.
12
 */
13
14
use Monolog\Logger;
15
use Yoghi\Bundle\MaddaBundle\Generator\DDDGenerator;
16
use Yoghi\Bundle\MaddaBundleTest\Utils\AbstractCommonLogTest;
17
use Yoghi\Bundle\MaddaBundleTest\Utils\FileCompare;
18
use Yoghi\Bundle\MaddaBundleTest\Utils\VfsAdapter;
19
20
/**
21
 * @author Stefano Tamagnini <>
22
 */
23
class DDDGeneratorTest extends \PHPUnit_Framework_TestCase
24
{
25
    use AbstractCommonLogTest;
26
    use FileCompare;
27
28
    public function testGenerateDDDOnVfs()
29
    {
30
        $directoryOutput = self::$directoryV->url().'/output';
31
        $directorySrcGen = self::$directoryV->url().'/src-gen';
32
        $resourcesDir = __DIR__.'/../Resources';
33
        if (!file_exists($directoryOutput)) {
34
            mkdir($directoryOutput, 0700, true);
35
        }
36
        if (!file_exists($directorySrcGen)) {
37
            mkdir($directorySrcGen, 0700, true);
38
        }
39
        $data = file_get_contents($resourcesDir.'/ddd/real.yml');
40
        file_put_contents($directoryOutput.'/test.yml', $data);
41
42
        $dddg = new DDDGenerator();
43
        $dddg->setLogger($this->logger);
44
        $dddg->analyze($directoryOutput.'/test.yml');
45
        $dddg->generate(new VfsAdapter($directorySrcGen));
46
47
        // $data = file_get_contents("vfs://root/src-gen/BitPrepared/Bundle/FormazioneBundle/Domain/Events/DomainEvent.php");
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
48
        // echo $data;
49
50
        // $finderV = new Finder();
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% 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...
51
        // $finderV->search($directorySrcGen, 'php');
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% 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...
52
        // foreach ($finderV->getFindedFiles() as $file) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
53
        //     $namespace = str_replace('vfs://root/src-gen/', '', pathinfo($file, PATHINFO_DIRNAME));
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% 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...
54
        //     $name = str_replace('.php', '', pathinfo($file, PATHINFO_FILENAME));
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% 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...
55
        //     $this->logger->info('$mappaToCheck[\''.$namespace.'\'] = \''.$name.'\';');
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% 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...
56
        // }
57
        // echo $this->readLog();
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
58
        // exit;
59
60
        $mappaToCheck = [];
61
        $mappaToCheck['BitPrepared/Bundle/FormazioneBundle/Domain/Events'][] = 'DomainEvent';
62
        $mappaToCheck['BitPrepared/Bundle/FormazioneBundle/Domain/Events'][] = 'SpiegazioneSessioneCampoAddDocumentEvent';
63
        $mappaToCheck['BitPrepared/Bundle/FormazioneBundle/Domain/Events'][] = 'SpiegazioneSessioneCampoCreateEvent';
64
        $mappaToCheck['BitPrepared/Bundle/FormazioneBundle/Domain/Events'][] = 'SpiegazioneSessioneCampoDeleteEvent';
65
        $mappaToCheck['BitPrepared/Bundle/FormazioneBundle/Domain/ValueObject/TipologiaCampo'][] = 'CFMLC';
66
        $mappaToCheck['BitPrepared/Bundle/FormazioneBundle/Domain/ValueObject/TipologiaCampo'][] = 'CFMEG';
67
        $mappaToCheck['BitPrepared/Bundle/FormazioneBundle/Domain/ValueObject/TipologiaCampo'][] = 'CFMRS';
68
        $mappaToCheck['BitPrepared/Bundle/FormazioneBundle/Domain/ValueObject/TipologiaCampo'][] = 'CFT';
69
        $mappaToCheck['BitPrepared/Bundle/FormazioneBundle/Domain/ValueObject/TipologiaCampo'][] = 'CAMLC';
70
        $mappaToCheck['BitPrepared/Bundle/FormazioneBundle/Domain/ValueObject/TipologiaCampo'][] = 'CAMEG';
71
        $mappaToCheck['BitPrepared/Bundle/FormazioneBundle/Domain/ValueObject/TipologiaCampo'][] = 'CAMRS';
72
        $mappaToCheck['BitPrepared/Bundle/FormazioneBundle/Domain/ValueObject/TipologiaCampo'][] = 'CCG';
73
        $mappaToCheck['BitPrepared/Bundle/FormazioneBundle/Domain/ValueObject'][] = 'TipologiaCampo';
74
        $mappaToCheck['BitPrepared/Bundle/FormazioneBundle/Domain/ValueObject'][] = 'Sessione';
75
        $mappaToCheck['BitPrepared/Bundle/FormazioneBundle/Domain/ValueObject'][] = 'SessioniArray';
76
        $mappaToCheck['BitPrepared/Bundle/FormazioneBundle/Domain/Entity'][] = 'SessioneCampo';
77
        $mappaToCheck['BitPrepared/Bundle/FormazioneBundle/Domain/Aggregate'][] = 'SpiegazioneSessioneCampo';
78
        $mappaToCheck['BitPrepared/Bundle/FormazioneBundle/Domain/Service/QueryRequest'][] = 'DettagliSessioneRequest';
79
        $mappaToCheck['BitPrepared/Bundle/FormazioneBundle/Domain/Service/QueryRequest'][] = 'ElencoSessioniForTipologiaRequest';
80
        $mappaToCheck['BitPrepared/Bundle/FormazioneBundle/Domain/Service/QueryRequest'][] = 'ElencoSessioniRequest';
81
        $mappaToCheck['BitPrepared/Bundle/FormazioneBundle/Domain/Service/CommandRequest'][] = 'NewSessioneRequest';
82
        $mappaToCheck['BitPrepared/Bundle/FormazioneBundle/Domain/Classes'][] = 'SampleClassWithNamespace';
83
        $mappaToCheck[''][] = 'SampleClass';
84
85 View Code Duplication
        foreach ($mappaToCheck as $namespace => $classList) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
86
            foreach ($classList as $className) {
87
                $this->compareClassPhp($resourcesDir.'/ddd/generated/'.$namespace, $namespace, $className, $directorySrcGen);
88
            }
89
        }
90
91
        // $namespace = 'BitPrepared/Bundle/FormazioneBundle/Domain/ValueObject';
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...
92
        // $className = 'Sessione';
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...
93
        // $this->compareClassPhp($resourcesDir.'/ddd/generated/'.$namespace, $namespace, $className, $directorySrcGen);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
94
        //
95
        // $namespace = 'BitPrepared/Bundle/FormazioneBundle/Domain/ValueObject';
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...
96
        // $className = 'SessioniArray';
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...
97
        // $this->compareClassPhp($resourcesDir.'/ddd/generated/'.$namespace, $namespace, $className, $directorySrcGen);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
98
99
        $errors = $dddg->getErrors();
100
        $this->assertCount(0, $errors, 'errori durante la generazione');
101
    }
102
103 View Code Duplication
    public function testGenerateDDDOnVfsBadEventsSpecific()
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...
104
    {
105
        $directoryOutput = self::$directoryV->url().'/output';
106
        $directorySrcGen = self::$directoryV->url().'/src-gen-bad-event';
107
        $resourcesDir = __DIR__.'/../Resources';
108
        if (!file_exists($directoryOutput)) {
109
            mkdir($directoryOutput, 0700, true);
110
        }
111
        if (!file_exists($directorySrcGen)) {
112
            mkdir($directorySrcGen, 0700, true);
113
        }
114
        $data = file_get_contents($resourcesDir.'/ddd/badEvents.yml');
115
        file_put_contents($directoryOutput.'/test.yml', $data);
116
117
        $dddg = new DDDGenerator();
118
        $dddg->setLogger($this->logger);
119
        $dddg->analyze($directoryOutput.'/test.yml');
120
        $dddg->generate(new VfsAdapter($directorySrcGen));
121
122
        $errors = $dddg->getErrors();
123
        $this->assertCount(1, $errors, 'errori non previsti durante la generazione');
124
    }
125
126 View Code Duplication
    public function testGenerateDDDOnVfsBad()
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...
127
    {
128
        $directoryOutput = self::$directoryV->url().'/output';
129
        $directorySrcGen = self::$directoryV->url().'/src-gen-bad-event';
130
        $resourcesDir = __DIR__.'/../Resources';
131
        if (!file_exists($directoryOutput)) {
132
            mkdir($directoryOutput, 0700, true);
133
        }
134
        if (!file_exists($directorySrcGen)) {
135
            mkdir($directorySrcGen, 0700, true);
136
        }
137
        $data = file_get_contents($resourcesDir.'/ddd/bad.yml');
138
        file_put_contents($directoryOutput.'/test.yml', $data);
139
140
        $dddg = new DDDGenerator();
141
        $dddg->setLogger($this->logger);
142
        $dddg->analyze($directoryOutput.'/test.yml');
143
        $dddg->generate(new VfsAdapter($directorySrcGen));
144
145
        $errors = $dddg->getErrors();
146
        $this->assertCount(1, $errors, 'errori non previsti durante la generazione');
147
    }
148
149 View Code Duplication
    public function testGenerateDDDOnVfsBadDefinition()
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...
150
    {
151
        $directoryOutput = self::$directoryV->url().'/output';
152
        $directorySrcGen = self::$directoryV->url().'/src-gen-bad-event';
153
        $resourcesDir = __DIR__.'/../Resources';
154
        if (!file_exists($directoryOutput)) {
155
            mkdir($directoryOutput, 0700, true);
156
        }
157
        if (!file_exists($directorySrcGen)) {
158
            mkdir($directorySrcGen, 0700, true);
159
        }
160
        $data = file_get_contents($resourcesDir.'/ddd/badDefinition.yml');
161
        file_put_contents($directoryOutput.'/test.yml', $data);
162
163
        $dddg = new DDDGenerator();
164
        $dddg->setLogger($this->logger);
165
        $dddg->analyze($directoryOutput.'/test.yml');
166
        $dddg->generate(new VfsAdapter($directorySrcGen));
167
168
        $errors = $dddg->getErrors();
169
        $this->assertCount(1, $errors, 'errori non previsti durante la generazione');
170
    }
171
172
    public function testGenerateDDDOnVfsEventsSpecific()
173
    {
174
        $directoryOutput = self::$directoryV->url().'/output';
175
        $directorySrcGen = self::$directoryV->url().'/src-gen-event';
176
        $resourcesDir = __DIR__.'/../Resources';
177
        if (!file_exists($directoryOutput)) {
178
            mkdir($directoryOutput, 0700, true);
179
        }
180
        if (!file_exists($directorySrcGen)) {
181
            mkdir($directorySrcGen, 0700, true);
182
        }
183
        $data = file_get_contents($resourcesDir.'/ddd/realEvents.yml');
184
        file_put_contents($directoryOutput.'/test.yml', $data);
185
186
        $dddg = new DDDGenerator();
187
        $dddg->setLogger($this->logger);
188
        $dddg->analyze($directoryOutput.'/test.yml');
189
        $dddg->generate(new VfsAdapter($directorySrcGen));
190
191
        // $finderV = new Finder();
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% 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...
192
        // $finderV->search($directorySrcGen, 'php');
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% 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...
193
        // foreach ($finderV->getFindedFiles() as $file) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
194
        //     $namespace = str_replace('vfs://root/src-gen-event/', '', pathinfo($file, PATHINFO_DIRNAME));
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% 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...
195
        //     $name = str_replace('.php', '', pathinfo($file, PATHINFO_FILENAME));
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% 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...
196
        //     $this->logger->info('$mappaToCheck[\''.$namespace.'\'] = \''.$name.'\';');
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% 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...
197
        // }
198
        // echo $this->readLog();
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
199
        // exit;
200
201
        $mappaToCheck = [];
202
        $mappaToCheck['BitPrepared/Bundle/EventBundle/Domain/Events'][] = 'DomainEvent';
203
        $mappaToCheck['BitPrepared/Bundle/EventBundle/Domain/Events'][] = 'SpiegazioneSessioneCampoCreateEvent';
204
        $mappaToCheck['BitPrepared/Bundle/EventBundle/Domain/Events'][] = 'SpiegazioneSessioneCampoDeleteEvent';
205
        $mappaToCheck['BitPrepared/Bundle/EventBundle/Domain/Events'][] = 'SpiegazioneSessioneCampoAddDocumentEvent';
206
        $mappaToCheck['BitPrepared/Bundle/EventBundle/Domain/Aggregate'][] = 'SpiegazioneSessioneCampo';
207
208 View Code Duplication
        foreach ($mappaToCheck as $namespace => $classList) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
209
            foreach ($classList as $className) {
210
                $this->compareClassPhp($resourcesDir.'/ddd/generated/'.$namespace, $namespace, $className, $directorySrcGen);
211
            }
212
        }
213
214
        $errors = $dddg->getErrors();
215
        $this->assertCount(0, $errors, 'errori durante la generazione');
216
    }
217
}
218