Exemplo n.º 1
0
    /**
     * Tests that eventual magic comments in sections are preserved in the dumped output
     */
    public function testPreserveMagicComments()
    {
        $parser = new Parser(__DIR__ . '/../resources/examples/magic_comments.cfg');
        $configuraton = $parser->parse();
        $writer = new Writer($configuraton);
        $expected = <<<EOD
# Generated with Jalle19/haphproxy
global
    # HAPHPROXY_COMMENT this is the magic comment
    daemon

EOD;
        $this->assertEquals($expected, $writer->dump());
    }
Exemplo n.º 2
0
 /**
  * This test reads each of the configuration files in resources/, dumps them to a temporary file, then tells
  * haproxy to validate it. If the process exits successfully, the test passes
  *
  * @dataProvider configurationProvider
  */
 public function testParseDump($configurationPath)
 {
     // Parse the configuration
     $parser = new Parser($configurationPath);
     $configuration = $parser->parse();
     // Dump the configuration to a temporary file
     $tempFilePath = tempnam(sys_get_temp_dir(), 'haphproxy-test');
     $writer = new Writer($configuration);
     file_put_contents($tempFilePath, $writer->dump());
     // Tell haproxy to validate the configuration and check the output of the command
     $builder = new ProcessBuilder(['haproxy', '-f', $tempFilePath, '-c']);
     $process = $builder->getProcess();
     $process->run();
     $output = $process->getOutput();
     $this->assertTrue($process->isSuccessful());
     $this->assertEquals('Configuration file is valid', trim($output));
 }