File: tests/UtilsTest.php

Recommend this page to a friend!
  Classes of WsdlToPhp  >  Package Base  >  tests/UtilsTest.php  >  Download  
File: tests/UtilsTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: Package Base
Base classes for implementing a package generator
Author: By
Last change: issue #32 - ensure PHP => 8.0.0 tests compatibility
issue #32 - migrate to PHP >= 7.4
Date: 1 month ago
Size: 2,289 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

namespace
WsdlToPhp\PackageBase\Tests;

use
DOMDocument;
use
InvalidArgumentException;
use
ValueError;
use
WsdlToPhp\PackageBase\Utils;

class
UtilsTest extends TestCase
{
    public function
testGetFormattedXmlAsString()
    {
       
$this->assertEquals(file_get_contents(__DIR__ . '/resources/formated.xml'), Utils::getFormattedXml(file_get_contents(__DIR__ . '/resources/oneline.xml')));
    }

    public function
testGetFormattedXmlAsDomDocument()
    {
       
$this->assertInstanceOf(DOMDocument::class, Utils::getFormattedXml(file_get_contents(__DIR__ . '/resources/oneline.xml'), true));
    }

    public function
testGetFormattedXmlEmptyStringAsString()
    {
       
$this->expectException(-1 === version_compare(PHP_VERSION, '8.0.0') ? InvalidArgumentException::class : ValueError::class);

       
Utils::getFormattedXml('');
    }

    public function
testGetFormattedXmlEmptyStringAsDomDocument()
    {
       
$this->expectException(-1 === version_compare(PHP_VERSION, '8.0.0') ? InvalidArgumentException::class : ValueError::class);

       
Utils::getFormattedXml('', true);
    }

    public function
testGetFormattedXmlInvalidXmlAsDomDocument()
    {
       
$this->expectException(InvalidArgumentException::class);

       
Utils::getFormattedXml('<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:img="http://ws.estesexpress.com/imageview" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://ws.estesexpress.com/imageview" xml:lang="en"><root>', true);
    }

    public function
testGetFormattedXmlNullAsString()
    {
       
$this->assertNull(Utils::getFormattedXml(null));
    }

    public function
testGetFormattedXmlNullAsDomDocument()
    {
       
$this->assertNull(Utils::getFormattedXml(null, true));
    }

    public function
testGetDOMDocument()
    {
       
$this->assertInstanceOf(DOMDocument::class, Utils::getDOMDocument(file_get_contents(__DIR__ . '/resources/oneline.xml')));
    }

    public function
testGetDOMDocumentException()
    {
       
$this->expectException(-1 === version_compare(PHP_VERSION, '8.0.0') ? InvalidArgumentException::class : ValueError::class);

       
$this->assertInstanceOf(DOMDocument::class, Utils::getDOMDocument(''));
    }
}


For more information send a message to info at phpclasses dot org.