AnnotationDriverTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 5
dl 0
loc 66
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testLoadMetadataForNonDocumentThrowsException() 0 10 1
A testGetAllClassNamesIsIdempotent() 0 10 1
A testGetAllClassNamesReturnsAlreadyLoadedClassesIfAppropriate() 0 10 1
A testGetClassNamesReturnsOnlyTheAppropriateClasses() 0 10 1
A loadDriverForCMSDocuments() 0 6 1
A loadDriver() 0 7 1
A ensureIsLoaded() 0 4 1
1
<?php
2
3
namespace Doctrine\Tests\ODM\CouchDB\Mapping;
4
5
use Doctrine\ODM\CouchDB\Mapping\ClassMetadata;
6
7
class AnnotationDriverTest extends AbstractMappingDriverTest
8
{
9
    public function testLoadMetadataForNonDocumentThrowsException()
10
    {
11
        $cm = new ClassMetadata('stdClass');
12
        $reader = new \Doctrine\Common\Annotations\SimpleAnnotationReader();
13
        $reader->addNamespace('Doctrine\ODM\CouchDB\Mapping\Annotations');
14
        $annotationDriver = new \Doctrine\ODM\CouchDB\Mapping\Driver\AnnotationDriver($reader);
15
16
        $this->setExpectedException('Doctrine\ODM\CouchDB\Mapping\MappingException');
17
        $annotationDriver->loadMetadataForClass('stdClass', $cm);
18
    }
19
20
    public function testGetAllClassNamesIsIdempotent()
21
    {
22
        $annotationDriver = $this->loadDriverForCMSDocuments();
23
        $original = $annotationDriver->getAllClassNames();
24
25
        $annotationDriver = $this->loadDriverForCMSDocuments();
26
        $afterTestReset = $annotationDriver->getAllClassNames();
27
28
        $this->assertEquals($original, $afterTestReset);
29
    }
30
31
    public function testGetAllClassNamesReturnsAlreadyLoadedClassesIfAppropriate()
32
    {
33
        $rightClassName = 'Doctrine\Tests\Models\CMS\CmsUser';
34
        $this->ensureIsLoaded($rightClassName);
35
36
        $annotationDriver = $this->loadDriverForCMSDocuments();
37
        $classes = $annotationDriver->getAllClassNames();
38
39
        $this->assertContains($rightClassName, $classes);
40
    }
41
42
    public function testGetClassNamesReturnsOnlyTheAppropriateClasses()
43
    {
44
        $extraneousClassName = 'Doctrine\Tests\Models\ECommerce\ECommerceCart';
45
        $this->ensureIsLoaded($extraneousClassName);
46
47
        $annotationDriver = $this->loadDriverForCMSDocuments();
48
        $classes = $annotationDriver->getAllClassNames();
49
50
        $this->assertNotContains($extraneousClassName, $classes);
51
    }
52
53
    protected function loadDriverForCMSDocuments()
54
    {
55
        $annotationDriver = $this->loadDriver();
56
        $annotationDriver->addPaths(array(__DIR__ . '/../../../../../Doctrine/Tests/Models/CMS'));
57
        return $annotationDriver;
58
    }
59
60
    protected function loadDriver()
61
    {
62
        $cache = new \Doctrine\Common\Cache\ArrayCache();
0 ignored issues
show
Unused Code introduced by
$cache 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...
63
        $reader = new \Doctrine\Common\Annotations\SimpleAnnotationReader();
64
        $reader->addNamespace('Doctrine\ODM\CouchDB\Mapping\Annotations');
65
        return new \Doctrine\ODM\CouchDB\Mapping\Driver\AnnotationDriver($reader);
66
    }
67
68
    protected function ensureIsLoaded($entityClassName)
69
    {
70
        new $entityClassName;
71
    }
72
}