You are here

public function BitbucketManagerTest::testGetBuildHookDetailsForPluginConfiguration in Build Hooks 8.2

Same name and namespace in other branches
  1. 3.x modules/build_hooks_bitbucket/tests/src/Unit/BitbucketManagerTest.php \Drupal\Tests\build_hooks_bitbucket\Unit\BitbucketManagerTest::testGetBuildHookDetailsForPluginConfiguration()

Tests getting build hook details..

File

modules/build_hooks_bitbucket/tests/src/Unit/BitbucketManagerTest.php, line 20

Class

BitbucketManagerTest
Defines a test for BitBucketManager.

Namespace

Drupal\Tests\build_hooks_bitbucket\Unit

Code

public function testGetBuildHookDetailsForPluginConfiguration() {
  $configFactory = $this
    ->getConfigFactoryStub([
    'build_hooks_bitbucket.settings' => [
      'username' => 'fooUser',
      'password' => 'barPassword',
    ],
  ]);
  $httpClient = $this
    ->prophesize(ClientInterface::class);
  $manager = new BitbucketManager($configFactory, $httpClient
    ->reveal());
  $random = $this
    ->getRandomGenerator()
    ->name();
  $settings = [
    'repo' => [
      'workspace' => $random . '-workspace',
      'slug' => $random . '-slug',
    ],
    'ref' => [
      'name' => $random . '-ref',
      'type' => 'branch',
    ],
    'selector' => [
      'name' => $random . '-selector',
      'type' => 'pull-requests',
    ],
  ];
  $result = $manager
    ->getBuildHookDetailsForPluginConfiguration($settings);
  $this
    ->assertInstanceOf(BuildHookDetails::class, $result);
  $this
    ->assertEquals('https://api.bitbucket.org/2.0/repositories/' . $random . '-workspace/' . $random . '-slug/pipelines/', $result
    ->getUrl());
  $this
    ->assertEquals('POST', $result
    ->getMethod());
  $expectedOptions = [
    'json' => [
      'target' => [
        'type' => 'pipeline_ref_target',
        'ref_name' => $random . '-ref',
        'ref_type' => 'branch',
        'selector' => [
          'type' => 'pull-requests',
          'pattern' => $random . '-selector',
        ],
      ],
    ],
    'auth' => [
      'fooUser',
      'barPassword',
    ],
  ];
  $this
    ->assertEquals($expectedOptions, $result
    ->getOptions());
}