Skip to content

Commit

Permalink
Merge c32a725 into 778cce4
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm committed Jul 28, 2023
2 parents 778cce4 + c32a725 commit 27fd774
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 11 deletions.
10 changes: 3 additions & 7 deletions test/integration/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
use eiriksm\CosyComposerTest\GetExecuterTrait;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\InputDefinition;
use Violinist\Slug\Slug;

abstract class Base extends TestCase
{
use GetCosyTrait;
use GetExecuterTrait;

protected $usesDirect = true;

protected $defaultSha = 123;
Expand Down Expand Up @@ -47,9 +49,6 @@ public function setUp() : void
$this->cosy = $c;
}

use GetCosyTrait;
use GetExecuterTrait;

protected function createExpectedCommandForPackage($package)
{
return ["composer", 'update', '-n', '--no-ansi', $package, '--with-dependencies'];
Expand Down Expand Up @@ -182,9 +181,6 @@ protected function getMockProviderFactory()
protected function setDummyGithubProvider()
{
$mock_provider = $this->getMockProvider();
$slug = new Slug();
$slug->setProvider('github.com');
$slug->setSlug('a/b');
$mock_provider->method('repoIsPrivate')
->willReturn(true);
$mock_provider->method('getDefaultBranch')
Expand Down
10 changes: 6 additions & 4 deletions test/integration/ComposerUpdateIntegrationBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ function ($cmd) {
$this->setDummyGithubProvider();
$this->placeInitialComposerLock();
$this->mockProvider = $mock_provider;
$this->mockProvider->method('createPullRequest')
->willReturnCallback(function (Slug $slug, array $params) {
return $this->createPullRequest($slug, $params);
});
if (method_exists($this->mockProvider, 'method')) {
$this->mockProvider->method('createPullRequest')
->willReturnCallback(function (Slug $slug, array $params) {
return $this->createPullRequest($slug, $params);
});
}
}

protected function createPullRequest(Slug $slug, array $params)
Expand Down
43 changes: 43 additions & 0 deletions test/integration/FakeGitlab.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace eiriksm\CosyComposerTest\integration;

use eiriksm\CosyComposer\Providers\Gitlab;
use Violinist\Slug\Slug;

class FakeGitlab extends Gitlab
{

public function getClient()
{
return $this->client;
}

public function getdefaultBranch($slug)
{
return 'main';
}

public function getDefaultBase(Slug $slug, $default_branch)
{
return 'abab';
}

public function getPrsNamed(Slug $slug): array
{
return [
'drushdrush9721036' => [
'base' => [
'sha' => 'fefe',
],
'number' => 123,
'title' => 'Not update drush, thats for sure. This will trigger an update of the PR',
]
];
}

public function getBranchesFlattened(Slug $slug)
{
return ['drushdrush9721036'];
}
}
47 changes: 47 additions & 0 deletions test/integration/FakeGitlabClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace eiriksm\CosyComposerTest\integration;

use Gitlab\Api\MergeRequests;
use Gitlab\Client;

class FakeGitlabClient extends Client
{

protected $calls = [];

public function appendCall($call)
{
$this->calls[] = $call;
}

public function getCalls()
{
return $this->calls;
}

public function mergeRequests()
{
return (new class($this) extends MergeRequests {

private $client;

public function __construct(Client $client, int $perPage = null)
{
parent::__construct($client, $perPage);
$this->client = $client;
}

public function update($project_id, $mr_id, $params)
{
$this->client->appendCall([
'MergeRequests',
'update',
$project_id,
$mr_id,
$params,
]);
}
});
}
}
58 changes: 58 additions & 0 deletions test/integration/UpdateGitlabAssigneesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace eiriksm\CosyComposerTest\integration;

use Gitlab\Client;
use Violinist\ProjectData\ProjectData;

class UpdateGitlabAssigneesTest extends UpdateExistingWithAssigneesTest
{

/**
* @var FakeGitlab
*/
protected $myProvider;

public function setUp(): void
{
parent::setUp();
}

protected function getMockProvider()
{
if (!$this->myProvider instanceof FakeGitlab) {
$this->myProvider = new FakeGitlab(new FakeGitlabClient());
}
return $this->myProvider;
}

protected function setDummyGithubProvider()
{
$mock_provider_factory = $this->getMockProviderFactory();
$mock_provider_factory->method('createFromHost')
->willReturn($this->getMockProvider());

$this->cosy->setProviderFactory($mock_provider_factory);
}

/**
* @dataProvider exceptionDataProvider
*/
public function testPrUpdatedWhenConflict($exception_class)
{
$project = new ProjectData();
$project->setRoles(['agency']);
$this->cosy->setProject($project);
$this->cosy->setUrl('https://gitlab.com/a/b');
$this->runtestExpectedOutput();
$calls = $this->myProvider->getClient()->getCalls();
foreach ($calls as $call) {
if ($call[0] !== 'MergeRequests' || $call[1] !== 'update') {
continue;
}
if (empty($call[4]['assignee_ids']) && empty($call[4]['assignee_id'])) {
$this->fail('Assignee ids not set');
}
}
}
}

0 comments on commit 27fd774

Please sign in to comment.