Test Failed
Push — master ( 58d34e...819155 )
by Christopher
03:53
created

testEntitysAndPropertiesAndNavigationProperties()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 91
Code Lines 80

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 91
rs 8.518
cc 1
eloc 80
nc 1
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
 * Created by PhpStorm.
4
 * User: Doc
5
 * Date: 5/11/2017
6
 * Time: 11:01 PM
7
 */
8
9
namespace AlgoWeb\ODataMetadata\Tests;
10
11
use AlgoWeb\ODataMetadata\MetadataManager;
12
13
class MetadataManagerTest extends \PHPUnit_Framework_TestCase
14
{
15
    public function testIsOKAtDefault()
16
    {
17
        $ds = DIRECTORY_SEPARATOR;
0 ignored issues
show
Unused Code introduced by
$ds is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
18
        $metadataManager = new MetadataManager();
19
        $msg = null;
20
        $edmx = $metadataManager->getEdmx();
21
        $this->assertTrue($edmx->isOK($msg), $msg);
22
        $this->assertNull($msg);
23
24
        $d = $metadataManager->getEdmxXML();
25
        $this->v3MetadataAgainstXSD($d);
26
    }
27
28 View Code Duplication
    public function v3MetadataAgainstXSD($data)
1 ignored issue
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...
29
    {
30
        $ds = DIRECTORY_SEPARATOR;
31
        $xml = new \DOMDocument();
32
        $xml->loadXML($data);
33
        $xml->schemaValidate(dirname(__DIR__) . $ds . "xsd" . $ds . "/Microsoft.Data.Entity.Design.Edmx_3.xsd");
34
    }
35
36
    public function testEntitysAndProperties()
37
    {
38
        $metadataManager = new MetadataManager();
39
40
        $eType = $metadataManager->addEntityType("Category");
41
        $this->assertNotFalse($eType, "Etype is false not type " . $metadataManager->getLastError());
42
        $metadataManager->addPropertyToEntityType($eType, "CategoryID", "Int32", null, false, true, "Identity");
43
        $metadataManager->addPropertyToEntityType($eType, "CategoryName", "String");
44
        $metadataManager->addPropertyToEntityType($eType, "Description", "String");
45
        $metadataManager->addPropertyToEntityType($eType, "Picture", "Binary");
46
47
        $eType = $metadataManager->addEntityType("CustomerDemographic");
48
        $metadataManager->addPropertyToEntityType($eType, "CustomerTypeID", "String", null, false, true);
49
        $metadataManager->addPropertyToEntityType($eType, "CustomerDesc", "String");
50
51
52
        $msg = null;
53
        $edmx = $metadataManager->getEdmx();
54
        $this->assertTrue($edmx->isOK($msg), $msg);
55
        $this->assertNull($msg);
56
57
        $d = $metadataManager->getEdmxXML();
58
        $this->v3MetadataAgainstXSD($d);
59
    }
60
61
    public function testEntitysAndPropertiesAndNavigationProperties()
62
    {
63
        $metadataManager = new MetadataManager();
64
65
        $CategoryType = $metadataManager->addEntityType("Category");
66
        $this->assertNotFalse($CategoryType, "Etype is false not type " . $metadataManager->getLastError());
67
        $metadataManager->addPropertyToEntityType($CategoryType, "CategoryID", "Int32", null, false, true, "Identity");
68
        $metadataManager->addPropertyToEntityType($CategoryType, "CategoryName", "String");
69
        $metadataManager->addPropertyToEntityType($CategoryType, "Description", "String");
70
        $metadataManager->addPropertyToEntityType($CategoryType, "Picture", "Binary");
71
72
        $CustomerDemographicType = $metadataManager->addEntityType("CustomerDemographic");
73
        $metadataManager->addPropertyToEntityType($CustomerDemographicType, "CustomerTypeID", "String", null, false, true);
74
        $metadataManager->addPropertyToEntityType($CustomerDemographicType, "CustomerDesc", "String");
75
76
        $CustomerType = $metadataManager->addEntityType("Customer");
77
        $metadataManager->addPropertyToEntityType($CustomerType, "CustomerID", "String", null, false, true);
78
        $metadataManager->addPropertyToEntityType($CustomerType, "CompanyName", "String");
79
        $metadataManager->addPropertyToEntityType($CustomerType, "ContactName", "String");
80
        $metadataManager->addPropertyToEntityType($CustomerType, "ContactTitle", "String");
81
        $metadataManager->addPropertyToEntityType($CustomerType, "Address", "String");
82
        $metadataManager->addPropertyToEntityType($CustomerType, "City", "String");
83
        $metadataManager->addPropertyToEntityType($CustomerType, "Region", "String");
84
        $metadataManager->addPropertyToEntityType($CustomerType, "PostalCode", "String");
85
        $metadataManager->addPropertyToEntityType($CustomerType, "Country", "String");
86
        $metadataManager->addPropertyToEntityType($CustomerType, "Phone", "String");
87
        $metadataManager->addPropertyToEntityType($CustomerType, "Fax", "String");
88
89
        $EmployeeType = $metadataManager->addEntityType("Employee");
90
        $metadataManager->addPropertyToEntityType($EmployeeType, "EmployeeID", "Int32", null, false, true, "Identity");
91
        $metadataManager->addPropertyToEntityType($EmployeeType, "LastName", "String");
92
        $metadataManager->addPropertyToEntityType($EmployeeType, "FirstName", "String");
93
        $metadataManager->addPropertyToEntityType($EmployeeType, "Title", "String");
94
        $metadataManager->addPropertyToEntityType($EmployeeType, "TitleOfCourtesy", "String");
95
        $metadataManager->addPropertyToEntityType($EmployeeType, "BirthDate", "DateTime");
96
        $metadataManager->addPropertyToEntityType($EmployeeType, "HireDate", "DateTime");
97
        $metadataManager->addPropertyToEntityType($EmployeeType, "Address", "String");
98
        $metadataManager->addPropertyToEntityType($EmployeeType, "City", "String");
99
        $metadataManager->addPropertyToEntityType($EmployeeType, "Region", "String");
100
        $metadataManager->addPropertyToEntityType($EmployeeType, "PostalCode", "String");
101
        $metadataManager->addPropertyToEntityType($EmployeeType, "Country", "String");
102
        $metadataManager->addPropertyToEntityType($EmployeeType, "HomePhone", "String");
103
        $metadataManager->addPropertyToEntityType($EmployeeType, "Extension", "String");
104
        $metadataManager->addPropertyToEntityType($EmployeeType, "Photo", "Binary");
105
        $metadataManager->addPropertyToEntityType($EmployeeType, "Notes", "String");
106
        $metadataManager->addPropertyToEntityType($EmployeeType, "ReportsTo", "Int32");
107
        $metadataManager->addPropertyToEntityType($EmployeeType, "PhotoPath", "String");
108
109
        $Order_DetailType = $metadataManager->addEntityType("Order_Detail");
110
        $metadataManager->addPropertyToEntityType($Order_DetailType, "OrderID", "Int32", null, false, true);
111
        $metadataManager->addPropertyToEntityType($Order_DetailType, "ProductID", "Int32", null, false, true);
112
        $metadataManager->addPropertyToEntityType($Order_DetailType, "UnitPrice ", "Decimal");
113
        $metadataManager->addPropertyToEntityType($Order_DetailType, "Quantity", "Int16");
114
        $metadataManager->addPropertyToEntityType($Order_DetailType, "Discount", "Single");
115
116
        $OrderType = $metadataManager->addEntityType("Order");
117
        $metadataManager->addPropertyToEntityType($OrderType, "OrderID", "Int32", null, false, true, "Identity");
118
        $metadataManager->addPropertyToEntityType($OrderType, "CustomerID", "String");
119
        $metadataManager->addPropertyToEntityType($OrderType, "EmployeeID", "Int32");
120
        $metadataManager->addPropertyToEntityType($OrderType, "OrderDate", "DateTime");
121
        $metadataManager->addPropertyToEntityType($OrderType, "RequiredDate", "DateTime");
122
        $metadataManager->addPropertyToEntityType($OrderType, "ShippedDate", "DateTime");
123
        $metadataManager->addPropertyToEntityType($OrderType, "ShipVia", "DateTime");
124
        $metadataManager->addPropertyToEntityType($OrderType, "Freight", "Decimal");
125
        $metadataManager->addPropertyToEntityType($OrderType, "ShipName", "String");
126
        $metadataManager->addPropertyToEntityType($OrderType, "ShipAddress", "String");
127
        $metadataManager->addPropertyToEntityType($OrderType, "ShipCity", "String");
128
        $metadataManager->addPropertyToEntityType($OrderType, "ShipRegion", "String");
129
        $metadataManager->addPropertyToEntityType($OrderType, "ShipPostalCode", "String");
130
        $metadataManager->addPropertyToEntityType($OrderType, "ShipCountry", "String");
131
132
        $ProductType = $metadataManager->addEntityType("Product");
133
        $metadataManager->addPropertyToEntityType($ProductType, "ProductID", "Int32", null, false, true, "Identity");
134
        $metadataManager->addPropertyToEntityType($ProductType, "ProductName", "String");
135
        $metadataManager->addPropertyToEntityType($ProductType, "SupplierID", "Int32");
136
        $metadataManager->addPropertyToEntityType($ProductType, "CategoryID", "Int32");
137
        $metadataManager->addPropertyToEntityType($ProductType, "QuantityPerUnit", "String");
138
        $metadataManager->addPropertyToEntityType($ProductType, "UnitPrice", "Decimal");
139
        $metadataManager->addPropertyToEntityType($ProductType, "UnitsInStock", "Int16");
140
        $metadataManager->addPropertyToEntityType($ProductType, "UnitsOnOrder", "Int16");
141
        $metadataManager->addPropertyToEntityType($ProductType, "ReorderLevel", "Int16");
142
        $metadataManager->addPropertyToEntityType($ProductType, "Discontinued", "Boolean");
143
        $msg = null;
144
        $edmx = $metadataManager->getEdmx();
145
        $this->assertTrue($edmx->isOK($msg), $msg);
146
        $this->assertNull($msg);
147
148
        $d = $metadataManager->getEdmxXML();
149
        //die($d);
150
        $this->v3MetadataAgainstXSD($d);
151
    }
152
}
153