You are here

public function CircleBuildHookTest::testDeploymentHooksV2 in Build Hooks 8.2

Same name and namespace in other branches
  1. 3.x modules/build_hooks_circleci/tests/src/Kernel/CircleBuildHookTest.php \Drupal\Tests\build_hooks_circleci\Kernel\CircleBuildHookTest::testDeploymentHooksV2()

Tests deployment hooks for version 2.

File

modules/build_hooks_circleci/tests/src/Kernel/CircleBuildHookTest.php, line 63

Class

CircleBuildHookTest
Defines a class for testing circle CI build hooks module.

Namespace

Drupal\Tests\build_hooks_circleci\Kernel

Code

public function testDeploymentHooksV2() {
  $project = $this
    ->randomMachineName();
  $branch = $this
    ->randomMachineName();
  $parameter_name = $this
    ->randomMachineName();
  $parameter_value = $this
    ->randomMachineName();
  $api_key = $this
    ->randomMachineName();
  $expected_url = 'https://circleci.com/api/v2/project/gh/' . $project . '/pipeline';
  $request = $this
    ->assertFrontendEnvironmentBuildHook('circleciv2', Trigger::DEPLOYMENT_STRATEGY_ENTITYSAVE, $expected_url, [
    'project' => $project,
    'type' => 'branch',
    'reference' => $branch,
    'parameters' => [
      [
        'name' => $parameter_name,
        'value' => $parameter_value,
        'type' => 'string',
      ],
      [
        'name' => 'param2',
        'value' => '2',
        'type' => 'integer',
      ],
      [
        'name' => 'param3',
        'value' => '0',
        'type' => 'boolean',
      ],
      [
        'name' => 'param4',
        'value' => 'true',
        'type' => 'boolean',
      ],
    ],
    'token' => $api_key,
  ]);
  $this
    ->assertEquals(json_encode([
    'branch' => $branch,
    'parameters' => [
      $parameter_name => $parameter_value,
      'param2' => 2,
      'param3' => FALSE,
      'param4' => TRUE,
    ],
  ]), (string) $request
    ->getBody());
  $this
    ->assertEquals([
    'application/json',
  ], $request
    ->getHeader('Content-Type'));
  $this
    ->assertEquals([
    'Basic ' . base64_encode($api_key . ':'),
  ], $request
    ->getHeader('Authorization'));
  $this
    ->assertEquals('POST', $request
    ->getMethod());
}