setUpBeforeClass()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 12

Duplication

Lines 15
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 15
loc 15
rs 9.4285
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
namespace Tpg\ExtjsBundle\Tests\Command\ODM;
3
4
use Doctrine\Bundle\MongoDBBundle\Command\CreateSchemaDoctrineODMCommand;
5
use Doctrine\Bundle\MongoDBBundle\Command\DropSchemaDoctrineODMCommand;
6
use Doctrine\ODM\MongoDB\DocumentManager;
7
use FOS\RestBundle\Routing\Loader\RestYamlCollectionLoader;
8
9
use Symfony\Bundle\FrameworkBundle\Console\Application;
10
use Symfony\Component\Console\Tester\CommandTester;
11
use Symfony\Component\Routing\Router;
12
use Test\TestBundle\Document\Order;
13
use Test\TestBundle\Document\OrderLineItem;
14
use Symfony\Bundle\FrameworkBundle\Client;
15
use Tpg\ExtjsBundle\Tests\Command\BaseTestGeneratedRestController as Base;
16
17
class BaseTestGeneratedRestController extends Base {
18
    /** @var Order[] $records */
19
    protected $records = array();
20
    /** @var \Test\TestBundle\Document\Client $clientDocument */
21
    protected $clientDocument;
22
    /** @var Client */
23
    protected $client;
24
25
    protected function setUp() {
26
        parent::setUp();
27
        $client = $this->createClient();
28
        /** @var DocumentManager $manager */
29
        $manager = $client->getContainer()->get("doctrine.odm.mongodb.document_manager");
30
        $clientDocument = new \Test\TestBundle\Document\Client();
31
        $clientDocument->setFirstName('Test')
32
            ->setLastName('Test');
33
        $manager->persist($clientDocument);
34
        $this->clientDocument = new \Test\TestBundle\Document\Client();
35
        $this->clientDocument->setFirstName('Jimmy')
36
            ->setLastName('Bob');
37
        $manager->persist($this->clientDocument);
38
        $order = new Order();
39
        $order->setName("Invoice 1")
40
            ->setTotalPrice(5.02)
41
            ->addLineItem(
42
                OrderLineItem::newInstance()
43
                    ->setProductId(1)
44
                    ->setQuantity(1)
45
                    ->setPrice(5.02)
46
                    ->setTotal(5.02)
47
            )
48
            ->setClient($clientDocument)
49
        ;
50
        $manager->persist($order);
51
        $this->records[] = $order;
52
        $order = new Order();
53
        $order->setName("Invoice 2")
54
            ->setTotalPrice(10.58)
55
            ->addLineItem(
56
                OrderLineItem::newInstance()
57
                    ->setProductId(2)
58
                    ->setQuantity(2)
59
                    ->setPrice(2.50)
60
                    ->setTotal(5.00)
61
            )
62
            ->addLineItem(
63
                OrderLineItem::newInstance()
64
                    ->setProductId(3)
65
                    ->setQuantity(1)
66
                    ->setPrice(5.58)
67
                    ->setTotal(5.58)
68
            )
69
            ->setClient($clientDocument)
70
        ;
71
        $manager->persist($order);
72
        $this->records[] = $order;
73
        $manager->flush();
74
        /** @var RestYamlCollectionLoader $loader */
75
        $loader = $client->getContainer()->get("fos_rest.routing.loader.yaml_collection");
76
        $router = $client->getContainer()->get('router');
77
        $router->getRouteCollection()->addCollection(
78
            $loader->load(__DIR__.'/../../Fixtures/Test/TestBundle/Resources/config/routing.rest.yml')
79
        );
80
        $this->client = $client;
81
    }
82
83
    protected function tearDown() {
84
        /** @var DocumentManager $manager */
85
        $manager = $this->createClient()->getContainer()->get("doctrine.odm.mongodb.document_manager");
86
        $manager->createQueryBuilder()->remove('Test\TestBundle\Document\Order')->getQuery()->execute();
87
        $manager->createQueryBuilder()->remove('Test\TestBundle\Document\Client')->getQuery()->execute();
88
        parent::tearDown();
89
    }
90
91 View Code Duplication
    public static function setUpBeforeClass() {
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...
92
        parent::setUpBeforeClass();
93
        $kernel = new \AppKernel('test', true);
94
        $app = new Application($kernel);
95
        $app->addCommands(array(
96
            new CreateSchemaDoctrineODMCommand(),
97
        ));
98
        $kernel->boot();
99
        $command = $app->find('doctrine:mongodb:schema:create');
100
        $commandTester = new CommandTester($command);
101
        $commandTester->execute(array(
102
            'command' => $command->getName(),
103
        ));
104
        $kernel->shutdown();
105
    }
106
107 View Code Duplication
    public static function tearDownAfterClass() {
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...
108
        parent::tearDownAfterClass();
109
        $kernel = new \AppKernel('test', true);
110
        $app = new Application($kernel);
111
        $app->addCommands(array(
112
            new DropSchemaDoctrineODMCommand(),
113
        ));
114
        $kernel->boot();
115
        $command = $app->find('doctrine:mongodb:schema:drop');
116
        $commandTester = new CommandTester($command);
117
        $commandTester->execute(array(
118
                'command' => $command->getName(),
119
            ));
120
        $kernel->shutdown();
121
    }
122
}