Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions tests/Badge/Model/UseCase/CreateCircleCiBadgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,15 @@ public static function shouldCreateCircleCiBadgeProvider(): array

public function testShouldCreateDefaultBadgeOnError(): void
{
$package = $this->createMockWithoutInvokingTheOriginalConstructor(
Package::class,
['hasStableVersion', 'getLatestStableVersion', 'getOriginalObject']
);
$package = $this->createMockWithoutInvokingTheOriginalConstructor(Package::class);

$this->repository
->method('fetchByRepository')
->willReturn($package);

$repo = $this->createMockWithoutInvokingTheOriginalConstructor(
\Packagist\Api\Result\Package::class,
['getRepository']
);
$repo->expects($this->once())
->method('getRepository')
->will($this->throwException(new \RuntimeException()));

$package->expects($this->once())
->method('getOriginalObject')
->willReturn($repo);
->method('getRepository')
->willThrowException(new \RuntimeException());

$repository = 'PUGX/badge-poser';
$badge = $this->useCase->createCircleCiBadge($repository);
Expand Down
17 changes: 3 additions & 14 deletions tests/Badge/Model/UseCase/CreateComposerLockBadgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use App\Badge\Service\ClientStrategy;
use App\Badge\ValueObject\Repository;
use GuzzleHttp\ClientInterface;
use Packagist\Api\Result\Package;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -55,15 +54,10 @@ public function testShouldCreateComposerLockBadge(int $returnCode, string $expec
->method('fetchByRepository')
->willReturn($package);

$repo = $this->createMock(Package::class);
$repo->expects($this->once())
$package->expects($this->once())
->method('getRepository')
->willReturn('https://github.com/user/repository');

$package->expects($this->once())
->method('getOriginalObject')
->willReturn($repo);

$package->expects($this->once())
->method('getDefaultBranch')
->willReturn('master');
Expand All @@ -90,14 +84,9 @@ public function testShouldCreateDefaultBadgeOnError(): void
->method('fetchByRepository')
->willReturn($package);

$repo = $this->createMock(Package::class);
$repo->expects($this->once())
->method('getRepository')
->will($this->throwException(new \RuntimeException()));

$package->expects($this->once())
->method('getOriginalObject')
->willReturn($repo);
->method('getRepository')
->willThrowException(new \RuntimeException());

$repository = 'PUGX/badge-poser';
$badge = $this->useCase->createComposerLockBadge($repository);
Expand Down
8 changes: 6 additions & 2 deletions tests/Service/SnippetGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function testGenerateAllSnippetsWithAndWithoutFeaturedBadges(): void
->willReturn($routeCollection);
$router
->method('generate')
->willReturnCallback(function (string $name, array $params = []) {
->willReturnCallback(function (string $name, array $params = [], int $referenceType = RouterInterface::ABSOLUTE_URL) {
if ('pugx_badge_packagist' === $name) {
return 'repo_url';
}
Expand Down Expand Up @@ -206,7 +206,11 @@ public function testGenerateAllSnippetsWithAndWithoutFeaturedBadges(): void
'pugx_badge_circleci' => 'img_url12',
];

return $map[$name] ?? 'repo_url';
if (!\array_key_exists($name, $map)) {
throw new \InvalidArgumentException(\sprintf('Unexpected route name "%s" in SnippetGeneratorTest router mock.', $name));
}

return $map[$name];
});

$poser = $this->getMockBuilder(Poser::class)
Expand Down