Example #1
0
 public function testValidConfig()
 {
     $config = new Config();
     $config->load(__DIR__ . DS . 'config.test.php');
     $this->assertInstanceOf('T4\\Core\\Std', $config->db);
     $this->assertInstanceOf('T4\\Core\\Std', $config);
     $this->assertEquals('mysql', $config->db->default->driver);
     $this->assertEquals('localhost', $config->db->default->host);
     $this->assertEquals('test', $config->name);
 }
Example #2
0
    public function testSave()
    {
        $config = new Config();
        $config->load(self::TEST_CONFIG_FILE);
        $config->db->default = 42;
        $config->save();
        $expected = <<<FILE
<?php

return [
  'db' =>
  [
    'default' => 42,
  ],
  'name' => 'test',
];
FILE;
        $expected = str_replace(["\r\n", "\r", "\n"], '', $expected);
        $this->assertEquals($expected, str_replace(["\r\n", "\r", "\n"], '', file_get_contents(self::TEST_CONFIG_FILE)));
    }
Example #3
0
    public function testSave()
    {
        $config = new Config(__DIR__ . '/savetest.config.php');
        $this->assertEquals('Test Application', $config->application->name);
        $config->foo = 'bar';
        $config->baz = [1, 2, 3];
        $config->songs = ['Hey' => 'Jude', 'I just' => ['call' => ['to' => 'say']]];
        $config->save();
        $expectedText = <<<'CONFIG'
<?php

return [
  'application' =>
  [
    'name' => 'Test Application',
  ],
  'foo' => 'bar',
  'baz' =>
  [
    0 => 1,
    1 => 2,
    2 => 3,
  ],
  'songs' =>
  [
    'Hey' => 'Jude',
    'I just' =>
    [
      'call' =>
      [
        'to' => 'say',
      ],
    ],
  ],
];
CONFIG;
        $this->assertEquals(str_replace("\r\n", "\n", $expectedText), str_replace("\r\n", "\n", file_get_contents(__DIR__ . '/savetest.config.php')));
    }