<?php
-
-require_once 'application/config/ConfigPhp.php';
+namespace Shaarli\Config;
/**
* Class ConfigPhpTest
+ *
+ * We run tests in separate processes due to the usage for $GLOBALS
+ * which are kept between tests.
+ * @runTestsInSeparateProcesses
*/
-class ConfigPhpTest extends PHPUnit_Framework_TestCase
+class ConfigPhpTest extends \Shaarli\TestCase
{
/**
* @var ConfigPhp
*/
protected $configIO;
- public function setUp()
+ protected function setUp(): void
{
$this->configIO = new ConfigPhp();
}
*/
public function testRead()
{
- $conf = $this->configIO->read('tests/config/php/configOK');
+ $conf = $this->configIO->read('tests/utils/config/configPhp.php');
$this->assertEquals('root', $conf['login']);
$this->assertEquals('lala', $conf['redirector']);
$this->assertEquals('data/datastore.php', $conf['config']['DATASTORE']);
$this->assertEquals(array(), $this->configIO->read('nope'));
}
+ /**
+ * Read an empty existent config file -> array with blank default values.
+ */
+ public function testReadEmpty()
+ {
+ $dataFile = 'tests/utils/config/emptyConfigPhp.php';
+ $conf = $this->configIO->read($dataFile);
+ $this->assertEmpty($conf['login']);
+ $this->assertEmpty($conf['title']);
+ $this->assertEmpty($conf['titleLink']);
+ $this->assertEmpty($conf['config']);
+ $this->assertEmpty($conf['plugins']);
+ }
+
/**
* Write a new config file.
*/
public function testWriteNew()
{
- $dataFile = 'tests/config/php/configWrite';
+ $dataFile = 'tests/utils/config/configWrite.php';
$data = array(
'login' => 'root',
'redirector' => 'lala',
$GLOBALS[\'config\'][\'DATASTORE\'] = \'data/datastore.php\';
$GLOBALS[\'plugins\'][\'WALLABAG_VERSION\'] = \'1\';
';
- $this->assertEquals($expected, file_get_contents($dataFile .'.php'));
- unlink($dataFile .'.php');
+ $this->assertEquals($expected, file_get_contents($dataFile));
+ unlink($dataFile);
}
/**
*/
public function testOverwrite()
{
- $source = 'tests/config/php/configOK.php';
- $dest = 'tests/config/php/configOverwrite';
- copy($source, $dest . '.php');
+ $source = 'tests/utils/config/configPhp.php';
+ $dest = 'tests/utils/config/configOverwrite.php';
+ copy($source, $dest);
$conf = $this->configIO->read($dest);
$conf['redirector'] = 'blabla';
$this->configIO->write($dest, $conf);
$conf = $this->configIO->read($dest);
$this->assertEquals('blabla', $conf['redirector']);
- unlink($dest .'.php');
+ unlink($dest);
}
}