|
| 1 | +<?php declare(strict_types=1); |
| 2 | + |
| 3 | +namespace Soap\WsdlReader\Test\Unit\Locator; |
| 4 | + |
| 5 | +use Closure; |
| 6 | +use PHPUnit\Framework\TestCase; |
| 7 | +use Soap\Wsdl\Loader\StreamWrapperLoader; |
| 8 | +use Soap\WsdlReader\Exception\ServiceException; |
| 9 | +use Soap\WsdlReader\Locator\ServiceSelectionCriteria; |
| 10 | +use Soap\WsdlReader\Locator\Wsdl1SelectedServiceLocator; |
| 11 | +use Soap\WsdlReader\Model\Definitions\SoapVersion; |
| 12 | +use Soap\WsdlReader\Model\Service\Wsdl1SelectedService; |
| 13 | +use Soap\WsdlReader\Wsdl1Reader; |
| 14 | + |
| 15 | +final class Wsdl1SelectedServiceLocatorTest extends TestCase |
| 16 | +{ |
| 17 | + /** |
| 18 | + * @dataProvider provideServiceLocations |
| 19 | + */ |
| 20 | + public function test_it_can_locate_service( |
| 21 | + string $wsdl, |
| 22 | + ServiceSelectionCriteria $criteria, |
| 23 | + Closure $assert |
| 24 | + ): void { |
| 25 | + |
| 26 | + $locator = new Wsdl1SelectedServiceLocator(); |
| 27 | + $wsdl1 = (new Wsdl1Reader(new StreamWrapperLoader()))($wsdl); |
| 28 | + |
| 29 | + $service = $locator($wsdl1, $criteria); |
| 30 | + $assert($service); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * @dataProvider provideNotLocatableServices |
| 35 | + */ |
| 36 | + public function test_it_can_not_locate_service( |
| 37 | + string $wsdl, |
| 38 | + ServiceSelectionCriteria $criteria, |
| 39 | + ): void { |
| 40 | + $this->expectException(ServiceException::class); |
| 41 | + |
| 42 | + $locator = new Wsdl1SelectedServiceLocator(); |
| 43 | + $wsdl1 = (new Wsdl1Reader(new StreamWrapperLoader()))($wsdl); |
| 44 | + |
| 45 | + $locator($wsdl1, $criteria); |
| 46 | + } |
| 47 | + |
| 48 | + public static function provideServiceLocations(): iterable |
| 49 | + { |
| 50 | + $weatherWs = FIXTURE_DIR . '/wsdl/weather-ws.wsdl'; |
| 51 | + |
| 52 | + yield 'first-default' => [ |
| 53 | + $weatherWs, |
| 54 | + ServiceSelectionCriteria::defaults(), |
| 55 | + self::assertSoapWeather11Service(...), |
| 56 | + ]; |
| 57 | + |
| 58 | + yield 'first-http' => [ |
| 59 | + $weatherWs, |
| 60 | + ServiceSelectionCriteria::defaults() |
| 61 | + ->withServiceName('Weather') |
| 62 | + ->withPortName('WeatherHttpGet') |
| 63 | + ->withAllowHttpPorts(), |
| 64 | + self::assertSoapHttpGetService(...), |
| 65 | + ]; |
| 66 | + |
| 67 | + yield 'first-soap12' => [ |
| 68 | + $weatherWs, |
| 69 | + ServiceSelectionCriteria::defaults() |
| 70 | + ->withPreferredSoapVersion(SoapVersion::SOAP_12), |
| 71 | + self::assertSoapWeather12Service(...), |
| 72 | + ]; |
| 73 | + } |
| 74 | + |
| 75 | + public static function provideNotLocatableServices(): iterable |
| 76 | + { |
| 77 | + $weatherWs = FIXTURE_DIR . '/wsdl/weather-ws.wsdl'; |
| 78 | + |
| 79 | + yield 'invalid-service-name' => [ |
| 80 | + $weatherWs, |
| 81 | + ServiceSelectionCriteria::defaults()->withServiceName('invalid'), |
| 82 | + ]; |
| 83 | + |
| 84 | + yield 'invalid-port-name' => [ |
| 85 | + $weatherWs, |
| 86 | + ServiceSelectionCriteria::defaults()->withPortName('invalid'), |
| 87 | + ]; |
| 88 | + |
| 89 | + } |
| 90 | + |
| 91 | + private static function assertSoapWeather11Service(Wsdl1SelectedService $service): void |
| 92 | + { |
| 93 | + static::assertSame('Weather', $service->service->name); |
| 94 | + static::assertSame('WeatherSoap', $service->port->name); |
| 95 | + static::assertSame('http://wsf.cdyne.com/WeatherWS/Weather.asmx', $service->port->address->location); |
| 96 | + static::assertSame(true, $service->port->address->type->isSoap()); |
| 97 | + static::assertSame(SoapVersion::SOAP_11, $service->port->address->type->soapVersion()); |
| 98 | + static::assertSame('WeatherSoap', $service->binding->name); |
| 99 | + static::assertSame('WeatherSoap', $service->portType->name); |
| 100 | + static::assertSame('GetWeatherInformationSoapIn', $service->messages->items[0]->name); |
| 101 | + } |
| 102 | + |
| 103 | + private static function assertSoapWeather12Service(Wsdl1SelectedService $service): void |
| 104 | + { |
| 105 | + static::assertSame('Weather', $service->service->name); |
| 106 | + static::assertSame('WeatherSoap12', $service->port->name); |
| 107 | + static::assertSame('http://wsf.cdyne.com/WeatherWS/Weather.asmx', $service->port->address->location); |
| 108 | + static::assertSame(true, $service->port->address->type->isSoap()); |
| 109 | + static::assertSame(SoapVersion::SOAP_12, $service->port->address->type->soapVersion()); |
| 110 | + static::assertSame('WeatherSoap12', $service->binding->name); |
| 111 | + static::assertSame('WeatherSoap', $service->portType->name); |
| 112 | + static::assertSame('GetWeatherInformationSoapIn', $service->messages->items[0]->name); |
| 113 | + } |
| 114 | + |
| 115 | + private static function assertSoapHttpGetService(Wsdl1SelectedService $service): void |
| 116 | + { |
| 117 | + static::assertSame('Weather', $service->service->name); |
| 118 | + static::assertSame('WeatherHttpGet', $service->port->name); |
| 119 | + static::assertSame('http://wsf.cdyne.com/WeatherWS/Weather.asmx', $service->port->address->location); |
| 120 | + static::assertSame(false, $service->port->address->type->isSoap()); |
| 121 | + static::assertSame(null, $service->port->address->type->soapVersion()); |
| 122 | + static::assertSame('WeatherHttpGet', $service->binding->name); |
| 123 | + static::assertSame('WeatherHttpGet', $service->portType->name); |
| 124 | + static::assertSame('GetWeatherInformationSoapIn', $service->messages->items[0]->name); |
| 125 | + } |
| 126 | +} |
0 commit comments