Completed
Push — wip-platform ( 442c75...159b0f )
by
unknown
02:42
created

BlastGeneratorTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * Copyright (C) 2015-2017 Libre Informatique
5
 *
6
 * This file is licenced under the GNU LGPL v3.
7
 * For the full copyright and license information, please view the LICENSE.md
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Blast\Bundle\CoreBundle\Tests\Unit\Generator;
12
13
use PHPUnit\Framework\TestCase;
14
use org\bovigo\vfs\vfsStream;
15
use Blast\Bundle\CoreBundle\Generator\BlastGenerator;
16
17
class BlastGeneratorTest extends TestCase
18
{
19
    /**
20
     * @var BlastGenerator
21
     */
22
    protected $object;
23
24
    private $blastFile;
25
    private $skeletonDirectory;
26
    private $modelManager;
27
28
    private $root;
29
    private $file;
30
31
    /**
32
     * @todo check if it is pertinent to cover __construct and do it(or not) in setUp
33
     * @covers \Blast\Bundle\CoreBundle\Generator\BlastGenerator::__construct
34
     */
35
    protected function setUp()
36
    {
37
        // As blast.yml is modified by the test
38
        $this->root = vfsStream::setup('BlastTestRessources');
39
        $this->file = vfsStream::newFile('blast.yml');
40
        $this->root->addChild($this->file);
41
42
        /*
43
         *   @todo test with and/or without original content
44
         */
45
        $this->file->setContent(file_get_contents(__DIR__ . '/../../../Resources/config/blast.yml'));
46
47
        $this->blastFile = vfsStream::url('BlastTestRessources/blast.yml');
48
49
        /*
50
         * @todo check if it should be tested with other skeleton
51
         */
52
53
        $this->skeletonDirectory = __DIR__ . '/../../../Resources/skeleton';
54
55
        // Sonata Model Manager is used to launch getExportFields
56
        // from the method addResource in Blast\Bundle\CoreBundle\Generator\BlastGenerator
57
        // $managerType =  'sonata.admin.manager.orm';
58
        $modelManagerMock = $this->getMockForAbstractClass('Sonata\AdminBundle\Model\ModelManagerInterface');
59
60
        $map = [
61
            ['Model', ['foo', 'bar', 'not_an_id']],
62
            ['Ledom', ['id', 'zoo', 'rab']],
63
         ];
64
        $modelManagerMock
65
             ->expects($this->any())
66
             ->method('getExportFields')
67
             ->will($this->returnValueMap($map));
68
69
        $this->modelManager = $modelManagerMock;
70
        $this->object = new BlastGenerator(
71
            $this->blastFile,
72
            $this->modelManager,
73
            $this->skeletonDirectory
74
        );
75
    }
76
77
    protected function tearDown()
78
    {
79
    }
80
81
    /**
82
     * @covers \Blast\Bundle\CoreBundle\Generator\BlastGenerator::addResource
83
     */
84
    public function testAddResource()
85
    {
86
        $this->assertFileExists($this->blastFile);
87
88
        $this->object->AddResource('Model');
89
        $this->object->AddResource('Ledom');
90
91
        $content = $this->file->getContent();
92
93
        // Model
94
        $this->assertContains('blast', $content);
95
        $this->assertContains('foo: ~', $content);
96
        $this->assertContains('Model:', $content);
97
98
        // Ledom
99
        $this->assertContains('Ledom:', $content);
100
101
        /*
102
         * @todo should be test for '#id: ~' when content is generated by sequence like ORM\GeneratedValue(strategy="AUTO")
103
         */
104
        $this->assertContains('id: ~', $content);
105
106
        // echo  $this->file->getContent();
107
    }
108
}
109