[php] Set required PHP version to 7.2 (#6603)

* Set PHP 7.2 as minimum version

* Update PHPUnit to 8 || 9

* Set Bionic environment in Travis config

* PHPUnit 8 requires void return in static methods

* PHPUnit 8 requires void return in static methods

* Fix curl exception message test

When I run "curl http://wrong_host.zxc" output is:
curl: (6) Could not resolve host: wrong_host.zxc
Maybe this message is different across versions.

Tested curl version:
curl 7.54.0 (x86_64-apple-darwin18.0) libcurl/7.54.0 LibreSSL/2.6.5 zlib/1.2.11 nghttp2/1.24.1

* Update assertions of deprecated assertInternalType

* Migrate to expectException method of PHPUnit 8

* Fix PHPCS Fixer errors

* Replace deprecated 'assertRegExp' assertion

* Exclude PHPUnit and php-cs-fixer cache

* Refresh samples

* Set root Travis CI environment to PHP 7.2.5

* Change to 7.3 as 7.2.27 is highest preinstalled

* Fix testWrongHost test
This commit is contained in:
Yuriy Belenko
2020-06-14 17:41:03 +03:00
committed by GitHub
parent e282a052bf
commit 4f1d7c0f04
285 changed files with 918 additions and 4376 deletions

View File

@@ -14,7 +14,7 @@ class AsyncTest extends TestCase
/** @var int */
private $petId;
public function setUp()
public function setUp(): void
{
$this->api = new Api\PetApi();
@@ -58,15 +58,13 @@ class AsyncTest extends TestCase
list($pet, $status, $headers) = $promise->wait();
$this->assertEquals(200, $status);
$this->assertInternalType('array', $headers);
$this->assertIsArray($headers);
$this->assertInstanceOf(Pet::class, $pet);
}
/**
* @expectedException \OpenAPI\Client\ApiException
*/
public function testAsyncThrowingException()
{
$this->expectException(\OpenAPI\Client\ApiException::class);
$promise = $this->api->getPetByIdAsync(0);
$promise->wait();
}
@@ -80,11 +78,9 @@ class AsyncTest extends TestCase
sleep(1);
}
/**
* @expectedException \OpenAPI\Client\ApiException
*/
public function testAsyncHttpInfoThrowingException()
{
$this->expectException(\OpenAPI\Client\ApiException::class);
$promise = $this->api->getPetByIdAsyncWithHttpInfo(0);
$promise->wait();
}

View File

@@ -32,11 +32,9 @@ class EnumTestTest extends TestCase
$this->assertSame($expected, $enum->listInvalidProperties());
}
/**
* @expectedException \InvalidArgumentException
*/
public function testThrowExceptionWhenInvalidAmbiguousValueHasPassed()
{
$this->expectException(\InvalidArgumentException::class);
$enum = new EnumTest();
$enum->setEnumString(0);
}

View File

