TestCase   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 7

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 7
dl 0
loc 107
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 22 1
A setUp() 0 6 2
A getClassMetadataFactory() 0 20 1
A getMigratorFileName() 0 9 1
A versionToDirectory() 0 7 1
1
<?php
2
3
/**
4
 * This file is part of the Cubiche/EventSourcing component.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Cubiche\Domain\EventSourcing\Tests\Units;
12
13
use Cubiche\Core\Metadata\ClassMetadataFactory;
14
use Cubiche\Domain\EventSourcing\Metadata\Driver\AnnotationDriver;
15
use Cubiche\Domain\EventSourcing\Versioning\Version;
16
use Cubiche\Tests\TestCase as BaseTestCase;
17
use Doctrine\Common\Annotations\AnnotationReader;
18
use Doctrine\Common\Annotations\AnnotationRegistry;
19
use Doctrine\Common\Annotations\CachedReader;
20
use Doctrine\Common\Cache\FilesystemCache;
21
use mageekguy\atoum\adapter as Adapter;
22
use mageekguy\atoum\annotations\extractor as Extractor;
23
use mageekguy\atoum\asserter\generator as Generator;
24
use mageekguy\atoum\test\assertion\manager as Manager;
25
use mageekguy\atoum\tools\variable\analyzer as Analyzer;
26
27
/**
28
 * TestCase class.
29
 *
30
 * Generated by TestGenerator on 2016-06-28 at 14:36:54.
31
 */
32
abstract class TestCase extends BaseTestCase
33
{
34
    /**
35
     * @var string
36
     */
37
    protected $migrationsDirectory;
38
39
    /**
40
     * @var string
41
     */
42
    protected $cacheDirectory;
43
44
    /**
45
     * @param Adapter   $adapter
46
     * @param Extractor $annotationExtractor
47
     * @param Generator $asserterGenerator
48
     * @param Manager   $assertionManager
49
     * @param \Closure  $reflectionClassFactory
50
     * @param \Closure  $phpExtensionFactory
51
     * @param Analyzer  $analyzer
52
     */
53
    public function __construct(
54
        Adapter $adapter = null,
55
        Extractor $annotationExtractor = null,
56
        Generator $asserterGenerator = null,
57
        Manager $assertionManager = null,
58
        \Closure $reflectionClassFactory = null,
59
        \Closure $phpExtensionFactory = null,
60
        Analyzer $analyzer = null
61
    ) {
62
        parent::__construct(
63
            $adapter,
64
            $annotationExtractor,
65
            $asserterGenerator,
66
            $assertionManager,
67
            $reflectionClassFactory,
68
            $phpExtensionFactory,
69
            $analyzer
70
        );
71
72
        $this->migrationsDirectory = __DIR__.'/Migrations/Cli/Migrations';
73
        $this->cacheDirectory = __DIR__.'/Migrations/Cache';
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function setUp()
80
    {
81
        if (is_dir($this->migrationsDirectory)) {
82
            system('rm -rf '.escapeshellarg($this->migrationsDirectory));
83
        }
84
    }
85
86
    /**
87
     * @return ClassMetadataFactory
88
     */
89
    protected function getClassMetadataFactory()
90
    {
91
        $reader = new CachedReader(
92
            new AnnotationReader(),
93
            new FilesystemCache($this->cacheDirectory),
94
            $debug = true
95
        );
96
97
        AnnotationRegistry::registerFile(
98
            __DIR__.'/../../Metadata/Annotations/Migratable.php'
99
        );
100
101
        $driver = new AnnotationDriver($reader, [__DIR__.'/../Fixtures']);
102
        $driver->addExcludePaths([
103
            __DIR__.'/../Fixtures/Event',
104
            __DIR__.'/../Fixtures/Listener',
105
        ]);
106
107
        return new ClassMetadataFactory($driver);
108
    }
109
110
    /**
111
     * @param string  $aggregateClassName
112
     * @param Version $version
113
     *
114
     * @return string
115
     */
116
    protected function getMigratorFileName($aggregateClassName, Version $version)
117
    {
118
        return sprintf(
119
            '%s/%s/%s',
120
            $this->migrationsDirectory,
121
            $this->versionToDirectory($version),
122
            str_replace('\\', '/', $aggregateClassName).'Migration.php'
123
        );
124
    }
125
126
    /**
127
     * @param Version $version
128
     *
129
     * @return string
130
     */
131
    protected function versionToDirectory(Version $version)
132
    {
133
        return sprintf(
134
            'V%s',
135
            str_replace('.', '_', $version->__toString())
136
        );
137
    }
138
}
139