Skip to content

Commit

Permalink
Add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
phenaproxima committed Oct 26, 2023
1 parent 2eee68d commit f3d357a
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,40 @@ public function testMaxBytesOverride(): void
]);
$this->assertSame(123, Repository::$maxBytes);
}

/**
* @covers ::getTargetFromUrl
*/
public function testTargetFromUrl(): void
{
$updater = $this->prophesize(ComposerCompatibleUpdater::class);

$updater->getLength('packages.json')
->shouldBeCalled()
->willReturn(39);
$updater->getLength('another/target.json')
->shouldBeCalled()
->willReturn(59);

$repository = $this->mockRepository($updater->reveal(), [
'url' => 'http://localhost/repo',
]);
$event = new PreFileDownloadEvent(
PluginEvents::PRE_FILE_DOWNLOAD,
$this->composer->getLoop()->getHttpDownloader(),
"http://localhost/repo/packages.json",
'metadata',
[
'repository' => $repository,
]
);
$repository->prepareMetadata($event);
$this->assertSame(39, $event->getTransportOptions()['max_file_size']);

// If the URL of the metadata doesn't start with the repository URL,
// we should fall back to using the URL's path component as the target.
$event->setProcessedUrl('http://localhost/another/target.json');
$repository->prepareMetadata($event);
$this->assertSame(59, $event->getTransportOptions()['max_file_size']);
}
}

0 comments on commit f3d357a

Please sign in to comment.