1 | <?php |
||
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 |