forked from php-soap/encoding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractMethodEncoderTests.php
More file actions
62 lines (53 loc) · 2.01 KB
/
AbstractMethodEncoderTests.php
File metadata and controls
62 lines (53 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php declare(strict_types=1);
namespace Soap\Encoding\Test\Unit\Encoder\Method;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Soap\Encoding\Encoder\Method\MethodContext;
use Soap\Encoding\Encoder\Method\SoapMethodEncoder;
use Soap\Engine\Metadata\Model\Parameter;
use Soap\Engine\Metadata\Model\TypeMeta;
use Soap\Engine\Metadata\Model\XsdType;
use Soap\Xml\Xmlns;
abstract class AbstractMethodEncoderTests extends TestCase
{
/**
* @return iterable<int, array{encoder: SoapMethodEncoder, context: MethodContext, xml: string, data: mixed}>
*/
abstract public static function provideIsomorphicCases(): iterable;
#[DataProvider('provideIsomorphicCases')]
public function test_it_can_decode_from_xml(SoapMethodEncoder $encoder, MethodContext $context, string $xml, mixed $data): void
{
$iso = $encoder->iso($context);
$actual = $iso->from($xml);
static::assertEquals($data, $actual);
}
#[DataProvider('provideIsomorphicCases')]
public function test_it_can_encode_into_xml(SoapMethodEncoder $encoder, MethodContext $context, string $xml, mixed $data): void
{
$iso = $encoder->iso($context);
$actual = $iso->to($data);
static::assertSame($xml, $actual);
}
protected static function createParameter(string $name): Parameter
{
return new Parameter(
$name,
self::createType($name),
);
}
protected static function createType(string $name): XsdType
{
return XsdType::guess('string')
->withXmlTypeName('string')
->withXmlNamespace(Xmlns::xsd()->value())
->withXmlNamespaceName('xsd')
->withXmlTargetNodeName($name)
->withXmlTargetNamespace(Xmlns::xsd()->value())
->withXmlTargetNamespaceName('xsd')
->withMeta(
static fn (): TypeMeta => (new TypeMeta())
->withIsElement(true)
->withIsSimple(true)
);
}
}