@@ -7,13 +7,11 @@ use PHPUnit\Framework\TestCase;
class ExceptionTest extends TestCase
{
/**
* @expectedException \OpenAPI\Client\ApiException
* @expectedExceptionCode 404
* @expectedExceptionMessage http://petstore.swagger.io/INVALID_URL/store/inventory
*/
public function testNotFound()
{
$this->expectException(\OpenAPI\Client\ApiException::class);
$this->expectExceptionCode(404);
$this->expectExceptionMessage('http://petstore.swagger.io/INVALID_URL/store/inventory');
$config = new Configuration();
$config->setHost('http://petstore.swagger.io/INVALID_URL');
@@ -24,12 +22,11 @@ class ExceptionTest extends TestCase
$api->getInventory();
}
/**
* @expectedException \OpenAPI\Client\ApiException
* @expectedExceptionMessage Could not resolve host
*/
public function testWrongHost()
{
$this->expectException(\OpenAPI\Client\ApiException::class);
$this->expectExceptionMessage('Could not resolve');
$this->expectExceptionMessage('wrong_host.zxc');
$config = new Configuration();
$config->setHost('http://wrong_host.zxc');

View File

@@ -11,7 +11,7 @@ class HeadersTest extends TestCase
/** @var FakeHttpClient */
private $fakeHttpClient;
public function setUp()
public function setUp(): void
{
$this->fakeHttpClient = new FakeHttpClient();
}

View File

@@ -8,7 +8,7 @@ class OrderApiTest extends TestCase
{
// add a new pet (id 10005) to ensure the pet object is available for all the tests
public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
// for error reporting (need to run with php5.3 to get no warning)
//ini_set('display_errors', 1);
@@ -31,13 +31,11 @@ class OrderApiTest extends TestCase
$order->setStatus("placed");
$this->assertSame("placed", $order->getStatus());
}
/**
* @expectedException InvalidArgumentException
*/
public function testOrderException()
{
// initialize the API client
$this->expectException(\InvalidArgumentException::class);
$order = new Model\Order();
$order->setStatus("invalid_value");
}

View File

@@ -15,16 +15,14 @@ class OuterEnumTest extends TestCase
OuterEnum::class
);
$this->assertInternalType('string', $result);
$this->assertIsString($result);
$this->assertEquals('placed', $result);
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Invalid value for enum
*/
public function testDeserializeInvalidValue()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid value for enum');
ObjectSerializer::deserialize(
"lkjfalgkdfjg",
OuterEnum::class
@@ -58,7 +56,7 @@ class OuterEnumTest extends TestCase
$json
);
$this->assertInternalType('string', $result);
$this->assertIsString($result);
}
public function testSanitizeNested()
@@ -74,19 +72,17 @@ class OuterEnumTest extends TestCase
$input
);
$this->assertInternalType('object', $result);
$this->assertIsObject($result);
$this->assertInstanceOf(\stdClass::class, $result);
$this->assertInternalType('string', $result->outerEnum);
$this->assertIsString($result->outerEnum);
$this->assertEquals('approved', $result->outerEnum);
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Invalid value for enum
*/
public function testSanitizeNestedInvalidValue()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid value for enum');
$input = new EnumTest([
'enum_string' => 'UPPER',
'enum_integer' => -1,

View File

@@ -17,7 +17,7 @@ class ParametersTest extends TestCase
/** @var UserApi */
private $userApi;
public function setUp()
public function setUp(): void
{
$this->fakeHttpClient = new FakeHttpClient();
$this->fakeApi = new Api\FakeApi($this->fakeHttpClient);

View File

@@ -15,7 +15,7 @@ class PetApiTest extends TestCase
private $api;
// add a new pet (id 10005) to ensure the pet object is available for all the tests
public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
// increase memory limit to avoid fatal error due to findPetByStatus
// returning a lot of data
@@ -50,7 +50,7 @@ class PetApiTest extends TestCase
Assert::assertEquals(200, $status);
}
public function setUp()
public function setUp(): void
{
$this->api = new Api\PetApi();
}
@@ -362,13 +362,12 @@ class PetApiTest extends TestCase
/**
* test invalid argument
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Missing the required parameter $status when calling findPetsByStatus
*/
public function testInvalidArgument()
{
// the argument is required, and we must specify one or some from 'available', 'pending', 'sold'
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Missing the required parameter $status when calling findPetsByStatus');
$this->api->findPetsByStatus([]);
}

View File

@@ -15,7 +15,7 @@ class RequestTest extends TestCase
/** @var FakeHttpClient */
private $fakeClient;
public function setUp()
public function setUp(): void
{
$this->fakeClient = new FakeHttpClient();
$this->api = new Api\FakeApi($this->fakeClient);

View File

@@ -16,7 +16,7 @@ class ResponseTypesTest extends TestCase
/** @var FakeHttpClient */
private $fakeHttpClient;
public function setUp()
public function setUp(): void
{
$this->fakeHttpClient = new FakeHttpClient();
$this->api = new PetApi($this->fakeHttpClient);
@@ -38,12 +38,10 @@ class ResponseTypesTest extends TestCase
$this->assertInstanceOf(Pet::class, $result);
}
/**
* @expectedException \OpenAPI\Client\ApiException
* @expectedExceptionCode 400
*/
public function testDefinedErrorException()
{
$this->expectException(\OpenAPI\Client\ApiException::class);
$this->expectExceptionCode(400);
$statusCode = 400;
$this->fakeHttpClient->setResponse(new Response($statusCode, [], '{}'));
@@ -69,12 +67,10 @@ class ResponseTypesTest extends TestCase
// $this->assertInstanceOf(Error::class, $result);
// }
/**
* @expectedException \OpenAPI\Client\ApiException
* @expectedExceptionCode 404
*/
public function testDefaultErrorException()
{
$this->expectException(\OpenAPI\Client\ApiException::class);
$this->expectExceptionCode(404);
$statusCode = 404;
$this->fakeHttpClient->setResponse(new Response($statusCode, [], '{}'));

View File

@@ -14,7 +14,7 @@ class StoreApiTest extends TestCase
/** @var StoreApi */
private $api;
public function setUp()
public function setUp(): void
{
$this->api = new StoreApi();
}
@@ -22,7 +22,7 @@ class StoreApiTest extends TestCase
/**
* Setup before running each test case
*/
public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
// add a new pet (id 10005) to ensure the pet object is available for all the tests
// new pet
@@ -51,7 +51,7 @@ class StoreApiTest extends TestCase
{
$result = $this->api->getInventory();
$this->assertInternalType('array', $result);
$this->assertInternalType('int', $result['available']);
$this->assertIsArray($result);
$this->assertIsInt($result['available']);
}
}

View File

@@ -11,7 +11,7 @@ class UserApiTest extends TestCase
/** @var UserApi*/
private $api;
public function setUp()
public function setUp(): void
{
$this->api = new Api\UserApi();
}
@@ -23,11 +23,15 @@ class UserApiTest extends TestCase
// login
$response = $this->api->loginUser('xxxxx', 'yyyyyyyy');
$this->assertInternalType('string', $response);
$this->assertRegExp(
'/logged in user session/',
$response,
"response string starts with 'logged in user session'"
);
$this->assertIsString($response);
$pattern = '/logged in user session/';
$assertMessage = "response string starts with 'logged in user session'";
$this->assertIsString($response);
if (method_exists($this, 'assertMatchesRegularExpression')) {
$this->assertMatchesRegularExpression($pattern, $response, $assertMessage);
} else {
$this->assertRegExp($pattern, $response, $assertMessage);
}
}
}