These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 |
||
0 ignored issues
–
show
|
|||
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 |
||
0 ignored issues
–
show
|
|||
49 | { |
||
50 | /** |
||
51 | * @Id |
||
52 | */ |
||
53 | public $id; |
||
54 | |||
55 | /** |
||
56 | * @Field(type="string") |
||
57 | */ |
||
58 | public $name; |
||
59 | } |
||
60 |
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.