PHP Classes

File: specs/.common.php

Recommend this page to a friend!
  Classes of Daniele Orlando   FluidXML   specs/.common.php   Download  
File: specs/.common.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: FluidXML
Manipulate XML documents using a fluent interface
Author: By
Last change: The biggest commit since the 1.0 release.

This is a major step forward breaking compatibility with the past.
Under the hood there is a general reorganization to be PSR-0/4 compliant,
a general cleanup of the API names for being consistent and allowing future
clean APIs growth, some notable additions like the ->filter() method to
programmatically filter the query results and ->html() to output the document
as valid HTML 5 string.

[+] New:
* ->html() is part of the family.
* ->filter() is part of the family.
* ->comment() is part of the family.
* ->setComment() is part of the family.
* ->addComment() is part of the family.
* ->size() is an alias of ->length().
* ->__invoke() is an alias of ->query().
* ->__toString() is an alias of ->xml().
* ->array() replaces ->asArray().
* ->addChild() replaces ->appendChild().
* ->addText() replaces ->appendText().
* ->addCdata() replaces ->appendCdata().

[~] Changed:
* fluidxml() has gained the super powers of fluidify().
* FluidXml->__construct() has gained the super powers of FluidXml::load().
* ::load()/fluidify() can be ONLY used to load an XML file.

[-] Removed:
* ->asArray() has been removed superseded by ->array().
* ->appendText() has been removed superseded by ->addText().
* ->appendCdata() has been removed superseded by ->addCdata().
* ->appendChild() has been removed superseded by ->addChild().
* ->insertSiblingBefore() has been removed superseded by ->prependSibling().
* ->insertSiblingAfter() has been removed superseded by ->appendSibling().

[@] Internal:
* PSR-0/4 compliance.
* FluidXml.php is still there for people not using Composer/PSR-0/4 loaders.
Internal refactoring and performance regression fix.

* [@] internal refactoring. Performances are normal.
FluidContext refactoring.
Date: 8 years ago
Size: 1,633 bytes
 

Contents

Class file image Download
<?php

$ds
= \DIRECTORY_SEPARATOR;
$source_dir = __DIR__ . "{$ds}..{$ds}source";
\
set_include_path($source_dir . \PATH_SEPARATOR . \get_include_path());

use \
FluidXml\FluidXml;
use \
FluidXml\FluidInterface;

function
__($actual, $expected)
{
       
$v = [ 'actual' => \var_export($actual, true),
              
'expected' => \var_export($expected, true) ];

       
$sep = ' ';
       
$msg_l = \strlen($v['actual'] . $v['expected']);

        if (
$msg_l > 60) {
               
$sep = "\n";
        }

        return
"expected " . $v['expected'] . ",$sep"
              
. "given " . $v['actual'] . ".";
}

function
assert_equal_xml($actual, $expected)
{
       
$xml_header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

       
$actual = \trim($actual->xml());
       
$expected = \trim($xml_header . $expected);
        \
assert($actual === $expected, __($actual, $expected));
}

function
assert_is_a($actual, $expected)
{
        \
assert(\is_a($actual, $expected) === true, __(\get_class($actual), $expected));
}

function
assert_is_fluid($method, ...$args)
{
       
$instance = new FluidXml();

        if (\
method_exists($instance, $method)) {
               
$actual = \call_user_func([$instance, $method], ...$args);
               
$expected = FluidInterface::class;
               
assert_is_a($actual, $expected);
        }

       
$instance = $instance->query('/*');

        if (\
method_exists($instance, $method)) {
               
$actual = \call_user_func([$instance, $method], ...$args);
               
$expected = FluidInterface::class;
               
assert_is_a($actual, $expected);
        }
}