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