|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +namespace SoapTest\Xml\Unit\Builder; |
| 5 | + |
| 6 | +use PHPUnit\Framework\TestCase; |
| 7 | +use Soap\Xml\Builder\Header\Actor; |
| 8 | +use Soap\Xml\Builder\Header\MustUnderstand; |
| 9 | +use Soap\Xml\Builder\SoapHeader; |
| 10 | +use Soap\Xml\Builder\SoapHeaders; |
| 11 | +use Soap\Xml\Manipulator\PrependSoapHeaders; |
| 12 | +use VeeWee\Xml\Dom\Document; |
| 13 | +use function VeeWee\Xml\Dom\Builder\children; |
| 14 | +use function VeeWee\Xml\Dom\Builder\namespaced_element; |
| 15 | +use function VeeWee\Xml\Dom\Builder\value; |
| 16 | +use function VeeWee\Xml\Dom\Configurator\comparable; |
| 17 | + |
| 18 | +final class SoapHeaderTest extends TestCase |
| 19 | +{ |
| 20 | + public function test_it_can_create_a_header_element(): void |
| 21 | + { |
| 22 | + $tns = 'https://foo.bar'; |
| 23 | + $builder = new SoapHeaders( |
| 24 | + new SoapHeader( |
| 25 | + $tns, |
| 26 | + 'x:Auth', |
| 27 | + children( |
| 28 | + namespaced_element($tns, 'x:user', value('josbos')), |
| 29 | + namespaced_element($tns, 'x:password', value('topsecret')) |
| 30 | + ) |
| 31 | + ), |
| 32 | + new SoapHeader($tns, 'Acting', Actor::next()), |
| 33 | + new SoapHeader($tns, 'Understanding', new MustUnderstand()) |
| 34 | + ); |
| 35 | + $doc = Document::fromXmlFile(FIXTURE_DIR.'/empty-envelope.xml'); |
| 36 | + $headers = $doc->build($builder); |
| 37 | + $doc->manipulate(new PrependSoapHeaders(...$headers)); |
| 38 | + |
| 39 | + $expected = <<<EOXML |
| 40 | + <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope/" |
| 41 | + soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding"> |
| 42 | + <soap:Header xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"> |
| 43 | + <x:Auth xmlns:x="https://foo.bar"> |
| 44 | + <x:user>josbos</x:user> |
| 45 | + <x:password>topsecret</x:password> |
| 46 | + </x:Auth> |
| 47 | + <Acting xmlns="https://foo.bar" soap:actor="http://schemas.xmlsoap.org/soap/actor/next" /> |
| 48 | + <Understanding xmlns="https://foo.bar" soap:mustUnderstand="1" /> |
| 49 | + </soap:Header> |
| 50 | + </soap:Envelope> |
| 51 | + EOXML; |
| 52 | + |
| 53 | + |
| 54 | + static::assertXmlStringEqualsXmlString( |
| 55 | + Document::fromXmlString($expected, comparable())->toXmlString(), |
| 56 | + Document::fromUnsafeDocument($doc->toUnsafeDocument(), comparable())->toXmlString() |
| 57 | + ); |
| 58 | + } |
| 59 | +} |
0 commit comments