Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
veewee committed Jun 25, 2021
1 parent a545eef commit cded4d1
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .phpunit.result.cache

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
<testsuite name="Integration">
<directory>./tests/Integration</directory>
</testsuite>
<testsuite name="Unit">
<directory>./tests/Unit</directory>
</testsuite>
</testsuites>
</phpunit>
27 changes: 27 additions & 0 deletions tests/Unit/Configuration/Classmap/ClassMapCollectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);

namespace SoapTest\ExtSoapEngine\Unit\Configuration\Classmap;

use PHPUnit\Framework\TestCase;
use Soap\ExtSoapEngine\Configuration\ClassMap\ClassMap;
use Soap\ExtSoapEngine\Configuration\ClassMap\ClassMapCollection;

class ClassMapCollectionTest extends TestCase
{
/** @test */
public function it_tests_class_maps(): void
{
$classMap = new ClassMapCollection(
$item1 = new ClassMap('wsdlType', 'phpType'),
new ClassMap('double', 'double'),
$item2 = new ClassMap('double', 'double'),
);

self::assertCount(2, $classMap);
self::assertSame([
'wsdlType' => $item1,
'double' => $item2,
], iterator_to_array($classMap));
}
}
19 changes: 19 additions & 0 deletions tests/Unit/Configuration/Classmap/ClassMapTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);

namespace SoapTest\ExtSoapEngine\Unit\Configuration\Classmap;

use PHPUnit\Framework\TestCase;
use Soap\ExtSoapEngine\Configuration\ClassMap\ClassMap;

class ClassMapTest extends TestCase
{
/** @test */
public function it_tests_class_maps(): void
{
$classMap = new ClassMap('wsdlType', 'phpType');

self::assertSame('wsdlType', $classMap->getWsdlType());
self::assertSame('phpType', $classMap->getPhpClassName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace SoapTest\ExtSoapEngine\Unit\Configuration\TypeConverter;

use PHPUnit\Framework\TestCase;
use Soap\ExtSoapEngine\Configuration\TypeConverter\DecimalTypeConverter;

class DecimalTypeConverterTest extends TestCase
{
protected DecimalTypeConverter $converter;

protected function setUp(): void
{
$this->converter = new DecimalTypeConverter();
}

public function testNamespaceIsSpecificValue()
{
$this->assertSame('http://www.w3.org/2001/XMLSchema', $this->converter->getTypeNamespace());
}

public function testNameIsSpecificValue()
{
$this->assertSame('decimal', $this->converter->getTypeName());
}

public function testConvertXmlToPhp()
{
$xml = '<decimal>24.700</decimal>';

$php = $this->converter->convertXmlToPhp($xml);

$this->assertIsFloat($php);
}

public function testConvertXmlToPhpWhenNoTextContent()
{
$xml = '<decimal/>';

$php = $this->converter->convertXmlToPhp($xml);

$this->assertNull($php);
}

public function testConvertPhpToXml()
{
$xml = '<decimal>24.7</decimal>';

$output = $this->converter->convertPhpToXml((float) 24.700);

$this->assertSame($xml, $output);
}
}
53 changes: 53 additions & 0 deletions tests/Unit/Configuration/TypeConverter/DoubleTypeConverterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace SoapTest\ExtSoapEngine\Unit\Configuration\TypeConverter;

use PHPUnit\Framework\TestCase;
use Soap\ExtSoapEngine\Configuration\TypeConverter\DoubleTypeConverter;

class DoubleTypeConverterTest extends TestCase
{
protected DoubleTypeConverter $converter;

protected function setUp(): void
{
$this->converter = new DoubleTypeConverter();
}

public function testNamespaceIsSpecificValue()
{
$this->assertSame('http://www.w3.org/2001/XMLSchema', $this->converter->getTypeNamespace());
}

public function testNameIsSpecificValue()
{
$this->assertSame('double', $this->converter->getTypeName());
}

public function testConvertXmlToPhp()
{
$xml = '<double>24.700</double>';

$php = $this->converter->convertXmlToPhp($xml);

$this->assertIsFloat($php);
}

public function testConvertXmlToPhpWhenNoTextContent()
{
$xml = '<double/>';

$php = $this->converter->convertXmlToPhp($xml);

$this->assertNull($php);
}

public function testConvertPhpToXml()
{
$xml = '<double>24.7</double>';

$output = $this->converter->convertPhpToXml((float) 24.700);

$this->assertSame($xml, $output);
}
}

0 comments on commit cded4d1

Please sign in to comment.