EntityTestCase   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 11
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 66
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A tearDown() 0 9 1
B getClassesMetadata() 0 15 5
A setUp() 0 6 1
A isEntity() 0 10 3
1
<?php
2
3
namespace WebCMS\Tests;
4
5
abstract class EntityTestCase extends BasicTestCase
6
{
7
    protected $exceptions = array(
8
        'BreadcrumbsItem.php',
9
    );
10
11
    protected $tool;
12
13
    public function __construct()
14
    {
15
        parent::__construct();
16
17
        $this->tool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
18
    }
19
20
    public function setUp()
21
    {
22
        parent::setUp();
23
24
        $this->tool->createSchema($this->getClassesMetadata(__DIR__.'/../Entity', 'WebCMS\\Entity'));
25
    }
26
27
    public function tearDown()
28
    {
29
        parent::tearDown();
30
31
        $this->em->clear();
32
33
        $tool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
34
        $tool->dropDatabase();
35
    }
36
37
    /**
38
     * @param string $path
39
     * @param string $namespace
40
     */
41
    protected function getClassesMetadata($path, $namespace)
42
    {
43
        $metadata = array();
44
45
        if ($handle = opendir($path)) {
46
            while (false !== ($file = readdir($handle))) {
47
                if (strstr($file, '.php') && $this->isEntity($file)) {
48
                    list($class) = explode('.', $file);
49
                    $metadata[] = $this->em->getClassMetadata($namespace.'\\'.$class);
50
                }
51
            }
52
        }
53
54
        return $metadata;
55
    }
56
57
    /**
58
     * @param string $path
59
     */
60
    private function isEntity($path)
61
    {
62
        foreach ($this->exceptions as $exception) {
63
            if (strpos($exception, $path) !== false) {
64
                return false;
65
            }
66
        }
67
68
        return true;
69
    }
70
}
71