-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
5 changed files
with
157 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
]); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} | ||
} | ||
} |