Exemple #1
0
    public function testCreatingConfiguration()
    {
        $config = new Statement\Configuration();
        $config->addStatement(new Statement\Comment('Sample file'));
        $config->addStatement(new Statement\Comment('Global settings', '#'));
        $config->addStatement(new Statement\Property('foo', 'bar'));
        $config->addStatement(new Statement\Property('gazonk', 'fnord'));
        $config->addStatement(new Statement\EmptyLine());
        $config->addStatement(new Statement\Section('omega'));
        $config->addStatement(new Statement\Property('alpha', 'beta'));
        $config->addStatement(new Statement\Property('kappa', 'gamma', ':'));
        $writer = new Ini\Writer();
        $file = fopen('php://memory', 'w+');
        $writer->write($config, $file);
        rewind($file);
        $expected = <<<EOT
; Sample file
# Global settings
foo = bar
gazonk = fnord

[omega]
alpha = beta
kappa : gamma

EOT;
        $this->assertSame($expected, stream_get_contents($file));
        fclose($file);
    }
Exemple #2
0
 public function testAddAndRemoveStatementsToConfiguration()
 {
     $global = new Statement\Configuration();
     $configuration = new Statement\Configuration();
     $comment = new Statement\Comment('A Comment');
     $empty = new Statement\EmptyLine();
     $property = new Statement\Property('height', 11);
     $section = new Statement\Section('general');
     try {
         $global->addStatement($configuration);
     } catch (\LogicException $e) {
         // Expected
     }
     $global->addStatement($comment);
     $global->addStatement($empty);
     $global->addStatement($property);
     $global->addStatement($section);
     $total = 4;
     $this->assertSame($total, count($global));
     foreach ($global as $statement) {
         $global->removeStatement($statement);
         $this->assertSame(--$total, count($global));
     }
 }