Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add php 8.4 to test matrix, remove implicit nullables #7871

Merged
merged 6 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
platform: [ubuntu-latest, windows-latest]
php: [ "8.0", "8.1", "8.2", "8.3" ]
php: [ "8.0", "8.1", "8.2", "8.3", "8.4" ]
extensions: ["grpc-1.54.0"]
type: ["Unit Test"]
include:
Expand Down
2 changes: 1 addition & 1 deletion BigQuery/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"phpunit/phpunit": "^9.0",
"phpspec/prophecy-phpunit": "^2.0",
"squizlabs/php_codesniffer": "2.*",
"phpdocumentor/reflection": "^5.3.3",
"phpdocumentor/reflection": "^5.3.3||^6.0",
"phpdocumentor/reflection-docblock": "^5.3",
"erusev/parsedown": "^1.6",
"google/cloud-storage": "^1.3"
Expand Down
2 changes: 1 addition & 1 deletion BigQuery/tests/Unit/Connection/RestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function setUp(): void
public function testApiEndpointForUniverseDomain(
array $config,
string $expectedEndpoint,
string $envUniverse = null
?string $envUniverse = null
) {
if ($envUniverse) {
putenv('GOOGLE_CLOUD_UNIVERSE_DOMAIN=' . $envUniverse);
Expand Down
2 changes: 1 addition & 1 deletion Bigtable/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"require-dev": {
"phpunit/phpunit": "^9.0",
"erusev/parsedown": "^1.6",
"phpdocumentor/reflection": "^5.3.3",
"phpdocumentor/reflection": "^5.3.3||^6.0",
"phpdocumentor/reflection-docblock": "^5.3",
"phpspec/prophecy-phpunit": "^2.0",
"dg/bypass-finals": "^1.7"
Expand Down
2 changes: 1 addition & 1 deletion Core/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"phpunit/phpunit": "^9.0",
"phpspec/prophecy-phpunit": "^2.0",
"squizlabs/php_codesniffer": "2.*",
"phpdocumentor/reflection": "^5.3.3",
"phpdocumentor/reflection": "^5.3.3||^6.0",
"phpdocumentor/reflection-docblock": "^5.3",
"erusev/parsedown": "^1.6",
"opis/closure": "^3",
Expand Down
4 changes: 2 additions & 2 deletions Core/src/AnonymousCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AnonymousCredentials implements
* @param callable $httpHandler
* @return array
*/
public function fetchAuthToken(callable $httpHandler = null)
public function fetchAuthToken(?callable $httpHandler = null)
{
return $this->token;
}
Expand Down Expand Up @@ -81,7 +81,7 @@ public function getLastReceivedToken()
public function updateMetadata(
$metadata,
$authUri = null,
callable $httpHandler = null
?callable $httpHandler = null
) {
return $metadata;
}
Expand Down
4 changes: 2 additions & 2 deletions Core/src/Batch/BatchRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class BatchRunner
* to use. **Defaults to** null. This is only for testing purpose.
*/
public function __construct(
ConfigStorageInterface $configStorage = null,
ProcessItemInterface $processor = null
?ConfigStorageInterface $configStorage = null,
?ProcessItemInterface $processor = null
) {
if ($configStorage === null || $processor === null) {
if ($this->isSysvIPCLoaded() && $this->isDaemonRunning()) {
Expand Down
2 changes: 1 addition & 1 deletion Core/src/Batch/Retry.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Retry
*
* @param BatchRunner $runner [optional] **Defaults to** a new BatchRunner.
*/
public function __construct(BatchRunner $runner = null)
public function __construct(?BatchRunner $runner = null)
{
$this->runner = $runner ?: new BatchRunner();
$this->initFailureFile();
Expand Down
2 changes: 1 addition & 1 deletion Core/src/Compute/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Metadata
/**
* @param ReaderInterface $reader [optional] A metadata reader implementation.
*/
public function __construct(ReaderInterface $reader = null)
public function __construct(?ReaderInterface $reader = null)
{
$this->reader = $reader ?: new HttpHandlerReader();
}
Expand Down
2 changes: 1 addition & 1 deletion Core/src/Compute/Metadata/Readers/HttpHandlerReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class HttpHandlerReader implements ReaderInterface
* @param callable $httpHandler [optional] An HTTP Handler capable of
* accepting PSR7 requests and returning PSR7 responses.
*/
public function __construct(callable $httpHandler = null)
public function __construct(?callable $httpHandler = null)
{
$this->httpHandler = $httpHandler
?: HttpHandlerFactory::build(HttpClientCache::getHttpClient());
Expand Down
2 changes: 1 addition & 1 deletion Core/src/Exception/ServiceException.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class ServiceException extends GoogleException
public function __construct(
$message = null,
$code = 0,
Exception $serviceException = null,
?Exception $serviceException = null,
array $metadata = []
) {
$this->serviceException = $serviceException;
Expand Down
4 changes: 2 additions & 2 deletions Core/src/ExponentialBackoff.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class ExponentialBackoff
*/
public function __construct(
$retries = null,
callable $retryFunction = null,
callable $retryListener = null
?callable $retryFunction = null,
?callable $retryListener = null
) {
$this->retries = $retries !== null ? (int) $retries : 3;
$this->retryFunction = $retryFunction;
Expand Down
4 changes: 2 additions & 2 deletions Core/src/GrpcTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public function send(callable $request, array $args, $whitelisted = false)
*/
private function getGaxConfig(
$version,
callable $authHttpHandler = null,
string $universeDomain = null
?callable $authHttpHandler = null,
?string $universeDomain = null
) {
$config = [
'libName' => 'gccl',
Expand Down
2 changes: 1 addition & 1 deletion Core/src/RequestWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ private function buildDefaultAsyncHandler()
/**
* Verify that the expected universe domain matches the universe domain from the credentials.
*/
private function checkUniverseDomain(FetchAuthTokenInterface $credentialsFetcher = null)
private function checkUniverseDomain(?FetchAuthTokenInterface $credentialsFetcher = null)
{
if (false === $this->hasCheckedUniverse) {
if ($this->universeDomain === '') {
Expand Down
2 changes: 1 addition & 1 deletion Core/src/RestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function send($resource, $method, array $options = [], $whitelisted = fal
* @param string $apiEndpointTemplate
* @return string
*/
private function getApiEndpoint($default, array $config, string $apiEndpointTemplate = null)
private function getApiEndpoint($default, array $config, ?string $apiEndpointTemplate = null)
{
// If the $default parameter is provided, or the user has set an "apiEndoint" config option,
// fall back to the previous behavior.
Expand Down
2 changes: 1 addition & 1 deletion Core/src/Retry.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Retry
public function __construct(
$retries,
callable $delayFunction,
callable $retryFunction = null
?callable $retryFunction = null
) {
$this->retries = $retries !== null ? (int) $retries : 3;
$this->delayFunction = $delayFunction;
Expand Down
2 changes: 1 addition & 1 deletion Core/src/Testing/ArrayHasSameValuesToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ArrayHasSameValuesToken implements TokenInterface
* @experimental
* @internal
*/
public function __construct($value, StringUtil $util = null)
public function __construct($value, ?StringUtil $util = null)
{
$this->value = $value;
$this->util = $util ?: new StringUtil();
Expand Down
6 changes: 5 additions & 1 deletion Core/src/Testing/Reflection/ReflectionHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

namespace Google\Cloud\Core\Testing\Reflection;

use phpDocumentor\Reflection\Php\Factory\Argument;

/**
* Class for determining which verison of phpdocumentor/reflection is being used.
* @internal
Expand All @@ -28,6 +30,8 @@ class ReflectionHandlerFactory
*/
public static function create()
{
return new ReflectionHandlerV5();
return class_exists(Argument::class)
? new ReflectionHandlerV5()
: new ReflectionHandlerV6();
}
}
28 changes: 23 additions & 5 deletions Core/src/Testing/Reflection/ReflectionHandlerV5.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,33 @@ public function classes(array $files)
}

/**
* @return ProjectFactory
* Split this into a separate method because ReflectionHandler V6 looks
* different
*/
public function createProjectFactory()
protected function createParser()
{
$parser = (new ParserFactory())->create(
return (new ParserFactory())->create(
ParserFactory::ONLY_PHP7,
new Lexer\Emulative(['phpVersion' => Lexer\Emulative::PHP_8_0])
);
}

/**
* Split this into a separate method because V6 does not support it
*/
protected function getAdditionalStrategies()
{
return [
new Factory\Argument(new PrettyPrinter()) // @phpstan-ignore-line
];
}

/**
* @return ProjectFactory
*/
public function createProjectFactory()
{
$parser = $this->createParser();
$nodeTraverser = new NodeTraverser();
$nodeTraverser->addVisitor(new NameResolver());
$nodeTraverser->addVisitor(new ElementNameResolver());
Expand All @@ -119,7 +138,6 @@ public function createProjectFactory()
$strategies = new ProjectFactoryStrategies(
[
new Factory\Namespace_(),
new Factory\Argument(new PrettyPrinter()),
new Factory\Class_($docblockFactory),
new Factory\Enum_($docblockFactory),
new Factory\EnumCase($docblockFactory, new PrettyPrinter()),
Expand All @@ -134,7 +152,7 @@ public function createProjectFactory()
new Factory\Trait_($docblockFactory),
new Factory\IfStatement(),
new TraitUse(),
]
] + $this->getAdditionalStrategies()
);

$strategies->addStrategy(
Expand Down
46 changes: 46 additions & 0 deletions Core/src/Testing/Reflection/ReflectionHandlerV6.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Google\Cloud\Core\Testing\Reflection;

use PhpParser\ParserFactory;
use PhpParser\PhpVersion;

/**
* Class for running snippets using phpdocumentor/reflection:v6.
*
* @internal
*/
class ReflectionHandlerV6 extends ReflectionHandlerV5
{
/**
* @see ReflectionHandlerV5
*/
protected function createParser()
{
$phpVersion = PhpVersion::fromString('8.1'); // PHP 8.1.0
return (new ParserFactory())->createForVersion($phpVersion);
}

/**
* @see ReflectionHandlerV5
*/
protected function getAdditionalStrategies()
{
return [];
}
}
2 changes: 1 addition & 1 deletion Core/src/Testing/System/DeletionQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function add($toDelete)
* @experimental
* @internal
*/
public function process(callable $action = null)
public function process(?callable $action = null)
{
if ($action) {
$action($this->queue);
Expand Down
2 changes: 1 addition & 1 deletion Core/src/ValidateTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ trait ValidateTrait
private function validateBatch(
array $input,
$type,
callable $additionalCheck = null
?callable $additionalCheck = null
) {
foreach ($input as $element) {
if (!($element instanceof $type)) {
Expand Down
2 changes: 1 addition & 1 deletion Core/tests/Unit/GrpcTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function () {
public function testUniverseDomainFromGaxConfig(
?string $universeDomain,
string $expectedUniverseDomain,
string $envUniverse = null
?string $envUniverse = null
) {
if ($envUniverse) {
putenv('GOOGLE_CLOUD_UNIVERSE_DOMAIN=' . $envUniverse);
Expand Down
2 changes: 1 addition & 1 deletion Core/tests/Unit/RequestWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ public function testFetchingCredentialAsAuthHeaderWithOverlappingHeaders()
public function testCheckUniverseDomainFails(
?string $universeDomain,
?string $credentialsUniverse,
string $message = null
?string $message = null
) {
$this->expectException(GoogleException::class);
$this->expectExceptionMessage($message ?: sprintf(
Expand Down
6 changes: 3 additions & 3 deletions Core/tests/Unit/ServiceBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ServiceBuilderTest extends TestCase
/**
* @dataProvider serviceProvider
*/
public function testBuildsClients($serviceName, $expectedClient, array $args = [], callable $beforeCallable = null)
public function testBuildsClients($serviceName, $expectedClient, array $args = [], ?callable $beforeCallable = null)
{
$this->checkAndSkipTest([$expectedClient]);

Expand Down Expand Up @@ -86,7 +86,7 @@ public function testKeyfilePathAuthPassthrough(
$serviceName,
$expectedClient,
array $args = [],
callable $beforeCallable = null
?callable $beforeCallable = null
) {
$this->checkAndSkipTest([$expectedClient]);

Expand Down Expand Up @@ -124,7 +124,7 @@ public function testKeyfileAuthPassthrough(
$serviceName,
$expectedClient,
array $args = [],
callable $beforeCallable = null
?callable $beforeCallable = null
) {
$this->checkAndSkipTest([$expectedClient]);

Expand Down
5 changes: 5 additions & 0 deletions Core/tests/Unit/ServicesNotFoundTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class ServicesNotFoundTest extends TestCase

public static function setUpBeforeClass(): void
{
if (version_compare(PHP_VERSION, '8.4', '>=')) {
// @TODO upgrade to using Laravel/closure instead
// @see https://github.com/opis/closure/pull/145
self::markTestSkipped('This test is not compatible with PHP 8.4');
}
self::$cloud = new ServiceBuilder;
foreach (spl_autoload_functions() as $function) {
if ($function[0] instanceof ClassLoader) {
Expand Down
2 changes: 1 addition & 1 deletion Datastore/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"phpunit/phpunit": "^9.0",
"phpspec/prophecy-phpunit": "^2.0",
"squizlabs/php_codesniffer": "2.*",
"phpdocumentor/reflection": "^5.3.3",
"phpdocumentor/reflection": "^5.3.3||^6.0",
"phpdocumentor/reflection-docblock": "^5.3",
"erusev/parsedown": "^1.6"
},
Expand Down
2 changes: 1 addition & 1 deletion Datastore/src/EntityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ interface EntityInterface
* created as the result of a service request.
* }
*/
public static function build(Key $key = null, array $entity = [], array $options = []);
public static function build(?Key $key = null, array $entity = [], array $options = []);

/**
* Defines embedded entity mappings.
Expand Down
4 changes: 2 additions & 2 deletions Datastore/src/EntityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ trait EntityTrait
* created as the result of a service request.
* }
*/
public function __construct(Key $key = null, array $entity = [], array $options = [])
public function __construct(?Key $key = null, array $entity = [], array $options = [])
{
$this->key = $key;
$this->entity = $entity;
Expand Down Expand Up @@ -92,7 +92,7 @@ public function __construct(Key $key = null, array $entity = [], array $options
* }
* @throws \InvalidArgumentException
*/
public static function build(Key $key = null, array $entity = [], array $options = [])
public static function build(?Key $key = null, array $entity = [], array $options = [])
{
return new static($key, $entity, $options);
}
Expand Down
Loading
Loading