Skip to content

Commit

Permalink
Add an automerge base
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm committed Jun 21, 2022
1 parent 202e6ec commit 18b2081
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 77 deletions.
61 changes: 61 additions & 0 deletions test/integration/AutoMergeBase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace eiriksm\CosyComposerTest\integration;

use Github\Exception\ValidationFailedException;
use Violinist\Slug\Slug;

abstract class AutoMergeBase extends ComposerUpdateIntegrationBase
{
protected $isUpdate = false;

protected function getBranchesFlattened()
{
if (!$this->isUpdate) {
return [];
}
return ['psrlog113114'];
}

protected function createPullRequest(Slug $slug, array $params)
{
if (!$this->isUpdate) {
return parent::createPullRequest($slug, $params);
}
throw new ValidationFailedException('I want you to update please');
}

protected function getPrsNamed()
{
if (!$this->isUpdate) {
return [];
}
return [
'psrlog113114' => [
'base' => [
'sha' => 456,
],
'title' => 'not the same as the other',
'number' => 666,
],
];
}

/**
* @dataProvider getUpdateVariations
*/
public function testAutomerge($should_have_updated)
{
$this->isUpdate = $should_have_updated;
$this->checkPrUrl = !$should_have_updated;
$this->runtestExpectedOutput();
}

public function getUpdateVariations()
{
return [
[true],
[false],
];
}
}
20 changes: 1 addition & 19 deletions test/integration/AutomergeSecurityNoUpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Test for automerge being enabled for security, but no security updates.
*/
class AutomergeSecurityNoUpdateTest extends ComposerUpdateIntegrationBase
class AutomergeSecurityNoUpdateTest extends AutoMergeBase
{
protected $composerAssetFiles = 'composer.automerge_sec_no_update';
protected $hasUpdatedPsrLog = false;
Expand All @@ -26,22 +26,4 @@ protected function createPullRequest(Slug $slug, array $params)
}
throw new ValidationFailedException('I want you to update please');
}

/**
* @dataProvider getUpdateVariations
*/
public function testAutomerge($should_have_updated)
{
$this->isUpdate = $should_have_updated;
$this->checkPrUrl = !$should_have_updated;
$this->runtestExpectedOutput();
}

public function getUpdateVariations()
{
return [
[true],
[false],
];
}
}
53 changes: 1 addition & 52 deletions test/integration/AutomergeSecurityUpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Test for automerge being enabled for security, but no security updates.
*/
class AutomergeSecurityUpdateTest extends ComposerUpdateIntegrationBase
class AutomergeSecurityUpdateTest extends AutoMergeBase
{
protected $composerAssetFiles = 'composer.automerge_sec_update';
protected $hasUpdatedPsrLog = false;
Expand All @@ -19,7 +19,6 @@ class AutomergeSecurityUpdateTest extends ComposerUpdateIntegrationBase
protected $packageVersionForToUpdateOutput = '1.1.4';
protected $hasAutoMerge = true;
protected $checkPrUrl = true;
private $isUpdate = false;

public function setUp()
{
Expand All @@ -31,54 +30,4 @@ public function setUp()
]);
$this->cosy->getCheckerFactory()->setChecker($checker);
}

protected function getBranchesFlattened()
{
if (!$this->isUpdate) {
return [];
}
return ['psrlog113114'];
}

protected function createPullRequest(Slug $slug, array $params)
{
if (!$this->isUpdate) {
return parent::createPullRequest($slug, $params);
}
throw new ValidationFailedException('I want you to update please');
}

protected function getPrsNamed()
{
if (!$this->isUpdate) {
return [];
}
return [
'psrlog113114' => [
'base' => [
'sha' => 456,
],
'title' => 'not the same as the other',
'number' => 666,
],
];
}

/**
* @dataProvider getUpdateVariations
*/
public function testAutomerge($should_have_updated)
{
$this->isUpdate = $should_have_updated;
$this->checkPrUrl = !$should_have_updated;
$this->runtestExpectedOutput();
}

public function getUpdateVariations()
{
return [
[true],
[false],
];
}
}
10 changes: 4 additions & 6 deletions test/integration/AutomergeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

namespace eiriksm\CosyComposerTest\integration;

use Github\Exception\ValidationFailedException;
use Violinist\Slug\Slug;

/**
* Test for automerge being enabled.
*/
class AutomergeTest extends ComposerUpdateIntegrationBase
class AutomergeTest extends AutoMergeBase
{
protected $composerAssetFiles = 'composer.automerge';
protected $hasUpdatedPsrLog = false;
Expand All @@ -15,9 +18,4 @@ class AutomergeTest extends ComposerUpdateIntegrationBase
protected $packageVersionForToUpdateOutput = '1.1.4';
protected $hasAutoMerge = true;
protected $checkPrUrl = true;

public function testAutomerge()
{
$this->runtestExpectedOutput();
}
}

0 comments on commit 18b2081

Please sign in to comment.