Skip to content

Commit

Permalink
Split version lookup into Packagist only and Packagist with Drupal.org.
Browse files Browse the repository at this point in the history
  • Loading branch information
TravisCarden committed Oct 7, 2020
1 parent 6ffb5b9 commit bce9ea9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Domain/Composer/Version/VersionFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function findLatestVersion(string $package_name, ?string $constraint, boo
$stability = 'dev';
}

$selector = $this->versionSelectorFactory->create();
$selector = $this->versionSelectorFactory->createWithDrupalDotOrg();
$candidate = $selector->findBestCandidate($package_name, $constraint, NULL, $stability);

if (!$candidate) {
Expand Down
15 changes: 13 additions & 2 deletions src/Domain/Composer/Version/VersionSelectorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,23 @@ public function __construct(PoolFactory $factory) {
}

/**
* Creates a Composer version selector for Packagist and Drupal.org.
* Creates a Composer version selector with Packagist only.
*
* @return \Composer\Package\Version\VersionSelector
* The version selector.
*/
public function create(): VersionSelector {
public function createWithPackagistOnly(): VersionSelector {
$pool = $this->factory->createWithPackagistOnly();
return new VersionSelector($pool);
}

/**
* Creates a Composer version selector with Packagist and drupal.org.
*
* @return \Composer\Package\Version\VersionSelector
* The version selector.
*/
public function createWithDrupalDotOrg(): VersionSelector {
$pool = $this->factory->createWithDrupalDotOrg();
return new VersionSelector($pool);
}
Expand Down
5 changes: 4 additions & 1 deletion tests/Domain/Composer/Version/VersionFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ protected function setUp(): void {

private function createVersionFinder(): VersionFinder {
$this->versionSelectorFactory
->create()
->createWithPackagistOnly()
->willReturn($this->versionSelector->reveal());
$this->versionSelectorFactory
->createWithDrupalDotOrg()
->willReturn($this->versionSelector->reveal());
$version_selector_factory = $this->versionSelectorFactory->reveal();
return new VersionFinder($version_selector_factory);
Expand Down
28 changes: 25 additions & 3 deletions tests/Domain/Composer/Version/VersionSelectorFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,37 @@ protected function createVersionSelectorFactory(): VersionSelectorFactory {

/**
* @covers ::__construct
* @covers ::create
* @covers ::createWithPackagistOnly
*/
public function testCreate(): void {
public function testCreateWithPackagistOnly(): void {
$this->poolFactory
->createWithPackagistOnly()
->shouldBeCalledOnce();
$this->poolFactory
->createWithDrupalDotOrg()
->shouldNotBeCalled();
$factory = $this->createVersionSelectorFactory();

$selector = $factory->createWithPackagistOnly();

/* @noinspection UnnecessaryAssertionInspection */
self::assertInstanceOf(VersionSelector::class, $selector, 'Created a version selector.');
}

/**
* @covers ::__construct
* @covers ::createWithDrupalDotOrg
*/
public function testCreateWithDrupalDotOrg(): void {
$this->poolFactory
->createWithDrupalDotOrg()
->shouldBeCalledOnce();
$this->poolFactory
->createWithPackagistOnly()
->shouldNotBeCalled();
$factory = $this->createVersionSelectorFactory();

$selector = $factory->create();
$selector = $factory->createWithDrupalDotOrg();

/* @noinspection UnnecessaryAssertionInspection */
self::assertInstanceOf(VersionSelector::class, $selector, 'Created a version selector.');
Expand Down

0 comments on commit bce9ea9

Please sign in to comment.