MigrationsTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createConfiguration() 0 8 1
A testMigrate() 0 12 1
1
<?php
2
namespace Doctrine\Tests\ODM\CouchDB\Functional;
3
4
use Doctrine\ODM\CouchDB\Migrations\DocumentMigration;
5
6
class MigrationsTest extends \Doctrine\Tests\ODM\CouchDB\CouchDBFunctionalTestCase
7
{
8
    public function createConfiguration($metaDriver)
9
    {
10
        $config = parent::createConfiguration($metaDriver);
11
12
        $config->setMigrations(new TestMigration());
13
14
        return $config;
15
    }
16
17
    public function testMigrate()
18
    {
19
        $documentManager = $this->createDocumentManager();
20
        $client = $documentManager->getCouchDBClient();
21
22
        $client->putDocument(array('foo' => 'bar'), 'foo'); 
23
24
        $document = $documentManager->find(__NAMESPACE__ . '\\MigrateDocument', 'foo');
25
26
        $this->assertInstanceOf(__NAMESPACE__ . '\\MigrateDocument', $document);
27
        $this->assertEquals('bar', $document->name);
28
    }
29
}
30
31
class TestMigration implements DocumentMigration
32
{
33
    public function migrate(array $data)
34
    {
35
        $data['type'] = str_replace('\\', '.', __NAMESPACE__ . '\\MigrateDocument');
36
        $data['doctrine_metadata'] = array();
37
38
        $data['name'] = $data['foo'];
39
        unset($data['foo']);
40
41
        return $data;
42
    }
43
}
44
45
/**
46
 * @Document
47
 */
48
class MigrateDocument
49
{
50
    /**
51
     * @Id
52
     */
53
    public $id;
54
55
    /**
56
     * @Field(type="string")
57
     */
58
    public $name;
59
}
60