Skip to content

Commit

Permalink
Merge branch 'master' into feat/clone-output
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm committed Apr 24, 2022
2 parents e88429c + d5c4eee commit 6ec137b
Show file tree
Hide file tree
Showing 5 changed files with 333 additions and 1 deletion.
11 changes: 11 additions & 0 deletions test/fixtures/composer.concurrent.update_branch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"require": {
"psr/log": "~1.1.3",
"psr/cache": "~1.0.0"
},
"extra": {
"violinist": {
"number_of_concurrent_updates": 1
}
}
}
119 changes: 119 additions & 0 deletions test/fixtures/composer.concurrent.update_branch.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "c8ba547438f3b94d6e7e25fedfea753f",
"packages": [
{
"name": "psr/cache",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/cache.git",
"reference": "9e66031f41fbbdda45ee11e93c45d480ccba3eb3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/cache/zipball/9e66031f41fbbdda45ee11e93c45d480ccba3eb3",
"reference": "9e66031f41fbbdda45ee11e93c45d480ccba3eb3",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Cache\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for caching libraries",
"keywords": [
"cache",
"psr",
"psr-6"
],
"support": {
"issues": "https://github.com/php-fig/cache/issues",
"source": "https://github.com/php-fig/cache/tree/master"
},
"time": "2015-12-11T02:52:07+00:00"
},
{
"name": "psr/log",
"version": "1.1.3",
"source": {
"type": "git",
"url": "https://github.com/php-fig/log.git",
"reference": "0f73288fd15629204f9d42b7055f72dacbe811fc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/0f73288fd15629204f9d42b7055f72dacbe811fc",
"reference": "0f73288fd15629204f9d42b7055f72dacbe811fc",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Log\\": "Psr/Log/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for logging libraries",
"homepage": "https://github.com/php-fig/log",
"keywords": [
"log",
"psr",
"psr-3"
],
"support": {
"source": "https://github.com/php-fig/log/tree/1.1.3"
},
"time": "2020-03-23T09:12:05+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.3.0"
}
118 changes: 118 additions & 0 deletions test/fixtures/composer.concurrent.update_branch.lock.updated
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "c8ba547438f3b94d6e7e25fedfea753f",
"packages": [
{
"name": "psr/cache",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/cache.git",
"reference": "d11b50ad223250cf17b86e38383413f5a6764bf8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8",
"reference": "d11b50ad223250cf17b86e38383413f5a6764bf8",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Cache\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for caching libraries",
"keywords": [
"cache",
"psr",
"psr-6"
],
"support": {
"source": "https://github.com/php-fig/cache/tree/master"
},
"time": "2016-08-06T20:24:11+00:00"
},
{
"name": "psr/log",
"version": "1.1.4",
"source": {
"type": "git",
"url": "https://github.com/php-fig/log.git",
"reference": "d49695b909c3b7628b6289db5479a1c204601f11"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11",
"reference": "d49695b909c3b7628b6289db5479a1c204601f11",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Log\\": "Psr/Log/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common interface for logging libraries",
"homepage": "https://github.com/php-fig/log",
"keywords": [
"log",
"psr",
"psr-3"
],
"support": {
"source": "https://github.com/php-fig/log/tree/1.1.4"
},
"time": "2021-05-03T11:20:27+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.3.0"
}
9 changes: 8 additions & 1 deletion test/integration/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ protected function setDummyGithubProvider()
$mock_provider->method('getDefaultBranch')
->willReturn('master');
$mock_provider->method('getBranchesFlattened')
->willReturn([]);
->willReturnCallback(function () {
return $this->getBranchesFlattened();
});
$default_sha = 123;
$mock_provider->method('getDefaultBase')
->willReturn($default_sha);
Expand All @@ -194,6 +196,11 @@ protected function setDummyGithubProvider()
$this->cosy->setProviderFactory($mock_provider_factory);
}

protected function getBranchesFlattened()
{
return [];
}

protected function getPrsNamed()
{
return [];
Expand Down
77 changes: 77 additions & 0 deletions test/integration/UpdateConcurrentOutdatedBranchTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace eiriksm\CosyComposerTest\integration;

use eiriksm\ArrayOutput\ArrayOutput;

class UpdateConcurrentOutdatedBranchTest extends ComposerUpdateIntegrationBase
{
protected $composerAssetFiles = 'composer.concurrent.update_branch';
private $sha;

public function setUp()
{
parent::setUp();
$this->sha = 123;

$mock_output = $this->createMock(ArrayOutput::class);
$mock_output->method('fetch')
->willReturn([
[
'{"installed": [{"name": "psr/cache", "version": "1.0.0", "latest": "1.0.1", "latest-status": "semver-safe-update"},{"name": "psr/log", "version": "1.1.3", "latest": "1.1.4", "latest-status": "semver-safe-update"}]}',
]
]);
$this->cosy->setOutput($mock_output);
}

public function testUpdateConcurrentWithOutdatedBranch()
{
$this->sha = '456';
$this->runtestExpectedOutput();
// This means we expect the first package (psr/cache) to be updated, since the PR is out of date. This should
// show in the messages then.
$this->assertOutputContainsMessage('Creating pull request from psrcache100101', $this->cosy);
$msg = $this->findMessage('Running composer update for package psr/log', $this->cosy);
self::assertFalse($msg);
}

public function testUpdateConcurrentWithUpToDateBranch()
{
$this->runtestExpectedOutput();
$this->assertOutputContainsMessage('Skipping psr/cache because a pull request already exists', $this->cosy);
$this->assertOutputContainsMessage('Skipping psr/log because the number of max concurrent PRs (1) seems to have been reached', $this->cosy);
}

protected function handleExecutorReturnCallback($cmd, &$return)
{
$packages = [
'psr/log',
'psr/cache',
];
foreach ($packages as $package) {
$expected_command = $this->createExpectedCommandForPackage($package);
if ($expected_command === $cmd) {
$this->placeUpdatedComposerLock();
}
}
}

protected function getPrsNamed()
{
return [
'psrcache100101' => [
'base' => [
'sha' => $this->sha,
],
'title' => 'Update psr/cache from 1.0.0 to 1.0.1',
],
];
}

protected function getBranchesFlattened()
{
return [
'psrcache100101',
];
}
}

0 comments on commit 6ec137b

Please sign in to comment.