Code Duplication    Length = 92-92 lines in 2 locations

tests/Unit/Generator/BlastGeneratorTest.php 1 location

@@ 19-110 (lines=92) @@
16
use org\bovigo\vfs\vfsStream;
17
use Blast\CoreBundle\Generator\BlastGenerator;
18
19
class BlastGeneratorTest extends TestCase
20
{
21
    /**
22
     * @var BlastGenerator
23
     */
24
    protected $object;
25
26
    private $blastFile;
27
    private $skeletonDirectory;
28
    private $modelManager;
29
30
    private $root;
31
    private $file;
32
33
    /**
34
     * @todo check if it is pertinent to cover __construct and do it(or not) in setUp
35
     * @covers \Blast\CoreBundle\Generator\BlastGenerator::__construct
36
     */
37
    protected function setUp()
38
    {
39
        // As blast.yml is modified by the test
40
        $this->root = vfsStream::setup('BlastTestRessources');
41
        $this->file = vfsStream::newFile('blast.yml');
42
        $this->root->addChild($this->file);
43
44
        /*
45
         *   @todo test with and/or without original content
46
         */
47
        $this->file->setContent(file_get_contents('src/Resources/config/blast.yml'));
48
49
        $this->blastFile = vfsStream::url('BlastTestRessources/blast.yml');
50
51
        /*
52
         * @todo check if it should be tested with other skeleton
53
         */
54
55
        $this->skeletonDirectory = 'src/Resources/skeleton';
56
57
        // Sonata Model Manager is used to launch getExportFields
58
        // from the method addResource in Blast\CoreBundle\Generator\BlastGenerator
59
        // $managerType =  'sonata.admin.manager.orm';
60
        $modelManagerMock = $this->getMockForAbstractClass('Sonata\AdminBundle\Model\ModelManagerInterface');
61
62
        $map = [
63
            ['Model', ['foo', 'bar', 'not_an_id']],
64
            ['Ledom', ['id', 'zoo', 'rab']],
65
         ];
66
        $modelManagerMock
67
             ->expects($this->any())
68
             ->method('getExportFields')
69
             ->will($this->returnValueMap($map));
70
71
        $this->modelManager = $modelManagerMock;
72
        $this->object = new BlastGenerator(
73
             $this->blastFile,
74
             $this->modelManager,
75
             $this->skeletonDirectory
76
         );
77
    }
78
79
    protected function tearDown()
80
    {
81
    }
82
83
    /**
84
     * @covers \Blast\CoreBundle\Generator\BlastGenerator::addResource
85
     */
86
    public function testAddResource()
87
    {
88
        $this->assertFileExists($this->blastFile);
89
90
        $this->object->AddResource('Model');
91
        $this->object->AddResource('Ledom');
92
93
        $content = $this->file->getContent();
94
95
        // Model
96
        $this->assertContains('blast', $content);
97
        $this->assertContains('foo: ~', $content);
98
        $this->assertContains('Model:', $content);
99
100
        // Ledom
101
        $this->assertContains('Ledom:', $content);
102
103
        /*
104
         * @todo should be test for '#id: ~' when content is generated by sequence like ORM\GeneratedValue(strategy="AUTO")
105
         */
106
        $this->assertContains('id: ~', $content);
107
108
        // echo  $this->file->getContent();
109
    }
110
}
111

Tests/Unit/Generator/BlastGeneratorTest.php 1 location

@@ 19-110 (lines=92) @@
16
use org\bovigo\vfs\vfsStream;
17
use Blast\Bundle\CoreBundle\Generator\BlastGenerator;
18
19
class BlastGeneratorTest extends TestCase
20
{
21
    /**
22
     * @var BlastGenerator
23
     */
24
    protected $object;
25
26
    private $blastFile;
27
    private $skeletonDirectory;
28
    private $modelManager;
29
30
    private $root;
31
    private $file;
32
33
    /**
34
     * @todo check if it is pertinent to cover __construct and do it(or not) in setUp
35
     * @covers \Blast\Bundle\CoreBundle\Generator\BlastGenerator::__construct
36
     */
37
    protected function setUp()
38
    {
39
        // As blast.yml is modified by the test
40
        $this->root = vfsStream::setup('BlastTestRessources');
41
        $this->file = vfsStream::newFile('blast.yml');
42
        $this->root->addChild($this->file);
43
44
        /*
45
         *   @todo test with and/or without original content
46
         */
47
        $this->file->setContent(file_get_contents('src/Resources/config/blast.yml'));
48
49
        $this->blastFile = vfsStream::url('BlastTestRessources/blast.yml');
50
51
        /*
52
         * @todo check if it should be tested with other skeleton
53
         */
54
55
        $this->skeletonDirectory = 'src/Resources/skeleton';
56
57
        // Sonata Model Manager is used to launch getExportFields
58
        // from the method addResource in Blast\Bundle\CoreBundle\Generator\BlastGenerator
59
        // $managerType =  'sonata.admin.manager.orm';
60
        $modelManagerMock = $this->getMockForAbstractClass('Sonata\AdminBundle\Model\ModelManagerInterface');
61
62
        $map = [
63
            ['Model', ['foo', 'bar', 'not_an_id']],
64
            ['Ledom', ['id', 'zoo', 'rab']],
65
         ];
66
        $modelManagerMock
67
             ->expects($this->any())
68
             ->method('getExportFields')
69
             ->will($this->returnValueMap($map));
70
71
        $this->modelManager = $modelManagerMock;
72
        $this->object = new BlastGenerator(
73
             $this->blastFile,
74
             $this->modelManager,
75
             $this->skeletonDirectory
76
         );
77
    }
78
79
    protected function tearDown()
80
    {
81
    }
82
83
    /**
84
     * @covers \Blast\Bundle\CoreBundle\Generator\BlastGenerator::addResource
85
     */
86
    public function testAddResource()
87
    {
88
        $this->assertFileExists($this->blastFile);
89
90
        $this->object->AddResource('Model');
91
        $this->object->AddResource('Ledom');
92
93
        $content = $this->file->getContent();
94
95
        // Model
96
        $this->assertContains('blast', $content);
97
        $this->assertContains('foo: ~', $content);
98
        $this->assertContains('Model:', $content);
99
100
        // Ledom
101
        $this->assertContains('Ledom:', $content);
102
103
        /*
104
         * @todo should be test for '#id: ~' when content is generated by sequence like ORM\GeneratedValue(strategy="AUTO")
105
         */
106
        $this->assertContains('id: ~', $content);
107
108
        // echo  $this->file->getContent();
109
    }
110
}
111