Skip to content

Commit

Permalink
Fix all issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sayan goswami committed Jun 1, 2023
1 parent 58aeb72 commit b972913
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/Domain/Composer/Version/DrupalCoreVersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ private function assertNextMajorLatestMinorBetaOrLaterExists(): void {
$is_alpha = strpos($stability, "alpha");
$is_dev = strpos($stability, "dev");
if ($is_alpha || $is_dev) {
// Assigning to null as beta or later version does not exist.
$this->nextMajorLatestMinorBetaOrLater = NULL;

$message = "No next major, latest minor beta-or-later Drupal core version exists.";
throw new OrcaVersionNotFoundException($message);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Event/CiEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Symfony\Contracts\EventDispatcher\Event;

/**
* CiFailureEvent is called when an ORCA job fails.
* This event is called when an ORCA job completes.
*/
class CiEvent extends Event {

Expand Down
4 changes: 2 additions & 2 deletions src/Helper/Log/GoogleApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Acquia\Orca\Helper\Log;

use Acquia\Orca\Domain\Composer\Version\DrupalCoreVersionResolver;
use Acquia\Orca\Enum\CiJobEnum;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Contracts\HttpClient\Exception\ExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
Expand Down Expand Up @@ -94,11 +95,10 @@ public function __construct(HttpClientInterface $http_client,
*/
public function postData(array $data): void {

// @todo skip tests that have versions defined but are not running.
// Skip tests that have versions defined but are not running.
// If version is null for ex: STATIC_CODE_ANALYSIS jobs then send data
// as it is.
if (is_null($data['version'])) {
// @todo specify something appropriate here.
$data['version'] = 'NA';
}
elseif (!$this->version->existsPredefined($data['version'])) {
Expand Down
12 changes: 11 additions & 1 deletion tests/Console/Command/Ci/CiRunCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\EventDispatcher\EventDispatcher;

/**
* @property \Acquia\Orca\Domain\Ci\CiJobFactory|\Prophecy\Prophecy\ObjectProphecy $ciJobFactory
Expand All @@ -33,6 +34,7 @@ class CiRunCommandTest extends CommandTestBase {
protected AbstractCiJob|ObjectProphecy $ciJob;
protected CiRunOptionsFactory|ObjectProphecy $ciRunOptionsFactory;
protected CiRunOptions|ObjectProphecy $ciRunOptions;
protected EventDispatcher|ObjectProphecy $eventDispatcher;

protected function setUp(): void {
$this->ciRunOptions = $this->prophesize(CiRunOptions::class);
Expand All @@ -41,16 +43,24 @@ protected function setUp(): void {
->create(Argument::any())
->willReturn($this->ciRunOptions->reveal());
$this->ciJob = $this->prophesize(CiTestJob::class);
$this->ciJob
->jobName()
->willReturn(new CiJobEnum(CiJobEnum::STATIC_CODE_ANALYSIS));
$this->ciJobFactory = $this->prophesize(CiJobFactory::class);
$this->ciJobFactory
->create($this->validJob())
->willReturn($this->ciJob->reveal());
$this->eventDispatcher = $this->prophesize(EventDispatcher::class);
$this->eventDispatcher
->dispatch(Argument::cetera())
->willReturn(new \stdClass());
}

protected function createCommand(): Command {
$ci_run_options_factory = $this->ciRunOptionsFactory->reveal();
$ci_job_factory = $this->ciJobFactory->reveal();
return new CiRunCommand($ci_job_factory, $ci_run_options_factory);
$event_dispatcher = $this->eventDispatcher->reveal();
return new CiRunCommand($ci_job_factory, $ci_run_options_factory, $event_dispatcher);
}

private function validSutName(): string {
Expand Down
118 changes: 118 additions & 0 deletions tests/Helper/Log/GoogleApiClientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

namespace Acquia\Orca\Tests\Helper\Log;

use Acquia\Orca\Domain\Composer\Version\DrupalCoreVersionResolver;
use Acquia\Orca\Enum\CiJobEnum;
use Acquia\Orca\Enum\DrupalCoreVersionEnum;
use Acquia\Orca\Helper\Log\GoogleApiClient;
use Acquia\Orca\Tests\TestCase;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;

/**
* @property \Acquia\Orca\Domain\Composer\Version\DrupalCoreVersionResolver|\Prophecy\Prophecy\ObjectProphecy $version
*/


class GoogleApiClientTest extends TestCase {

protected DrupalCoreVersionResolver|ObjectProphecy $version;

/**
* @var \Prophecy\Prophecy\ObjectProphecy|\Symfony\Contracts\HttpClient\HttpClientInterface
*/
private HttpClientInterface|ObjectProphecy $httpClient;

/**
* @var \Prophecy\Prophecy\ObjectProphecy|\Symfony\Component\Console\Style\SymfonyStyle
*/
private ObjectProphecy|SymfonyStyle $output;

/**
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
*/
protected function setUp(): void {

$this->version = $this->prophesize(DrupalCoreVersionResolver::class);

$response = $this->prophesize(ResponseInterface::class);
$response->getStatusCode()
->willReturn(200);
$response->toArray()
->willReturn([
'access_token' => 'sample token',
'updates' => [
'updatedData' => [
'values' => [
'0' => ['Sample Data', 'Sample Data']
]
]
]
]);
$this->httpClient = $this->prophesize(HttpClientInterface::class);
$this->httpClient
->request(Argument::cetera())
->willReturn($response);
$this->output = $this->prophesize(SymfonyStyle::class);

}

protected function createGoogleClient(): GoogleApiClient {
$http_client = $this->httpClient->reveal();
$output_symfony = $this->output->reveal();
$version_resolver = $this->version->reveal();
$client_id = "Sample Client";
$client_secret = "Sample Secret";
$refresh_token = "Refresh Token";
return new GoogleApiClient($http_client, $output_symfony, $version_resolver, $client_id, $client_secret, $refresh_token);
}

/**
*
* @throws \Acquia\Orca\Exception\OrcaVersionNotFoundException|\Acquia\Orca\Exception\OrcaHttpException
*/
public function testPostDataWithNullVersion(): void {

$data = [
'job' => 'STATIC_CODE_ANALYSIS',
'phase' => 'script',
'sut' => 'drupal/example',
'status' => 'PASS',
'version' => NULL,
];
$this->version
->resolvePredefined(Argument::any())
->shouldNotBeCalled();

$google_client = $this->createGoogleClient();
$google_client->postData($data);
}

/**
* @throws \Acquia\Orca\Exception\OrcaHttpException
* @throws \Acquia\Orca\Exception\OrcaVersionNotFoundException
*/
public function testPostDataWithLatestDrupalVersion(): void {

$data = [
'job' => 'INTEGRATED_TEST_ON_CURRENT',
'phase' => 'script',
'sut' => 'drupal/example',
'status' => 'PASS',
'version' => DrupalCoreVersionEnum::CURRENT(),
];
$this->version
->existsPredefined(Argument::any())
->shouldBeCalled();
$this->version
->resolvePredefined(Argument::any())
->shouldBeCalledOnce();

$google_client = $this->createGoogleClient();
$google_client->postData($data);
}
}

0 comments on commit b972913

Please sign in to comment.