MongoGeneratorServiceTest::testEmbeddedDocument()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 2
eloc 11
nc 2
nop 0
1
<?php
2
namespace Tpg\ExtjsBundle\Tests\Service;
3
4
use Doctrine\Common\Annotations\AnnotationReader;
5
use Test\TestBundle\Mockup\TwigEngineMokcup;
6
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
7
use Tpg\ExtjsBundle\Service\GeneratorService;
8
9
class MongoGeneratorServiceTest extends TestCase {
10
    /** @var GeneratorService */
11
    protected $service;
12
13
    /** @var TwigEngineMokcup */
14
    protected $twigEngine;
15
16
    protected function setUp() {
17
        parent::setUp();
18
        $this->service = new GeneratorService();
19
        $this->service->setAnnotationReader(new AnnotationReader());
20
        $this->twigEngine = new TwigEngineMokcup();
21
        $this->service->setTwigEngine($this->twigEngine);
22
    }
23
24 View Code Duplication
    public function testDocumentProperty() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
        $this->service->generateMarkupForEntity('Test\TestBundle\Document\Order');
26
        $this->assertContains("Test.document.Order", $this->twigEngine->renderParameters['name']);
27
        $fieldsName = array();
28
        foreach ($this->twigEngine->renderParameters['fields'] as $field) {
29
            $fieldsName[] = $field['name'];
30
        }
31
        $this->assertContains("id", $fieldsName);
32
        $this->assertContains("name", $fieldsName);
33
        $this->assertContains("totalPrice", $fieldsName);
34
    }
35
36 View Code Duplication
    public function testDocumentPropertyType() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
        $this->service->generateMarkupForEntity('Test\TestBundle\Document\Order');
38
        $fieldsType = array();
39
        foreach ($this->twigEngine->renderParameters['fields'] as $field) {
40
            $fieldsType[$field['name']] = $field['type'];
41
        }
42
        $this->assertEquals("string", $fieldsType['id']);
43
        $this->assertEquals("string", $fieldsType['name']);
44
        $this->assertContains("float", $fieldsType['totalPrice']);
45
    }
46
47
    public function testEmbeddedDocument() {
48
        $this->service->generateMarkupForEntity('Test\TestBundle\Document\Order');
49
        $associations = array();
50
        foreach ($this->twigEngine->renderParameters['associations'] as $assoc) {
51
            $associations[$assoc['name']] = $assoc;
52
        }
53
        $this->assertEquals('Test.document.OrderLineItem', $associations['lineItems']['model']);
54
        $this->assertEquals('lineItems', $associations['lineItems']['name']);
55
        $this->assertEquals('EmbedMany', $associations['lineItems']['type']);
56
        $this->assertEquals('Test.document.OrderLineItem', $associations['lastLineItem']['model']);
57
        $this->assertEquals('lastLineItem', $associations['lastLineItem']['name']);
58
        $this->assertEquals('EmbedOne', $associations['lastLineItem']['type']);
59
    }
60
61
    public function testReferenceDocument() {
62
        $this->service->generateMarkupForEntity('Test\TestBundle\Document\Client');
63
        $associations = array();
64
        foreach ($this->twigEngine->renderParameters['associations'] as $assoc) {
65
            $associations[$assoc['name']] = $assoc;
66
        }
67
        $this->assertEquals('Test.document.Order', $associations['orders']['model']);
68
        $this->assertEquals('orders', $associations['orders']['name']);
69
        $this->assertEquals('ReferenceMany', $associations['orders']['type']);
70
71
        $this->service->generateMarkupForEntity('Test\TestBundle\Document\Order');
72
        $associations = array();
73
        foreach ($this->twigEngine->renderParameters['associations'] as $assoc) {
74
            $associations[$assoc['name']] = $assoc;
75
        }
76
        $this->assertEquals('Test.document.Client', $associations['client']['model']);
77
        $this->assertEquals('client', $associations['client']['name']);
78
        $this->assertEquals('ReferenceOne', $associations['client']['type']);
79
80
    }
81
}