Esempio n. 1
0
 public function testParseAndDump()
 {
     $data = array('lorem' => 'ipsum', 'dolor' => 'sit');
     $yml = Yaml::dump($data);
     $parsed = Yaml::parse($yml);
     $this->assertEquals($data, $parsed);
     $filename = __DIR__ . '/Fixtures/index.yml';
     $contents = file_get_contents($filename);
     $parsedByFilename = Yaml::parse($filename);
     $parsedByContents = Yaml::parse($contents);
     $this->assertEquals($parsedByFilename, $parsedByContents);
 }
Esempio n. 2
0
 /**
  *
  * the function returns a parsed array of a yaml file
  *
  * @param String $fileName
  *
  * @return array
  */
 public static function yamlParseFile($fileName)
 {
     //setting rootPath
     $upperFolders = 2;
     $scriptName = basename(__FILE__);
     $rootPath = str_replace(DIRECTORY_SEPARATOR . $scriptName, '', __FILE__);
     for ($i = 0; $i < $upperFolders; $i++) {
         $postition = strrpos($rootPath, DIRECTORY_SEPARATOR);
         $rootPath = substr($rootPath, 0, $postition);
     }
     $rootPath = $rootPath . DIRECTORY_SEPARATOR;
     //checking rootpath
     if (file_exists($rootPath . $fileName)) {
         //returning parsed yaml file
         return Yaml::parse($rootPath . $fileName);
     } elseif (file_exists(__DIR__ . '/../' . $fileName)) {
         //returning parsed yaml file
         return Yaml::parse(__DIR__ . '/../' . $fileName);
     } else {
         //throw Exception
         die("File doesn't exist or Rootpath is wrong");
     }
 }
Esempio n. 3
0
    public function testNestedFoldedStringBlockWithComments()
    {
        $this->assertEquals(array(array('title' => 'some title', 'content' => <<<EOT
# comment 1
header

    # comment 2
    <body>
        <h1>title</h1>
    </body>

footer # comment3
EOT
)), Yaml::parse(<<<EOF
-
    title: some title
    content: |
        # comment 1
        header

            # comment 2
            <body>
                <h1>title</h1>
            </body>

        footer # comment3
EOF
));
    }