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

CLI-1423: PHPUnit 10 #1820

Merged
merged 4 commits into from
Oct 23, 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
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
},
"require-dev": {
"acquia/coding-standards": "^3.0.1",
"brianium/paratest": "^6.6",
"brianium/paratest": "^7",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
"dominikb/composer-license-checker": "^2.4",
"infection/infection": "^0.27.7",
Expand All @@ -66,7 +66,7 @@
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpunit/phpunit": "^9.1",
"phpunit/phpunit": "10.5.31",
"slevomat/coding-standard": "^8.10",
"squizlabs/php_codesniffer": "^3.5",
"twig/twig": "^3.3"
Expand Down Expand Up @@ -140,7 +140,7 @@
"@unit-serial",
"@unit-parallel"
],
"unit-serial": "phpunit tests/phpunit -vvv --group serial",
"unit-serial": "phpunit tests/phpunit --group serial",
"unit-parallel": "paratest --exclude-group serial",
"coverage": "php -d pcov.enabled=1 vendor/bin/phpunit tests/phpunit --coverage-clover var/logs/clover.xml",
"lint": "phplint",
Expand Down
570 changes: 263 additions & 307 deletions composer.lock

Large diffs are not rendered by default.

22 changes: 6 additions & 16 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
<?xml version="1.0"?>
<!-- phpunit.xml.dist -->
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
cacheResultFile="var/.phpunit.result.cache"
failOnWarning="true"
failOnRisky="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
convertDeprecationsToExceptions="true"
>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" failOnWarning="true" failOnRisky="true" cacheDirectory="var">
<php>
<env name="AMPLITUDE_KEY" value=""/>
<env name="BUGSNAG_KEY" value=""/>
</php>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Acquia CLI Test Suite">
<directory>tests/phpunit</directory>
</testsuite>
</testsuites>
<logging/>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
2 changes: 1 addition & 1 deletion tests/phpunit/src/AcsfApi/AcsfServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function setUp(): void
/**
* @return array<mixed>
*/
public function providerTestIsMachineAuthenticated(): array
public static function providerTestIsMachineAuthenticated(): array
{
return [
[
Expand Down
14 changes: 7 additions & 7 deletions tests/phpunit/src/AcsfApi/EnvVarAcsfAuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

class EnvVarAcsfAuthenticationTest extends TestBase
{
private string $acsfCurrentFactoryUrl = 'https://www.test-something.com';
private static string $acsfCurrentFactoryUrl = 'https://www.test-something.com';

public function setUp(mixed $output = null): void
{
parent::setUp();
$this->cloudCredentials = new AcsfCredentials($this->datastoreCloud);
putenv('ACSF_USERNAME=' . $this->key);
putenv('ACSF_KEY=' . $this->secret);
putenv('ACSF_FACTORY_URI=' . $this->acsfCurrentFactoryUrl);
putenv('ACSF_USERNAME=' . self::$key);
putenv('ACSF_KEY=' . self::$secret);
putenv('ACSF_FACTORY_URI=' . self::$acsfCurrentFactoryUrl);
}

protected function tearDown(): void
Expand All @@ -30,8 +30,8 @@ protected function tearDown(): void
public function testKeyAndSecret(): void
{
$this->removeMockCloudConfigFile();
self::assertEquals($this->key, $this->cloudCredentials->getCloudKey());
self::assertEquals($this->secret, $this->cloudCredentials->getCloudSecret());
self::assertEquals($this->acsfCurrentFactoryUrl, $this->cloudCredentials->getBaseUri());
self::assertEquals(self::$key, $this->cloudCredentials->getCloudKey());
self::assertEquals(self::$secret, $this->cloudCredentials->getCloudSecret());
self::assertEquals(self::$acsfCurrentFactoryUrl, $this->cloudCredentials->getBaseUri());
}
}
4 changes: 2 additions & 2 deletions tests/phpunit/src/CloudApi/AcsfClientServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

class AcsfClientServiceTest extends TestBase
{
protected string $apiSpecFixtureFilePath = __DIR__ . '/../../../../assets/acsf-spec.json';
protected static string $apiSpecFixtureFilePath = __DIR__ . '/../../../../assets/acsf-spec.json';

protected string $apiCommandPrefix = 'acsf';

/**
* @return array<mixed>
*/
public function providerTestIsMachineAuthenticated(): array
public static function providerTestIsMachineAuthenticated(): array
{
return [
[
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/src/CloudApi/ClientServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ClientServiceTest extends TestBase
/**
* @return array<mixed>
*/
public function providerTestIsMachineAuthenticated(): array
public static function providerTestIsMachineAuthenticated(): array
{
return [
[
Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/src/CloudApi/EnvVarAuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class EnvVarAuthenticationTest extends TestBase
public function setUp(mixed $output = null): void
{
parent::setUp();
putenv('ACLI_KEY=' . $this->key);
putenv('ACLI_SECRET=' . $this->secret);
putenv('ACLI_KEY=' . self::$key);
putenv('ACLI_SECRET=' . self::$secret);
putenv('ACLI_CLOUD_API_BASE_URI=' . $this->cloudApiBaseUri);
}

Expand All @@ -28,8 +28,8 @@ protected function tearDown(): void
public function testKeyAndSecret(): void
{
$this->removeMockCloudConfigFile();
self::assertEquals($this->key, $this->cloudCredentials->getCloudKey());
self::assertEquals($this->secret, $this->cloudCredentials->getCloudSecret());
self::assertEquals(self::$key, $this->cloudCredentials->getCloudKey());
self::assertEquals(self::$secret, $this->cloudCredentials->getCloudSecret());
self::assertEquals($this->cloudApiBaseUri, $this->cloudCredentials->getBaseUri());
}
}
36 changes: 9 additions & 27 deletions tests/phpunit/src/CommandTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Gitlab\Api\Projects;
use Gitlab\Api\Users;
use Gitlab\Exception\RuntimeException;
use PHPUnit\Framework\Constraint\StringContains;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Message\StreamInterface;
Expand Down Expand Up @@ -63,7 +62,7 @@ protected function setUp(): void
protected function tearDown(): void
{
parent::tearDown();
if (!in_array('brokenProphecy', $this->getGroups())) {
if (!in_array('brokenProphecy', $this->groups())) {
$this->prophet->checkPredictions();
}
}
Expand Down Expand Up @@ -163,7 +162,7 @@ protected function printTestName(): void
{
if (getenv('ACLI_PRINT_COMMAND_OUTPUT')) {
$this->consoleOutput->writeln("");
$this->writeFullWidthLine(get_class($this) . "::" . $this->getName(), $this->consoleOutput);
$this->writeFullWidthLine(get_class($this) . "::" . $this->name(), $this->consoleOutput);
}
}

Expand Down Expand Up @@ -266,7 +265,7 @@ protected function mockGetEnvironments(): object
public function mockAcsfEnvironmentsRequest(
object $applicationsResponse
): object {
$environmentsResponse = $this->getMockEnvironmentsResponse();
$environmentsResponse = self::getMockEnvironmentsResponse();
foreach ($environmentsResponse->_embedded->items as $environment) {
$environment->ssh_url = 'profserv2.01dev@profserv201dev.ssh.enterprise-g1.acquia-sites.com';
$environment->domains = ["profserv201dev.enterprise-g1.acquia-sites.com"];
Expand Down Expand Up @@ -356,7 +355,7 @@ protected function mockDatabaseBackupsResponse(
int $backupId,
bool $existingBackups = true
): object {
$databaseBackupsResponse = $this->getMockResponseFromSpec('/environments/{environmentId}/databases/{databaseName}/backups', 'get', 200);
$databaseBackupsResponse = self::getMockResponseFromSpec('/environments/{environmentId}/databases/{databaseName}/backups', 'get', 200);
foreach ($databaseBackupsResponse->_embedded->items as $backup) {
$backup->_links->download->href = "/environments/$environmentsResponse->id/databases/$dbName/backups/$backupId/actions/download";
$backup->database->name = $dbName;
Expand Down Expand Up @@ -398,7 +397,7 @@ protected function mockDatabaseBackupCreateResponse(
mixed $environmentsResponse,
mixed $dbName
): mixed {
$backupCreateResponse = $this->getMockResponseFromSpec('/environments/{environmentId}/databases/{databaseName}/backups', 'post', 202)->{'Creating backup'}->value;
$backupCreateResponse = self::getMockResponseFromSpec('/environments/{environmentId}/databases/{databaseName}/backups', 'post', 202)->{'Creating backup'}->value;
$this->clientProphecy->request('post', "/environments/$environmentsResponse->id/databases/$dbName/backups")
->willReturn($backupCreateResponse)
->shouldBeCalled();
Expand Down Expand Up @@ -540,7 +539,7 @@ protected function getApiCommands(): array
{
$apiCommandHelper = new ApiCommandHelper($this->logger);
$commandFactory = $this->getCommandFactory();
return $apiCommandHelper->getApiCommands($this->apiSpecFixtureFilePath, $this->apiCommandPrefix, $commandFactory);
return $apiCommandHelper->getApiCommands(self::$apiSpecFixtureFilePath, $this->apiCommandPrefix, $commandFactory);
}

protected function getApiCommandByName(string $name): ApiBaseCommand|null
Expand All @@ -558,7 +557,7 @@ protected function getApiCommandByName(string $name): ApiBaseCommand|null
/**
* @return array<mixed>
*/
protected function getMockedGitLabProject(mixed $projectId): array
protected static function getMockedGitLabProject(int $projectId): array
{
return [
'default_branch' => 'master',
Expand Down Expand Up @@ -667,7 +666,7 @@ protected function mockGitLabUsersMe(ObjectProphecy|\Gitlab\Client $gitlabClient
*/
protected function mockGitLabPermissionsRequest(mixed $applicationUuid): array
{
$permissionsResponse = $this->getMockResponseFromSpec('/applications/{applicationUuid}/permissions', 'get', 200);
$permissionsResponse = self::getMockResponseFromSpec('/applications/{applicationUuid}/permissions', 'get', 200);
$permissions = $permissionsResponse->_embedded->items;
$permission = clone reset($permissions);
$permission->name = "administer environment variables on non-prod";
Expand All @@ -684,7 +683,7 @@ protected function mockGetGitLabProjects(mixed $applicationUuid, mixed $gitlabPr
$projects->all(['search' => $applicationUuid])
->willReturn($mockedGitlabProjects);
$projects->all()
->willReturn([$this->getMockedGitLabProject($gitlabProjectId)]);
->willReturn([self::getMockedGitLabProject($gitlabProjectId)]);
return $projects;
}

Expand Down Expand Up @@ -719,21 +718,4 @@ protected function getMockGitLabVariables(): array
],
];
}

/**
* Normalize strings for Windows tests.
*
* @todo Remove for PHPUnit 10.
*/
final public static function assertStringContainsStringIgnoringLineEndings(string $needle, string $haystack, string $message = ''): void
{
$haystack = strtr(
$haystack,
[
"\r" => "\n",
"\r\n" => "\n",
]
);
static::assertThat($haystack, new StringContains($needle, false), $message);
}
}
21 changes: 10 additions & 11 deletions tests/phpunit/src/Commands/Acsf/AcsfApiCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@ public function setUp(): void

protected function createCommand(): CommandBase
{
$this->createMockCloudConfigFile($this->getAcsfCredentialsFileContents());
$this->createMockCloudConfigFile(AcsfCommandTestBase::getAcsfCredentialsFileContents());
$this->cloudCredentials = new AcsfCredentials($this->datastoreCloud);
$this->setClientProphecies();
return $this->injectCommand(ApiBaseCommand::class);
}

/**
* @throws \JsonException
* @throws \Exception
*/
public function testAcsfCommandExecutionForHttpPostWithMultipleDataTypes(): void
{
$mockBody = $this->getMockResponseFromSpec('/api/v1/groups/{group_id}/members', 'post', '200');
$mockBody = self::getMockResponseFromSpec('/api/v1/groups/{group_id}/members', 'post', '200', true);
$this->clientProphecy->request('post', '/api/v1/groups/1/members')
->willReturn($mockBody)
->shouldBeCalled();
Expand All @@ -50,14 +54,11 @@ public function testAcsfCommandExecutionForHttpPostWithMultipleDataTypes(): void
// group_id.
'1',
]);

// Assert.
$output = $this->getDisplay();
}

public function testAcsfCommandExecutionBool(): void
{
$mockBody = $this->getMockResponseFromSpec('/api/v1/update/pause', 'post', '200');
$mockBody = self::getMockResponseFromSpec('/api/v1/update/pause', 'post', '200', true);
$this->clientProphecy->request('post', '/api/v1/update/pause')
->willReturn($mockBody)
->shouldBeCalled();
Expand All @@ -68,13 +69,11 @@ public function testAcsfCommandExecutionBool(): void
// Pause.
'1',
]);

// Assert.
}

public function testAcsfCommandExecutionForHttpGet(): void
{
$mockBody = $this->getMockResponseFromSpec('/api/v1/audit', 'get', '200');
$mockBody = self::getMockResponseFromSpec('/api/v1/audit', 'get', '200', true);
$this->clientProphecy->addQuery('limit', '1')->shouldBeCalled();
$this->clientProphecy->request('get', '/api/v1/audit')
->willReturn($mockBody)
Expand All @@ -95,7 +94,7 @@ public function testAcsfCommandExecutionForHttpGet(): void
/**
* @return array<mixed>
*/
public function providerTestAcsfCommandExecutionForHttpGetMultiple(): array
public static function providerTestAcsfCommandExecutionForHttpGetMultiple(): array
{
return [
[
Expand Down Expand Up @@ -170,7 +169,7 @@ public function providerTestAcsfCommandExecutionForHttpGetMultiple(): array
*/
public function testAcsfCommandExecutionForHttpGetMultiple(string $method, string $specPath, string $path, string $command, array $arguments = [], array $jsonArguments = []): void
{
$mockBody = $this->getMockResponseFromSpec($specPath, $method, '200');
$mockBody = self::getMockResponseFromSpec($specPath, $method, '200', true);
$this->clientProphecy->request($method, $path)
->willReturn($mockBody)
->shouldBeCalled();
Expand Down
Loading