ReaderTest::testReadFile()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 20
nc 1
nop 0
1
<?php
2
3
namespace Yoghi\Bundle\MaddaBundle\Model;
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
/**
15
 * @author Stefano Tamagnini <>
16
 */
17
class ReaderTest extends \PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * @expectedException Yoghi\Bundle\MaddaBundle\Exception\MaddaException
21
     */
22 View Code Duplication
    public function testReadNotExistFile()
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...
23
    {
24
        $baseDirectory = __DIR__.'/';
25
        $fileName = 'nonEsite.yml';
26
        $rym = new Reader();
27
        $rym->readYaml($baseDirectory.'/'.$fileName);
28
    }
29
30
    public function testEmptyReadFile()
31
    {
32
        $baseDirectory = __DIR__.'/../Resources/finder';
33
        $fileName = 'emptyModel.yml';
34
        $rym = new Reader();
35
        $rym->readYaml($baseDirectory.'/'.$fileName);
36
        $prop = $rym->getProperties();
0 ignored issues
show
Deprecated Code introduced by
The method Yoghi\Bundle\MaddaBundle...Reader::getProperties() has been deprecated.

This method has been deprecated.

Loading history...
37
        $propExpected = [
38
            'ddd' => [],
39
            'classes' => [],
40
        ];
41
        $this->assertEquals($propExpected, $prop, 'corretta lettura yml');
42
    }
43
44
    /**
45
     * @expectedException Yoghi\Bundle\MaddaBundle\Exception\MaddaException
46
     */
47 View Code Duplication
    public function testReadInvalidFile()
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...
48
    {
49
        $baseDirectory = __DIR__.'/../Resources/';
50
        $fileName = 'invalidModel.yml';
51
        $rym = new Reader();
52
        $rym->readYaml($baseDirectory.'/'.$fileName);
53
    }
54
55
    /**
56
     * @slowThreshold 10
57
     */
58
    public function testReadFile()
59
    {
60
        $baseDirectory = __DIR__.'/../Resources/finder/basemodel';
61
        $fileName = 'model.yml';
62
        $rym = new Reader();
63
        $rym->readYaml($baseDirectory.'/'.$fileName);
64
        $prop = $rym->getProperties();
0 ignored issues
show
Deprecated Code introduced by
The method Yoghi\Bundle\MaddaBundle...Reader::getProperties() has been deprecated.

This method has been deprecated.

Loading history...
65
        $propExpected = [
66
            'ddd' => [
67
            'vo' => [
68
                'package' => "Yoghi\Bundle\Madda\Domain\ValueObject",
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Yoghi\Bundle\Madda\Domain\ValueObject does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
69
                'getter' => 1,
70
            ],
71
            ],
72
            'classes' => [
73
            'TestEnum' => [
74
                'ddd' => ['type' => 'vo'],
75
                'name' => 'TestEnum',
76
                'description' => 'Test Enum',
77
                'namespace' => 'Yoghi\Bundle\Madda\Domain\ValueObject',
78
                'enum' => [
79
                'TEST',
80
                ],
81
            ],
82
            ],
83
        ];
84
        $this->assertEquals($propExpected, $prop, 'corretta lettura yml');
85
    }
86
87 View Code Duplication
    public function testReadDomainDefinition()
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...
88
    {
89
        $baseDirectory = __DIR__.'/../Resources/finder/basemodel';
90
        $fileName = 'model.yml';
91
        $rym = new Reader();
92
        $rym->readYaml($baseDirectory.'/'.$fileName);
93
        $testVoProperties = $rym->getDomainDefinitionAttributes('vo');
94
        $this->assertEquals('Yoghi\Bundle\Madda\Domain\ValueObject', $testVoProperties['package'], 'package non letto corretamente');
95
    }
96
97
    public function testReadAllClassDefinition()
98
    {
99
        $baseDirectory = __DIR__.'/../Resources/finder/basemodel';
100
        $fileName = 'model.yml';
101
        $rym = new Reader();
102
        $rym->readYaml($baseDirectory.'/'.$fileName);
103
        $prop = $rym->getClassesDefinition();
104
        $propExpected = [
105
        'TestEnum' => [
106
            'ddd' => ['type' => 'vo'],
107
            'name' => 'TestEnum',
108
            'description' => 'Test Enum',
109
            'namespace' => 'Yoghi\Bundle\Madda\Domain\ValueObject',
110
            'enum' => ['TEST'],
111
            ],
112
        ];
113
        $this->assertEquals($propExpected, $prop, 'corretta lettura yml');
114
    }
115
116 View Code Duplication
    public function testReadClassDefinition()
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...
117
    {
118
        $baseDirectory = __DIR__.'/../Resources/finder/basemodel';
119
        $fileName = 'model.yml';
120
        $rym = new Reader();
121
        $rym->readYaml($baseDirectory.'/'.$fileName);
122
        $testEnumProperties = $rym->getClassDefinitionAttributes('TestEnum');
123
        $this->assertEquals('Yoghi\Bundle\Madda\Domain\ValueObject', $testEnumProperties['namespace'], 'namespace non letto corretamente');
124
    }
125
}
126