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; |
|
|
|
|
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) |
|
|
|
|
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
|
|
|
die($d); |
59
|
|
|
$this->v3MetadataAgainstXSD($d); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.