protected function BuildHooksKernelTestBase::assertFrontendEnvironmentBuildHook in Build Hooks 3.x
Same name and namespace in other branches
- 8.2 tests/src/Kernel/BuildHooksKernelTestBase.php \Drupal\Tests\build_hooks\Kernel\BuildHooksKernelTestBase::assertFrontendEnvironmentBuildHook()
Assert a front-end environment build hook fires.
Parameters
string $plugin: Build hook plugin.
string $deployment_strategy: Deployment strategy.
string|null $expected_url: Expected URL.
array $settings: Plugin settings.
\GuzzleHttp\Psr7\Response $mockResponse: Response object to be returned by the mocked http-client.
string|null $entity_label: Entity label to use.
Return value
\GuzzleHttp\Psr7\Request|null Build hook request.
10 calls to BuildHooksKernelTestBase::assertFrontendEnvironmentBuildHook()
- BitbucketBuildHooksTest::testBitbucketFrontendEnvironment in modules/
build_hooks_bitbucket/ tests/ src/ Kernel/ BitbucketBuildHooksTest.php - Tests Bitbucket Pipelines front-end environment deployments.
- BuildHooksConfigEntityTest::testFrontendEnvironment in tests/
src/ Kernel/ BuildHooksConfigEntityTest.php - Tests front-end environment deployments.
- BuildTriggerTest::testAccessToDeployContents in tests/
src/ Kernel/ BuildTriggerTest.php - Tests a plugin can prevent a build via access to entities in the deploy.
- BuildTriggerTest::testGenericFrontendEnvironment in tests/
src/ Kernel/ BuildTriggerTest.php - Tests generic front-end environment deployments.
- BuildTriggerTest::testPreventBuildViaModule in tests/
src/ Kernel/ BuildTriggerTest.php - Tests a module can prevent a build.
File
- tests/
src/ Kernel/ BuildHooksKernelTestBase.php, line 95
Class
- BuildHooksKernelTestBase
- Defines a base kernel test class for Build Hooks module.
Namespace
Drupal\Tests\build_hooks\KernelCode
protected function assertFrontendEnvironmentBuildHook(string $plugin, string $deployment_strategy, string $expected_url = NULL, array $settings = [], Response $mockResponse = NULL, string $entity_label = NULL) : ?Request {
$response = $mockResponse ?? new Response(200, [], 'Hello, World');
$this
->mockClient($response);
$title = $this
->randomMachineName();
$environment = FrontendEnvironment::create([
'id' => 'foo',
'label' => $title,
'settings' => $settings,
'plugin' => $plugin,
'deployment_strategy' => $deployment_strategy,
]);
$environment
->save();
$this
->assertEquals($title, $environment
->label());
$entity = EntityTest::create([
'name' => $entity_label ?: $this
->randomMachineName(),
]);
$entity
->save();
/** @var \Drupal\build_hooks\DeployLogger $logger */
$logger = \Drupal::service('build_hooks.deploylogger');
// The entity-save strategy will never have queued items.
$this
->assertEquals($deployment_strategy === TriggerInterface::DEPLOYMENT_STRATEGY_ENTITYSAVE && $expected_url ? 0 : 1, $logger
->getNumberOfItemsSinceLastDeploymentForEnvironment($environment));
if ($deployment_strategy === TriggerInterface::DEPLOYMENT_STRATEGY_CRON) {
\Drupal::service('cron')
->run();
}
if ($deployment_strategy === TriggerInterface::DEPLOYMENT_STRATEGY_MANUAL) {
\Drupal::service('build_hooks.trigger')
->triggerBuildHookForEnvironment($environment);
}
if ($expected_url) {
$this
->assertCount(1, $this->history);
$request = reset($this->history)['request'];
$this
->assertEquals($expected_url, (string) $request
->getUri());
$this
->assertEquals(0, $logger
->getNumberOfItemsSinceLastDeploymentForEnvironment($environment));
return $request;
}
$this
->assertCount(0, $this->history);
return NULL;
}