PHP Classes

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: Add Sonar tools, minor improvements

Date: 1 year ago
Size: 2,343 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(): void
   
{
       
$this->assertEquals(file_get_contents(__DIR__ . '/resources/formated.xml'), Utils::getFormattedXml(file_get_contents(__DIR__ . '/resources/oneline.xml')));
    }

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

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

       
Utils::getFormattedXml('');
    }

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

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

    public function
testGetFormattedXmlInvalidXmlAsDomDocument(): void
   
{
       
$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(): void
   
{
       
$this->assertNull(Utils::getFormattedXml(null));
    }

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

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

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

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