]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - tests/config/ConfigJsonTest.php
namespacing: \Shaarli\Exceptions\IOException
[github/shaarli/Shaarli.git] / tests / config / ConfigJsonTest.php
index 5b3bce46559b03365f1fe20a99c2e5bb4e2f12e0..99c1ea569c00deb9b6c8bb49898b03517171623d 100644 (file)
@@ -1,11 +1,10 @@
 <?php
-
-require_once 'application/config/ConfigJson.php';
+namespace Shaarli\Config;
 
 /**
  * Class ConfigJsonTest
  */
-class ConfigJsonTest extends PHPUnit_Framework_TestCase
+class ConfigJsonTest extends \PHPUnit_Framework_TestCase
 {
     /**
      * @var ConfigJson
@@ -23,9 +22,9 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase
     public function testRead()
     {
         $conf = $this->configIO->read('tests/utils/config/configJson.json.php');
-        $this->assertEquals('root', $conf['login']);
-        $this->assertEquals('lala', $conf['redirector']);
-        $this->assertEquals('data/datastore.php', $conf['config']['DATASTORE']);
+        $this->assertEquals('root', $conf['credentials']['login']);
+        $this->assertEquals('lala', $conf['redirector']['url']);
+        $this->assertEquals('tests/utils/config/datastore.php', $conf['resource']['datastore']);
         $this->assertEquals('1', $conf['plugins']['WALLABAG_VERSION']);
     }
 
@@ -40,8 +39,8 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase
     /**
      * Read a non existent config file -> empty array.
      *
-     * @expectedException Exception
-     * @expectedExceptionMessage An error occured while parsing JSON file: error code #4
+     * @expectedException \Exception
+     * @expectedExceptionMessageRegExp  /An error occurred while parsing JSON configuration file \([\w\/\.]+\): error code #4/
      */
     public function testReadInvalidJson()
     {
@@ -55,10 +54,14 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase
     {
         $dataFile = 'tests/utils/config/configWrite.json.php';
         $data = array(
-            'login' => 'root',
-            'redirector' => 'lala',
-            'config' => array(
-                'DATASTORE' => 'data/datastore.php',
+            'credentials' => array(
+                'login' => 'root',
+            ),
+            'resource' => array(
+                'datastore' => 'data/datastore.php',
+            ),
+            'redirector' => array(
+                'url' => 'lala',
             ),
             'plugins' => array(
                 'WALLABAG_VERSION' => '1',
@@ -68,19 +71,23 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase
         // PHP 5.3 doesn't support json pretty print.
         if (defined('JSON_PRETTY_PRINT')) {
             $expected = '{
-    "login": "root",
-    "redirector": "lala",
-    "config": {
-        "DATASTORE": "data\/datastore.php"
+    "credentials": {
+        "login": "root"
+    },
+    "resource": {
+        "datastore": "data\/datastore.php"
+    },
+    "redirector": {
+        "url": "lala"
     },
     "plugins": {
         "WALLABAG_VERSION": "1"
     }
 }';
         } else {
-            $expected = '{"login":"root","redirector":"lala","config":{"DATASTORE":"data\/datastore.php"},"plugins":{"WALLABAG_VERSION":"1"}}';
+            $expected = '{"credentials":{"login":"root"},"resource":{"datastore":"data\/datastore.php"},"redirector":{"url":"lala"},"plugins":{"WALLABAG_VERSION":"1"}}';
         }
-        $expected = ConfigJson::$PHP_HEADER . $expected;
+        $expected = ConfigJson::getPhpHeaders() . $expected . ConfigJson::getPhpSuffix();
         $this->assertEquals($expected, file_get_contents($dataFile));
         unlink($dataFile);
     }
@@ -94,17 +101,17 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase
         $dest = 'tests/utils/config/configOverwrite.json.php';
         copy($source, $dest);
         $conf = $this->configIO->read($dest);
-        $conf['redirector'] = 'blabla';
+        $conf['redirector']['url'] = 'blabla';
         $this->configIO->write($dest, $conf);
         $conf = $this->configIO->read($dest);
-        $this->assertEquals('blabla', $conf['redirector']);
+        $this->assertEquals('blabla', $conf['redirector']['url']);
         unlink($dest);
     }
 
     /**
      * Write to invalid path.
      *
-     * @expectedException IOException
+     * @expectedException \Shaarli\Exceptions\IOException
      */
     public function testWriteInvalidArray()
     {
@@ -115,7 +122,7 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase
     /**
      * Write to invalid path.
      *
-     * @expectedException IOException
+     * @expectedException \Shaarli\Exceptions\IOException
      */
     public function testWriteInvalidBlank()
     {