Ejemplo n.º 1
0
 public function testCompileWithObject()
 {
     $compiler = new Compiler();
     $class = new \stdClass();
     $class->key = 'value';
     $data = ['key' => $class, 'key2' => 'boum'];
     $compiled = $compiler->compile($data);
     $this->assertInternalType("string", $compiled);
     $this->assertSame(0, strpos($compiled, "<?php\nreturn ["));
     $result = eval('?>' . $compiled);
     $this->assertSame(['key' => ['key' => 'value'], 'key2' => 'boum'], $result);
 }
Ejemplo n.º 2
0
 public function testCompilInDebugMode()
 {
     $configFile = __DIR__ . '/Fixtures/configuration.yml';
     $yaml = new Yaml();
     $compiler = new Compiler();
     file_put_contents($this->compiled, $compiler->compile($yaml->parse($configFile)));
     // compilation is older than config
     touch($this->compiled, time() - 2);
     touch($configFile, time() - 1);
     clearstatcache();
     $compiler = $this->getMockBuilder('Alchemy\\Phrasea\\Core\\Configuration\\Compiler')->disableOriginalConstructor()->getMock();
     $compiler->expects($this->once())->method('compile')->with(['main' => 'tiptop'])->will($this->returnValue('<?php return ["main" => "tiptop"];'));
     $yaml = $this->getMockBuilder('Symfony\\Component\\Yaml\\Yaml')->disableOriginalConstructor()->getMock();
     $yaml::staticExpects($this->once())->method('parse')->will($this->returnValue(['main' => 'tiptop']));
     $conf = $this->provideConfiguration($configFile, null, $compiler, $yaml, true);
     $this->assertSame(['main' => 'tiptop'], $conf->getConfig());
     $this->assertSame(['main' => 'tiptop'], $conf->getConfig());
     $this->assertSame(['main' => 'tiptop'], $conf->getConfig());
     $this->assertSame('tiptop', $conf['main']);
     $this->assertSame('tiptop', $conf['main']);
     $this->assertSame('tiptop', $conf['main']);
 }
Ejemplo n.º 3
0
 private function save()
 {
     $date = new \DateTime();
     $data = $this->compiler->compile($this->registry) . "\n// Last Update on " . $date->format(DATE_ISO8601) . " \n";
     file_put_contents($this->file, $data);
 }