Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm committed Apr 12, 2021
1 parent c0ecf39 commit fab721f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/CosyComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use eiriksm\CosyComposer\Exceptions\GitPushException;
use eiriksm\CosyComposer\Exceptions\OutsideProcessingHoursException;
use eiriksm\CosyComposer\Providers\PublicGithubWrapper;
use GuzzleHttp\Psr7\Request;
use Http\Client\HttpClient;
use Violinist\ChangelogFetcher\ChangelogRetriever;
use Violinist\ChangelogFetcher\DependencyRepoRetriever;
use Violinist\ComposerLockData\ComposerLockData;
Expand Down Expand Up @@ -260,6 +262,25 @@ public function getCacheDir()
return $this->cacheDir;
}

/**
* @return HttpClient
*/
public function getHttpClient()
{
if (!$this->httpClient) {
$this->httpClient = new \Http\Adapter\Guzzle6\Client();
}
return $this->httpClient;
}

/**
* @param HttpClient $httpClient
*/
public function setHttpClient(HttpClient $httpClient)
{
$this->httpClient = $httpClient;
}

/**
* @return string
*/
Expand Down Expand Up @@ -1482,7 +1503,11 @@ protected function attachDrupalAdvisories(array &$alerts)
throw new \Exception('No idea what endpoint to use to check for drupal security release');
}

$data = @file_get_contents(sprintf('https://updates.drupal.org/release-history/drupal/%s', $endpoint));
$client = $this->getHttpClient();
$url = sprintf('https://updates.drupal.org/release-history/drupal/%s', $endpoint);
$request = new Request('GET', $url);
$response = $client->sendRequest($request);
$data = $response->getBody();
$xml = @simplexml_load_string($data);
$known_names = [
'drupal/core-recommended',
Expand Down
10 changes: 10 additions & 0 deletions test/GetCosyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use eiriksm\ArrayOutput\ArrayOutput;
use eiriksm\CosyComposer\CommandExecuter;
use eiriksm\CosyComposer\CosyComposer;
use GuzzleHttp\Psr7\Response;
use Http\Adapter\Guzzle6\Client;
use Violinist\ProjectData\ProjectData;
use Violinist\SymfonyCloudSecurityChecker\SecurityChecker;

Expand All @@ -28,6 +30,14 @@ protected function getMockCosy($dir = null)
$mock_checker = $this->createMock(SecurityChecker::class);
$c->getCheckerFactory()->setChecker($mock_checker);
$c->setUserToken('user-token');
$response = $this->createMock(Response::class);
$response->method('getBody')
->willReturn('<?xml version="1.0" encoding="utf-8"?>
<project xmlns:dc="http://purl.org/dc/elements/1.1/"><releases></releases></project>');
$client = $this->createMock(Client::class);
$client->method('sendRequest')
->willReturn($response);
$c->setHttpClient($client);
return $c;
}
}

0 comments on commit fab721f

Please sign in to comment.