tienvx/pact-php-xml

This package is abandoned and no longer maintained. No replacement package was suggested.

Add XML Support For Pact PHP

v0.1.0 2023-10-13 14:46 UTC

This package is auto-updated.

Last update: 2024-01-10 01:48:47 UTC


README

This library contains classes support xml for Pact PHP.

Installation

composer require tienvx/pact-php-xml

Usage

<?php

require_once 'vendor/autoload.php';

use AaronDDM\XMLBuilder\Exception\XMLBuilderException;
use PhpPact\Consumer\Matcher;
use Tienvx\PactPhpXml\Model\Options;
use Tienvx\PactPhpXml\XmlBuilder;

$builder = new XmlBuilder();
$matcher = new Matcher();

try {
    $builder
        ->root(
            $builder->name('ns1:projects'),
            $builder->attribute('id', '1234'),
            $builder->attribute('xmlns:ns1', 'http://some.namespace/and/more/stuff'),
            $builder->add(
                $builder->eachLike(examples: 2),
                $builder->name('ns1:project'),
                $builder->attribute('id', $matcher->integerV3(1)),
                $builder->attribute('type', 'activity'),
                $builder->attribute('name', $matcher->string('Project 1')),
                $builder->attribute('due', $matcher->datetime("yyyy-MM-dd'T'HH:mm:ss.SZ", '2016-02-11T09:46:56.023Z')),
                $builder->add(
                    $builder->name('ns1:tasks'),
                    $builder->add(
                        $builder->eachLike(examples: 5),
                        $builder->name('ns1:task'),
                        $builder->attribute('id', $matcher->integerV3(1)),
                        $builder->attribute('name', $matcher->string('Task 1')),
                        $builder->attribute('done', $matcher->boolean()),
                    ),
                ),
            ),
        );

    var_dump($builder->getArray());
} catch (XMLBuilderException $e) {
    var_dump('An exception occurred: ' . $e->getMessage());
}

License

MIT