Skip to content

Commit

Permalink
Add method and test
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Aug 31, 2021
1 parent c88d339 commit 8bb6c72
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Command/Dispatcher/DispatchSettingsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ private function updateRepositories(Project $project): void
];

if ($project->hasBranches()) {
$defaultBranch = $project->stableBranch() ?? $project->unstableBranch();
$infoToUpdate['default_branch'] = $defaultBranch->name();
$infoToUpdate['default_branch'] = $project->defaultBranch()->name();
}

foreach ($infoToUpdate as $info => $value) {
Expand Down
9 changes: 9 additions & 0 deletions src/Domain/Value/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,15 @@ public function stableBranch(): ?Branch
return $this->branches[1] ?? null;
}

public function defaultBranch(): Branch
{
if (!$this->hasBranches()) {
throw NoBranchesAvailable::forProject($this);
}

return $this->stableBranch() ?? $this->unstableBranch();
}

public function isStable(): bool
{
return null !== $this->stableBranch();
Expand Down
156 changes: 156 additions & 0 deletions tests/Domain/Value/ProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,162 @@ public function documentationBadgeSlugProvider(): \Generator
php_extensions: []
docs_path: docs
tests_path: tests
CONFIG,
];
}

/**
* @test
*
* @dataProvider defaultBranchProvider
*/
public function defaultBranch(string $expected, string $yamlConfig): void
{
$package = new Package();
$package->fromArray([
'name' => 'sonata-project/admin-bundle',
'repository' => 'https://github.com/sonata-project/SonataAdminBundle',
]);

$config = Yaml::parse($yamlConfig);

$project = Project::fromValues(
'admin-bundle',
$config['admin-bundle'],
$package
);

self::assertSame($expected, $project->defaultBranch()->name());
}

/**
* @return \Generator<string, array<0: string, 1: string>>
*/
public function defaultBranchProvider(): \Generator
{
yield 'master' => [
'master',
<<<CONFIG
admin-bundle:
composer_version: '1'
phpstan: true
psalm: true
panther: true
excluded_files: []
custom_gitignore_part: ~
custom_gitattributes_part: ~
custom_doctor_rst_whitelist_part: ~
has_documentation: true
documentation_badge_slug: ~
branches:
master:
php: ['7.3', '7.4']
target_php: ~
frontend: true
custom_gitignore_part: ~
variants:
symfony/symfony: ['4.4']
sonata-project/block-bundle: ['4']
tools: []
php_extensions: []
docs_path: docs
tests_path: tests
CONFIG,
];

yield 'master - 3.x' => [
'3.x',
<<<CONFIG
admin-bundle:
composer_version: '1'
phpstan: true
psalm: true
panther: true
excluded_files: []
custom_gitignore_part: ~
custom_gitattributes_part: ~
custom_doctor_rst_whitelist_part: ~
has_documentation: true
documentation_badge_slug: ~
branches:
master:
php: ['7.3', '7.4']
target_php: ~
frontend: true
custom_gitignore_part: ~
variants:
symfony/symfony: ['4.4']
sonata-project/block-bundle: ['4']
tools: []
php_extensions: []
docs_path: docs
tests_path: tests
3.x:
php: ['7.3', '7.4']
target_php: ~
frontend: true
custom_gitignore_part: ~
variants:
symfony/symfony: ['4.4']
sonata-project/block-bundle: ['4']
tools: []
php_extensions: []
docs_path: docs
tests_path: tests
CONFIG,
];

yield 'master - 4.x - 3.x' => [
'4.x',
<<<CONFIG
admin-bundle:
composer_version: '1'
phpstan: true
psalm: true
panther: true
excluded_files: []
custom_gitignore_part: ~
custom_gitattributes_part: ~
custom_doctor_rst_whitelist_part: ~
has_documentation: true
documentation_badge_slug: ~
branches:
master:
php: ['7.3', '7.4']
target_php: ~
frontend: true
custom_gitignore_part: ~
variants:
symfony/symfony: ['4.4']
sonata-project/block-bundle: ['4']
tools: []
php_extensions: []
docs_path: docs
tests_path: tests
4.x:
php: ['7.3', '7.4']
target_php: ~
frontend: true
custom_gitignore_part: ~
variants:
symfony/symfony: ['4.4']
sonata-project/block-bundle: ['4']
tools: []
php_extensions: []
docs_path: docs
tests_path: tests
3.x:
php: ['7.3', '7.4']
target_php: ~
frontend: true
custom_gitignore_part: ~
variants:
symfony/symfony: ['4.4']
sonata-project/block-bundle: ['4']
tools: []
php_extensions: []
docs_path: docs
tests_path: tests
CONFIG,
];
}
Expand Down

0 comments on commit 8bb6c72

Please sign in to comment.