Skip to content

Commit

Permalink
check prophecies in test teardown
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell committed Dec 12, 2023
1 parent b23f587 commit 83ae3ff
Show file tree
Hide file tree
Showing 56 changed files with 206 additions and 126 deletions.
7 changes: 7 additions & 0 deletions tests/phpunit/src/CommandTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ protected function setUp(): void {
$this->printTestName();
}

protected function tearDown(): void {
parent::tearDown();
if (!in_array('brokenProphecy', $this->getGroups())) {
$this->prophet->checkPredictions();
}
}

protected function setCommand(CommandBase $command): void {
$this->command = $command;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/src/Commands/Acsf/AcsfApiCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function testAcsfCommandExecutionForHttpPostWithMultipleDataTypes(): void
]);

// Assert.
$this->prophet->checkPredictions();

$output = $this->getDisplay();
}

Expand All @@ -64,7 +64,7 @@ public function testAcsfCommandExecutionBool(): void {
]);

// Assert.
$this->prophet->checkPredictions();

}

public function testAcsfCommandExecutionForHttpGet(): void {
Expand All @@ -77,7 +77,7 @@ public function testAcsfCommandExecutionForHttpGet(): void {
$this->executeCommand(['--limit' => '1']);

// Assert.
$this->prophet->checkPredictions();

$output = $this->getDisplay();
$this->assertNotNull($output);
$this->assertJson($output);
Expand Down Expand Up @@ -112,7 +112,7 @@ public function testAcsfCommandExecutionForHttpGetMultiple(mixed $method, mixed
$this->executeCommand($arguments, []);

// Assert.
$this->prophet->checkPredictions();

$output = $this->getDisplay();
$this->assertNotNull($output);
$this->assertJson($output);
Expand Down
37 changes: 20 additions & 17 deletions tests/phpunit/src/Commands/Api/ApiCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ protected function createCommand(): CommandBase {
return $this->injectCommand(ApiBaseCommand::class);
}

/**
* @group brokenProphecy
*/
public function testArgumentsInteraction(): void {
$this->command = $this->getApiCommandByName('api:environments:log-download');
$this->executeCommand([], [
Expand Down Expand Up @@ -94,7 +97,7 @@ public function testApiCommandErrorResponse(): void {
]);

// Assert.
$this->prophet->checkPredictions();

$output = $this->getDisplay();
$this->assertJson($output);
$this->assertStringContainsString($mockBody->message, $output);
Expand All @@ -111,7 +114,7 @@ public function testApiCommandExecutionForHttpGet(): void {
$this->executeCommand(['--limit' => '1']);

// Assert.
$this->prophet->checkPredictions();

$output = $this->getDisplay();
$this->assertNotNull($output);
$this->assertJson($output);
Expand All @@ -120,6 +123,9 @@ public function testApiCommandExecutionForHttpGet(): void {
$this->assertArrayHasKey('uuid', $contents[0]);
}

/**
* @group brokenProphecy
*/
public function testObjectParam(): void {
$this->mockRequest('putEnvironmentCloudActions', '24-a47ac10b-58cc-4372-a567-0e02b2c3d470');
$this->command = $this->getApiCommandByName('api:environments:cloud-actions-update');
Expand All @@ -145,7 +151,7 @@ public function testInferApplicationUuidArgument(): void {
]);

// Assert.
$this->prophet->checkPredictions();

$output = $this->getDisplay();
$this->assertStringContainsString('Inferring Cloud Application UUID for this command since none was provided...', $output);
$this->assertStringContainsString('Set application uuid to ' . $application->uuid, $output);
Expand Down Expand Up @@ -195,7 +201,7 @@ public function testConvertApplicationAliasToUuidArgument(bool $support): void {
]);

// Assert.
$this->prophet->checkPredictions();

$this->getDisplay();
$this->assertEquals(0, $this->getStatusCode());
}
Expand All @@ -209,7 +215,7 @@ public function testConvertInvalidApplicationAliasToUuidArgument(): void {
$this->expectException(AcquiaCliException::class);
$this->expectExceptionMessage('No applications match the alias *:invalidalias');
$this->executeCommand(['applicationUuid' => $alias], []);
$this->prophet->checkPredictions();

}

/**
Expand All @@ -228,7 +234,6 @@ public function testConvertNonUniqueApplicationAliasToUuidArgument(): void {
$output = $this->getDisplay();
$this->assertStringContainsString('Use a unique application alias: devcloud:devcloud2, devcloud:devcloud2', $output);

$this->prophet->checkPredictions();
}

public function testConvertApplicationAliasWithRealmToUuidArgument(): void {
Expand All @@ -239,7 +244,7 @@ public function testConvertApplicationAliasWithRealmToUuidArgument(): void {
$this->command = $this->getApiCommandByName('api:applications:find');
$alias = 'devcloud:devcloud2';
$this->executeCommand(['applicationUuid' => $alias], []);
$this->prophet->checkPredictions();

}

/**
Expand Down Expand Up @@ -268,7 +273,7 @@ public function testConvertEnvironmentAliasToUuidArgument(): void {
]);

// Assert.
$this->prophet->checkPredictions();

$this->getDisplay();
$this->assertEquals(0, $this->getStatusCode());
}
Expand All @@ -287,7 +292,7 @@ public function testConvertInvalidEnvironmentAliasToUuidArgument(): void {
$this->expectException(AcquiaCliException::class);
$this->expectExceptionMessage('{environmentId} must be a valid UUID or site alias.');
$this->executeCommand(['environmentId' => $alias], []);
$this->prophet->checkPredictions();

}

public function testApiCommandExecutionForHttpPost(): void {
Expand All @@ -301,7 +306,7 @@ public function testApiCommandExecutionForHttpPost(): void {
$this->executeCommand($mockRequestArgs);

// Assert.
$this->prophet->checkPredictions();

$output = $this->getDisplay();
$this->assertNotNull($output);
$this->assertJson($output);
Expand Down Expand Up @@ -329,7 +334,7 @@ public function testApiCommandExecutionForHttpPut(): void {
$this->executeCommand($args);

// Assert.
$this->prophet->checkPredictions();

$output = $this->getDisplay();
$this->assertNotNull($output);
$this->assertJson($output);
Expand Down Expand Up @@ -424,14 +429,11 @@ public function testGetApplicationUuidFromBltYml(): void {
$bltConfigFilePath = Path::join($this->projectDir, 'blt', 'blt.yml');
$this->fs->dumpFile($bltConfigFilePath, Yaml::dump(['cloud' => ['appId' => $mockBody->uuid]]));
$this->executeCommand();
$this->prophet->checkPredictions();

$this->getDisplay();
$this->fs->remove($bltConfigFilePath);
}

/**
* Test of deletion of the user from organization by user uuid.
*/
public function testOrganizationMemberDeleteByUserUuid(): void {
$orgId = 'bfafd31a-83a6-4257-b0ec-afdeff83117a';
$memberUuid = '26c4af83-545b-45cb-b165-d537adc9e0b4';
Expand All @@ -446,7 +448,6 @@ public function testOrganizationMemberDeleteByUserUuid(): void {
],
);

$this->prophet->checkPredictions();
$output = $this->getDisplay();
$this->assertEquals(0, $this->getStatusCode());
$this->assertStringContainsString("Organization member removed", $output);
Expand All @@ -473,12 +474,14 @@ public function testOrganizationMemberDeleteByUserEmail(): void {
],
);

$this->prophet->checkPredictions();
$output = $this->getDisplay();
$this->assertEquals(0, $this->getStatusCode());
$this->assertStringContainsString("Organization member removed", $output);
}

/**
* @group brokenProphecy
*/
public function testOrganizationMemberDeleteInvalidEmail(): void {
$membersResponse = $this->getMockResponseFromSpec('/organizations/{organizationUuid}/members', 'get', 200);
$orgId = 'bfafd31a-83a6-4257-b0ec-afdeff83117a';
Expand Down
4 changes: 3 additions & 1 deletion tests/phpunit/src/Commands/App/AppOpenCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ public function testAppOpenCommand(): void {
$localMachineHelper->isBrowserAvailable()->willReturn(TRUE);
$this->mockRequest('getApplicationByUuid', $applicationUuid);
$this->executeCommand(['applicationUuid' => $applicationUuid]);
$this->prophet->checkPredictions();
}

/**
* @group brokenProphecy
*/
public function testAppOpenNoBrowser(): void {
$applicationUuid = 'a47ac10b-58cc-4372-a567-0e02b2c3d470';
$localMachineHelper = $this->mockLocalMachineHelper();
Expand Down
10 changes: 5 additions & 5 deletions tests/phpunit/src/Commands/App/AppVcsInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected function createCommand(): CommandBase {
}

/**
* Test when no environment available for the app.
* @group brokenProphecy
*/
public function testNoEnvAvailableCommand(): void {
$applications = $this->mockRequest('getApplications');
Expand All @@ -42,7 +42,7 @@ public function testNoEnvAvailableCommand(): void {
}

/**
* Test when no branch or tag available for the app.
* @group brokenProphecy
*/
public function testNoVcsAvailableCommand(): void {
$applications = $this->mockRequest('getApplications');
Expand All @@ -64,7 +64,7 @@ public function testNoVcsAvailableCommand(): void {
}

/**
* Test the list of the VCS details of the application.
* @group brokenProphecy
*/
public function testShowVcsListCommand(): void {
$applications = $this->mockRequest('getApplications');
Expand Down Expand Up @@ -96,7 +96,7 @@ public function testShowVcsListCommand(): void {
}

/**
* Test the list of deployed VCS but no deployed VCS available.
* @group brokenProphecy
*/
public function testNoDeployedVcs(): void {
$applications = $this->mockRequest('getApplications');
Expand Down Expand Up @@ -124,7 +124,7 @@ public function testNoDeployedVcs(): void {
}

/**
* Test the list of the only deployed VCS.
* @group brokenProphecy
*/
public function testListOnlyDeployedVcs(): void {
$applications = $this->mockRequest('getApplications');
Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/src/Commands/App/LinkCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public function testLinkCommandAlreadyLinked(): void {
$this->assertEquals(1, $this->getStatusCode());
}

/**
* @group brokenProphecy
*/
public function testLinkCommandInvalidDir(): void {
$this->mockRequest('getApplications');
$this->command->setProjectDir('');
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/src/Commands/App/LogTailCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testLogTailCommand(): void {
]);

// Assert.
$this->prophet->checkPredictions();

$output = $this->getDisplay();
$this->assertStringContainsString('Select a Cloud Platform application:', $output);
$this->assertStringContainsString('[0] Sample application 1', $output);
Expand All @@ -52,7 +52,7 @@ public function testLogTailCommandWithEnvArg(): void {
);

// Assert.
$this->prophet->checkPredictions();

$output = $this->getDisplay();
$this->assertStringContainsString('Apache request', $output);
$this->assertStringContainsString('Drupal request', $output);
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/src/Commands/App/NewCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function testNewDrupalCommand(array $package, string $directory = 'drupal
$this->executeCommand([
'directory' => $directory,
], $inputs);
$this->prophet->checkPredictions();

$output = $this->getDisplay();
$this->assertStringContainsString('Acquia recommends most customers use acquia/drupal-recommended-project to setup a Drupal project', $output);
$this->assertStringContainsString('Choose a starting project', $output);
Expand Down Expand Up @@ -117,7 +117,7 @@ public function testNewNextJSAppCommand(array $package, string $directory = 'nex
$this->executeCommand([
'directory' => $directory,
], $inputs);
$this->prophet->checkPredictions();

$output = $this->getDisplay();
$this->assertStringContainsString('acquia/next-acms is a starter template for building a headless site', $output);
$this->assertStringContainsString('Choose a starting project', $output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function testNewFromDrupal7Command(string $extensions_json, string $recom
'--recommendations' => $recommendations_json,
'--stored-analysis' => $extensions_json,
]);
$this->prophet->checkPredictions();

$output = $this->getDisplay();
$this->assertStringContainsString('Found Drupal 7 site', $output);
$this->assertStringContainsString('Computing recommendations', $output);
Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/src/Commands/App/TaskWaitCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testTaskWaitCommand(string $notification): void {
$this->executeCommand([
'notification-uuid' => $notification,
]);
$this->prophet->checkPredictions();

$output = $this->getDisplay();
self::assertStringContainsString(' [OK] The task with notification uuid 1bd3487e-71d1-4fca-a2d9-5f969b3d35c1 completed', $output);
$this->assertStringContainsString('Progress: 100', $output);
Expand All @@ -51,7 +51,7 @@ function ($response): void {
$this->executeCommand([
'notification-uuid' => $notificationUuid,
]);
$this->prophet->checkPredictions();

self::assertStringContainsString(' [ERROR] The task with notification uuid 1bd3487e-71d1-4fca-a2d9-5f969b3d35c1 failed', $this->getDisplay());
$this->assertEquals(Command::FAILURE, $this->getStatusCode());
}
Expand Down Expand Up @@ -93,7 +93,7 @@ public function testTaskWaitCommandWithEmptyJson(): void {
$this->executeCommand(['notification-uuid' => '{}']);

// Assert.
$this->prophet->checkPredictions();

}

public function testTaskWaitCommandWithInvalidUrl(): void {
Expand All @@ -102,7 +102,7 @@ public function testTaskWaitCommandWithInvalidUrl(): void {
$this->executeCommand(['notification-uuid' => 'https://cloud.acquia.com/api/notifications/foo']);

// Assert.
$this->prophet->checkPredictions();

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testArchiveExport(): void {
$this->executeCommand([
'destination-dir' => $destinationDir,
], $inputs);
$this->prophet->checkPredictions();

$output = $this->getDisplay();

self::assertStringContainsString('An archive of your Drupal application was created at', $output);
Expand Down
1 change: 1 addition & 0 deletions tests/phpunit/src/Commands/Auth/AuthLoginCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function providerTestAuthLoginCommand(): Generator {

/**
* @dataProvider providerTestAuthLoginCommand
* @group brokenProphecy
*/
public function testAuthLoginCommand(bool $machineIsAuthenticated, bool $assertCloudPrompts, array $inputs, array $args, string $outputToAssert): void {
$this->mockRequest('getAccountToken', $this->key);
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/src/Commands/ClearCacheCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testAliasesAreCached(): void {
$this->executeCommand($args, $inputs);

// Assert.
$this->prophet->checkPredictions();

$output = $this->getDisplay();
$this->assertEquals(0, $this->getStatusCode());
}
Expand Down
Loading

0 comments on commit 83ae3ff

Please sign in to comment.