diff --git a/.travis.yml b/.travis.yml index 0382f95c..b53fc4ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,22 +1,21 @@ language: php +os: + - linux +dist: bionic php: - - 5.6 - - 7.0 - - 7.1 - - 7.2 - - 7.3 - 7.4 + - 8.0 + - 8.1.0 env: - - SYMFONY_VERSION=2.7.* - - SYMFONY_VERSION=2.8.* - - SYMFONY_VERSION=3.4.* + - SYMFONY_VERSION=5.4.* + - SYMFONY_VERSION=6.0.* -matrix: - allow_failures: - - php: 5.6 - - php: 7.1 +jobs: + exclude: + - php: 7.4 + env: SYMFONY_VERSION=6.0.* before_script: - phpenv config-add myphp.ini @@ -27,7 +26,7 @@ before_script: - ./src/BeSimple/SoapClient/Tests/bin/axis.sh script: - - bin/simple-phpunit --coverage-text --debug + - SYMFONY_DEPRECATIONS_HELPER="max[indirect]=6" bin/simple-phpunit --coverage-text notifications: email: diff --git a/composer.json b/composer.json index 4d81ed1a..2f8691c3 100644 --- a/composer.json +++ b/composer.json @@ -20,15 +20,15 @@ } ], "require": { - "php": ">=5.4.0", + "php": ">=7.4.0", "ext-soap": "*", "ext-curl": "*", "ass/xmlsecurity": "~1.0", - "symfony/framework-bundle": "~2.6 || ~3.4", - "symfony/twig-bundle": "~2.6 || ~3.4", - "zendframework/zend-mime": "2.*", - "zendframework/zend-serializer": "^2.9", - "zendframework/zend-servicemanager": "^3.3" + "symfony/error-handler": "^5.4.3 || ^6.0.3", + "symfony/framework-bundle": "^5.4.4 || ^6.0.4", + "laminas/laminas-mail": "2.*", + "laminas/laminas-mime": "2.*", + "laminas/laminas-serializer": "^2.12" }, "replace": { "besimple/soap-bundle": "self.version", @@ -39,8 +39,8 @@ }, "require-dev": { "mikey179/vfsstream": "~1.0", - "symfony/filesystem": "~2.3", - "symfony/process": "~2.3", + "symfony/filesystem": "^5.4.3 || ^6.0.3", + "symfony/process": "^5.4.3 || ^6.0.3", "symfony/phpunit-bridge": "*" }, "autoload": { @@ -54,4 +54,4 @@ "config": { "bin-dir": "bin" } -} \ No newline at end of file +} diff --git a/src/BeSimple/SoapBundle/Soap/SoapRequest.php b/src/BeSimple/SoapBundle/Soap/SoapRequest.php index 346f6924..fec8f731 100644 --- a/src/BeSimple/SoapBundle/Soap/SoapRequest.php +++ b/src/BeSimple/SoapBundle/Soap/SoapRequest.php @@ -11,8 +11,8 @@ namespace BeSimple\SoapBundle\Soap; use BeSimple\SoapBundle\Util\Collection; +use Laminas\Mime\Message; use Symfony\Component\HttpFoundation\Request; -use Zend\Mime\Message; /** * SoapRequest. diff --git a/src/BeSimple/SoapBundle/Tests/Soap/SoapRequestTest.php b/src/BeSimple/SoapBundle/Tests/Soap/SoapRequestTest.php index 68ba58a9..80e113e1 100644 --- a/src/BeSimple/SoapBundle/Tests/Soap/SoapRequestTest.php +++ b/src/BeSimple/SoapBundle/Tests/Soap/SoapRequestTest.php @@ -23,8 +23,6 @@ class SoapRequestTest extends \PHPUnit\Framework\TestCase { public function testMtomMessage() { - $this->markTestSkipped('Skip because I\'m not sure that SoapRequest is used in a HTTP Request process.'); - $content = $this->loadRequestContentFixture('mtom/simple.txt'); $request = new SoapRequest(array(), array(), array(), array(), array(), array(), $content); diff --git a/src/BeSimple/SoapBundle/Util/Collection.php b/src/BeSimple/SoapBundle/Util/Collection.php index 4ea56994..edd1c584 100644 --- a/src/BeSimple/SoapBundle/Util/Collection.php +++ b/src/BeSimple/SoapBundle/Util/Collection.php @@ -53,12 +53,12 @@ public function clear() $this->elements = array(); } - public function count() + public function count(): int { return count($this->elements); } - public function getIterator() + public function getIterator(): \Traversable { return new \ArrayIterator($this->elements); } diff --git a/src/BeSimple/SoapBundle/WebServiceContext.php b/src/BeSimple/SoapBundle/WebServiceContext.php index dd20ef85..4be995e2 100644 --- a/src/BeSimple/SoapBundle/WebServiceContext.php +++ b/src/BeSimple/SoapBundle/WebServiceContext.php @@ -15,9 +15,9 @@ use BeSimple\SoapCommon\Converter\TypeConverterCollection; use BeSimple\SoapWsdl\Dumper\Dumper; use BeSimple\SoapServer\SoapServerBuilder; +use Laminas\Serializer\Serializer; use Symfony\Component\Config\ConfigCache; use Symfony\Component\Config\Loader\LoaderInterface; -use Zend\Serializer\Serializer; /** * WebServiceContext. diff --git a/src/BeSimple/SoapClient/SoapClient.php b/src/BeSimple/SoapClient/SoapClient.php index 5dcf8299..8e306aee 100644 --- a/src/BeSimple/SoapClient/SoapClient.php +++ b/src/BeSimple/SoapClient/SoapClient.php @@ -238,7 +238,7 @@ protected function __doHttpRequest(SoapRequest $soapRequest) * * @return string */ - public function __doRequest($request, $location, $action, $version, $oneWay = 0) + public function __doRequest($request, $location, $action, $version, $oneWay = 0): ?string { // wrap request data in SoapRequest object $soapRequest = SoapRequest::create($request, $location, $action, $version); @@ -307,7 +307,7 @@ protected function filterRequestOptions(SoapRequest $soapRequest) * * @return string */ - public function __getLastRequestHeaders() + public function __getLastRequestHeaders(): ?string { return $this->lastRequestHeaders; } @@ -327,7 +327,7 @@ public function __getRequestHeaders() * * @return string */ - public function __getLastRequest() + public function __getLastRequest(): ?string { return $this->lastRequest; } @@ -347,7 +347,7 @@ public function __getLastRequestUri() * * @return string */ - public function __getLastResponseHeaders() + public function __getLastResponseHeaders(): ?string { return $this->lastResponseHeaders; } @@ -357,7 +357,7 @@ public function __getLastResponseHeaders() * * @return string */ - public function __getLastResponse() + public function __getLastResponse(): ?string { return $this->lastResponse; } diff --git a/src/BeSimple/SoapClient/Tests/AbstractWebserverTest.php b/src/BeSimple/SoapClient/Tests/AbstractWebserverTest.php index 30c94bfb..5479109c 100644 --- a/src/BeSimple/SoapClient/Tests/AbstractWebserverTest.php +++ b/src/BeSimple/SoapClient/Tests/AbstractWebserverTest.php @@ -13,46 +13,37 @@ namespace BeSimple\SoapClient\Tests; use Symfony\Component\Process\PhpExecutableFinder; -use Symfony\Component\Process\ProcessBuilder; +use Symfony\Component\Process\Process; /** * @author francis.besset@gmail.com */ abstract class AbstractWebServerTest extends \PHPUnit\Framework\TestCase { - // when using the SetUpTearDownTrait, methods like doSetup() can - // be defined with and without the 'void' return type, as you wish - use \Symfony\Bridge\PhpUnit\SetUpTearDownTrait; - /** * @var ProcessBuilder */ static protected $webserver; - static protected $websererPortLength; + static protected $webserverPortLength; - public static function doSetUpBeforeClass() + public static function setUpBeforeClass(): void { - if (version_compare(PHP_VERSION, '5.4.0', '<')) { - self::markTestSkipped('PHP Webserver is available from PHP 5.4'); - } - $phpFinder = new PhpExecutableFinder(); - self::$webserver = ProcessBuilder::create(array( - 'exec', // used exec binary (https://github.com/symfony/symfony/issues/5759) + self::$webserver = new Process(array( $phpFinder->find(), '-S', sprintf('localhost:%d', WEBSERVER_PORT), '-t', __DIR__.DIRECTORY_SEPARATOR.'Fixtures', - ))->getProcess(); + )); self::$webserver->start(); usleep(200000); - self::$websererPortLength = strlen(WEBSERVER_PORT); + self::$webserverPortLength = strlen(WEBSERVER_PORT); } - public static function doTearDownAfterClass() + public static function tearDownAfterClass(): void { self::$webserver->stop(0); usleep(100000); diff --git a/src/BeSimple/SoapClient/Tests/AxisInterop/TestCase.php b/src/BeSimple/SoapClient/Tests/AxisInterop/TestCase.php index 46d90e89..fb5e4b28 100644 --- a/src/BeSimple/SoapClient/Tests/AxisInterop/TestCase.php +++ b/src/BeSimple/SoapClient/Tests/AxisInterop/TestCase.php @@ -4,11 +4,7 @@ class TestCase extends \PHPUnit\Framework\TestCase { - // when using the SetUpTearDownTrait, methods like doSetup() can - // be defined with and without the 'void' return type, as you wish - use \Symfony\Bridge\PhpUnit\SetUpTearDownTrait; - - protected function doSetUp() + protected function setUp(): void { $ch = curl_init('http://localhost:8080/'); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); diff --git a/src/BeSimple/SoapClient/Tests/CurlTest.php b/src/BeSimple/SoapClient/Tests/CurlTest.php index 0abf50e3..1f63650c 100644 --- a/src/BeSimple/SoapClient/Tests/CurlTest.php +++ b/src/BeSimple/SoapClient/Tests/CurlTest.php @@ -37,13 +37,13 @@ public function testGetErrorMessage() )); $curl->exec('http://unknown/curl.txt'); - $this->assertRegExp('/^Could not connect to host.*$/', $curl->getErrorMessage()); + $this->assertMatchesRegularExpression('/^Could not connect to host.*$/', $curl->getErrorMessage()); $curl->exec(sprintf('xyz://localhost:%d/@404.txt', WEBSERVER_PORT)); - $this->assertRegExp('/^Unknown protocol. Only http and https are allowed.*$/', $curl->getErrorMessage()); + $this->assertMatchesRegularExpression('/^Unknown protocol. Only http and https are allowed.*$/', $curl->getErrorMessage()); $curl->exec(''); - $this->assertRegExp('/^Unable to parse URL.*$/', $curl->getErrorMessage()); + $this->assertMatchesRegularExpression('/^Unable to parse URL.*$/', $curl->getErrorMessage()); } public function testGetRequestHeaders() @@ -53,10 +53,10 @@ public function testGetRequestHeaders() )); $curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT)); - $this->assertEquals(132 + self::$websererPortLength, strlen($curl->getRequestHeaders())); + $this->assertCorrectRequestHeaders($curl->getRequestHeaders(), '/curl.txt'); $curl->exec(sprintf('http://localhost:%s/404.txt', WEBSERVER_PORT)); - $this->assertEquals(131 + self::$websererPortLength, strlen($curl->getRequestHeaders())); + $this->assertCorrectRequestHeaders($curl->getRequestHeaders(), '/404.txt'); } public function testGetResponse() @@ -67,10 +67,11 @@ public function testGetResponse() $curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT)); $this->assertSame('OK', $curl->getResponseStatusMessage()); - // Adjust for PHP >= 7.2 sending a Date header + $response = $curl->getResponse(); - $response = preg_replace('/^Date:.*?\r\n/m', '', $response); - $this->assertEquals(145 + self::$websererPortLength, strlen($response)); + [$headers, $body] = explode("\r\n\r\n", $response, 2); + $this->assertCorrectResponseHeaders($headers, '200 OK', 'text/plain', strlen($body)); + $this->assertSame('This is a testfile for cURL.', $body); $curl->exec(sprintf('http://localhost:%d/404.txt', WEBSERVER_PORT)); $this->assertSame('Not Found', $curl->getResponseStatusMessage()); @@ -106,16 +107,12 @@ public function testGetResponseHeaders() )); $curl->exec(sprintf('http://localhost:%d/curl.txt', WEBSERVER_PORT)); - // Adjust for PHP >= 7.2 sending a Date header $headers = $curl->getResponseHeaders(); - $headers = preg_replace('/^Date:.*?\r\n/m', '', $headers); - $this->assertEquals(117 + self::$websererPortLength, strlen($headers)); + $this->assertCorrectResponseHeaders($headers, '200 OK', 'text/plain'); $curl->exec(sprintf('http://localhost:%d/404.txt', WEBSERVER_PORT)); - // Adjust for PHP >= 7.2 sending a Date header $headers = $curl->getResponseHeaders(); - $headers = preg_replace('/^Date:.*?\r\n/m', '', $headers); - $this->assertEquals(124 + self::$websererPortLength, strlen($headers)); + $this->assertCorrectResponseHeaders($headers, '404 Not Found', 'text/html'); } public function testGetResponseStatusCode() @@ -130,4 +127,22 @@ public function testGetResponseStatusCode() $curl->exec(sprintf('http://localhost:%d/404.txt', WEBSERVER_PORT)); $this->assertEquals(404, $curl->getResponseStatusCode()); } + + protected function assertCorrectRequestHeaders($headerStr, $requestPath) + { + $headers = explode("\r\n", $headerStr); + $this->assertContains("GET $requestPath HTTP/1.1", $headers); + $this->assertContains('User-Agent: PHP-SOAP/\BeSimple\SoapClient', $headers); + $this->assertContains('Accept: */*', $headers); + } + + protected function assertCorrectResponseHeaders($headerStr, $status, $contentType, $contentLen = null) + { + $headers = explode("\r\n", $headerStr); + $this->assertContains("HTTP/1.1 $status", $headers); + $this->assertContains("Content-Type: $contentType; charset=UTF-8", $headers); + if (null !== $contentLen) { + $this->assertContains("Content-Length: $contentLen", $headers); + } + } } diff --git a/src/BeSimple/SoapClient/Tests/ServerInterop/TestCase.php b/src/BeSimple/SoapClient/Tests/ServerInterop/TestCase.php index caf999a4..9b46d9a9 100644 --- a/src/BeSimple/SoapClient/Tests/ServerInterop/TestCase.php +++ b/src/BeSimple/SoapClient/Tests/ServerInterop/TestCase.php @@ -4,18 +4,8 @@ class TestCase extends \PHPUnit\Framework\TestCase { - // when using the SetUpTearDownTrait, methods like doSetup() can - // be defined with and without the 'void' return type, as you wish - use \Symfony\Bridge\PhpUnit\SetUpTearDownTrait; - - protected function doSetUp() + protected function setUp(): void { - if (version_compare(PHP_VERSION, '5.3.0', '=')) { - $this->markTestSkipped( - 'The PHP cli webserver is not available with PHP 5.3.' - ); - } - $ch = curl_init('http://localhost:8081/'); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_HEADER, true); diff --git a/src/BeSimple/SoapClient/Tests/SoapClientTest.php b/src/BeSimple/SoapClient/Tests/SoapClientTest.php index d379b9ce..bceb95bd 100644 --- a/src/BeSimple/SoapClient/Tests/SoapClientTest.php +++ b/src/BeSimple/SoapClient/Tests/SoapClientTest.php @@ -50,7 +50,7 @@ public function testSoapFaultWhenPassingInvalidWSDLs($wsdl) } $this->assertInstanceOf('SoapFault', $soapFault, 'Invalid type of exception'); - $this->assertRegExp('/SOAP-ERROR: Parsing WSDL: .*/', $soapFault->getMessage(), 'Invalid or incorrect exception message'); + $this->assertMatchesRegularExpression('/SOAP-ERROR: Parsing WSDL: .*/', $soapFault->getMessage(), 'Invalid or incorrect exception message'); $this->assertStringContainsString('WSDL', $soapFault->faultcode, 'Invalid type of faultcode'); } diff --git a/src/BeSimple/SoapClient/Tests/WsdlDownloaderTest.php b/src/BeSimple/SoapClient/Tests/WsdlDownloaderTest.php index e53acea4..4e6b221b 100644 --- a/src/BeSimple/SoapClient/Tests/WsdlDownloaderTest.php +++ b/src/BeSimple/SoapClient/Tests/WsdlDownloaderTest.php @@ -25,10 +25,6 @@ */ class WsdlDownloaderTest extends AbstractWebserverTest { - // when using the SetUpTearDownTrait, methods like doSetup() can - // be defined with and without the 'void' return type, as you wish - use \Symfony\Bridge\PhpUnit\SetUpTearDownTrait; - protected static $filesystem; protected static $fixturesPath; @@ -57,7 +53,7 @@ public function testDownloadDownloadsToVfs($source, $regexp, $nbDownloads) //Test that the Cache filename is valid $regexp = '#'.sprintf($regexp, $cacheDirForRegExp).'#'; - $this->assertRegExp($regexp, $cacheFileName); + $this->assertMatchesRegularExpression($regexp, $cacheFileName); } @@ -137,7 +133,7 @@ public function testResolveWsdlIncludes($source, $cacheFile, $remoteParentUrl, $ $m->invoke($wsdlDownloader, file_get_contents($source), $cacheFile, $remoteParentUrl); $this->assertCount($nbDownloads, $wsdlCacheDir->getChildren()); - $this->assertRegExp('#'.sprintf($regexp, $cacheDirForRegExp).'#', file_get_contents($cacheFile)); + $this->assertMatchesRegularExpression('#'.sprintf($regexp, $cacheDirForRegExp).'#', file_get_contents($cacheFile)); } public function provideResolveWsdlIncludes() @@ -204,7 +200,7 @@ public function testResolveXsdIncludes($source, $cacheFile, $remoteParentUrl, $r $m->invoke($wsdlDownloader, file_get_contents($source), $cacheFile, $remoteParentUrl); $this->assertCount($nbDownloads, $wsdlCacheDir->getChildren()); - $this->assertRegExp('#'.sprintf($regexp, $cacheDirForRegExp).'#', file_get_contents($cacheFile)); + $this->assertMatchesRegularExpression('#'.sprintf($regexp, $cacheDirForRegExp).'#', file_get_contents($cacheFile)); } public function provideResolveXsdIncludes() @@ -330,10 +326,10 @@ public function testValidResponseCode() $result = $wsdlDownloader->download('http://somefake.url/wsdl'); - $this->assertRegExp('/.*wsdl_[a-f0-9]{32}\.cache/', $result); + $this->assertMatchesRegularExpression('/.*wsdl_[a-f0-9]{32}\.cache/', $result); } - public static function doSetUpBeforeClass() + public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); @@ -349,7 +345,7 @@ public static function doSetUpBeforeClass() } } - public static function doTearDownAfterClass() + public static function tearDownAfterClass(): void { parent::tearDownAfterClass(); diff --git a/src/BeSimple/SoapCommon/FilterHelper.php b/src/BeSimple/SoapCommon/FilterHelper.php index 01a17177..2c7aeabf 100644 --- a/src/BeSimple/SoapCommon/FilterHelper.php +++ b/src/BeSimple/SoapCommon/FilterHelper.php @@ -134,7 +134,7 @@ public function addNamespace($prefix, $namespaceURI) * * @return \DOMElement */ - public function createElement($namespaceURI, $name, $value = null) + public function createElement($namespaceURI, $name, $value = '') { $prefix = $this->namespaces[$namespaceURI]; diff --git a/src/BeSimple/SoapCommon/Mime/PartHeader.php b/src/BeSimple/SoapCommon/Mime/PartHeader.php index 958c85fd..da7c2d3e 100644 --- a/src/BeSimple/SoapCommon/Mime/PartHeader.php +++ b/src/BeSimple/SoapCommon/Mime/PartHeader.php @@ -86,7 +86,7 @@ public function getHeader($name, $subValue = null) */ protected function generateHeaders() { - $charset = strtolower($this->getHeader('Content-Type', 'charset')); + $charset = strtolower($this->getHeader('Content-Type', 'charset') ?? ''); $preferences = array( 'scheme' => 'Q', 'input-charset' => 'utf-8', diff --git a/src/BeSimple/SoapCommon/Tests/CacheTest.php b/src/BeSimple/SoapCommon/Tests/CacheTest.php index 14a9cf96..7bb30340 100644 --- a/src/BeSimple/SoapCommon/Tests/CacheTest.php +++ b/src/BeSimple/SoapCommon/Tests/CacheTest.php @@ -18,10 +18,6 @@ class SoapRequestTest extends \PHPUnit\Framework\TestCase { - // when using the SetUpTearDownTrait, methods like doSetup() can - // be defined with and without the 'void' return type, as you wish - use \Symfony\Bridge\PhpUnit\SetUpTearDownTrait; - public function testSetEnabled() { Cache::setEnabled(Cache::ENABLED); @@ -87,7 +83,7 @@ public function testSetLimit() $this->assertEquals(1, Cache::getLimit()); } - public function doSetUp() + public function setUp(): void { ini_restore('soap.wsdl_cache_enabled'); ini_restore('soap.wsdl_cache'); diff --git a/src/BeSimple/SoapCommon/Tests/Mime/MultiPartTest.php b/src/BeSimple/SoapCommon/Tests/Mime/MultiPartTest.php index 96cd3665..d0358f1c 100644 --- a/src/BeSimple/SoapCommon/Tests/Mime/MultiPartTest.php +++ b/src/BeSimple/SoapCommon/Tests/Mime/MultiPartTest.php @@ -26,7 +26,7 @@ public function testConstructor() $this->assertEquals('multipart/related', $mp->getHeader('Content-Type')); $this->assertEquals('text/xml', $mp->getHeader('Content-Type', 'type')); $this->assertEquals('utf-8', $mp->getHeader('Content-Type', 'charset')); - $this->assertRegExp('~urn:uuid:.*~', $mp->getHeader('Content-Type', 'boundary')); + $this->assertMatchesRegularExpression('~urn:uuid:.*~', $mp->getHeader('Content-Type', 'boundary')); } public function testGetMimeMessage() diff --git a/src/BeSimple/SoapCommon/Tests/Mime/PartTest.php b/src/BeSimple/SoapCommon/Tests/Mime/PartTest.php index ab6a8a43..b2ceddda 100644 --- a/src/BeSimple/SoapCommon/Tests/Mime/PartTest.php +++ b/src/BeSimple/SoapCommon/Tests/Mime/PartTest.php @@ -36,7 +36,7 @@ public function testDefaultConstructor() $this->assertEquals('application/octet-stream', $p->getHeader('Content-Type')); $this->assertEquals('utf-8', $p->getHeader('Content-Type', 'charset')); $this->assertEquals(Part::ENCODING_BINARY, $p->getHeader('Content-Transfer-Encoding')); - $this->assertRegExp('~~', $p->getHeader('Content-ID')); + $this->assertMatchesRegularExpression('~~', $p->getHeader('Content-ID')); } public function testSetContent() diff --git a/src/BeSimple/SoapServer/SoapServer.php b/src/BeSimple/SoapServer/SoapServer.php index dc94d5b0..0b68917d 100644 --- a/src/BeSimple/SoapServer/SoapServer.php +++ b/src/BeSimple/SoapServer/SoapServer.php @@ -64,7 +64,7 @@ public function __construct($wsdl, array $options = array()) * * @param string $request Request string */ - public function handle($request = null) + public function handle($request = null): void { // wrap request data in SoapRequest object $soapRequest = SoapRequest::create($request, $this->soapVersion);