Skip to content
Merged
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
],
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.95",
"phpunit/phpunit": "^11.5",
"phpunit/phpunit": "^13.4",
"phpstan/phpstan": "^2.3",
"phpstan/phpstan-phpunit": "^2",
"phpstan/extension-installer": "^1.4.3",
Expand Down
16 changes: 8 additions & 8 deletions tests/Command/CiCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testValid(): void
$platform = $this->createMock(Github::class);
$platform->expects(static::once())->method('removePost');

$detector = $this->createMock(PlatformDetector::class);
$detector = static::createStub(PlatformDetector::class);
$detector->method('detect')->willReturn($platform);

$output = new BufferedOutput();
Expand All @@ -39,10 +39,10 @@ public function testValid(): void

public function testNotValid(): void
{
$platform = $this->createMock(Github::class);
$platform = static::createStub(Github::class);
$platform->method('post')->willReturn('https://danger.local/test');

$detector = $this->createMock(PlatformDetector::class);
$detector = static::createStub(PlatformDetector::class);
$detector->method('detect')->willReturn($platform);
$output = new BufferedOutput();

Expand All @@ -55,10 +55,10 @@ public function testNotValid(): void

public function testNotValidWarning(): void
{
$platform = $this->createMock(Github::class);
$platform = static::createStub(Github::class);
$platform->method('post')->willReturn('https://danger.local/test');

$detector = $this->createMock(PlatformDetector::class);
$detector = static::createStub(PlatformDetector::class);
$detector->method('detect')->willReturn($platform);
$output = new BufferedOutput();

Expand All @@ -71,16 +71,16 @@ public function testNotValidWarning(): void

public function testInvalidConfig(): void
{
$platform = $this->createMock(Github::class);
$platform = static::createStub(Github::class);
$platform->method('post')->willReturn('https://danger.local/test');

$detector = $this->createMock(PlatformDetector::class);
$detector = static::createStub(PlatformDetector::class);
$detector->method('detect')->willReturn($platform);

$cmd = new CiCommand($detector, new ConfigLoader(), new Runner(), new HTMLRenderer());

static::expectException(\InvalidArgumentException::class);
static::expectExceptionMessage('Invalid config option given');
static::expectExceptionMessageIsOrContains('Invalid config option given');

$input = new ArgvInput([]);
$input->bind($cmd->getDefinition());
Expand Down
12 changes: 6 additions & 6 deletions tests/Command/GithubCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class GithubCommandTest extends TestCase
#[DataProvider('invalidUrls')]
public function testInvalidUrl(string $url): void
{
$cmd = new GithubCommand($this->createMock(Github::class), new ConfigLoader(), new Runner());
$cmd = new GithubCommand(static::createStub(Github::class), new ConfigLoader(), new Runner());

static::expectException(\InvalidArgumentException::class);
static::expectExceptionMessage('The given url must be a valid Github URL');
static::expectExceptionMessageIsOrContains('The given url must be a valid Github URL');

$cmd->run(new ArgvInput(['danger', $url]), new NullOutput());
}
Expand All @@ -45,10 +45,10 @@ public static function invalidUrls(): array

public function testInvalidConfig(): void
{
$cmd = new GithubCommand($this->createMock(Github::class), new ConfigLoader(), new Runner());
$cmd = new GithubCommand(static::createStub(Github::class), new ConfigLoader(), new Runner());

static::expectException(\InvalidArgumentException::class);
static::expectExceptionMessage('Invalid config option given');
static::expectExceptionMessageIsOrContains('Invalid config option given');

$input = new ArgvInput(['danger', 'https://github.com']);
$input->bind($cmd->getDefinition());
Expand All @@ -59,10 +59,10 @@ public function testInvalidConfig(): void

public function testInvalidPr(): void
{
$cmd = new GithubCommand($this->createMock(Github::class), new ConfigLoader(), new Runner());
$cmd = new GithubCommand(static::createStub(Github::class), new ConfigLoader(), new Runner());

static::expectException(\InvalidArgumentException::class);
static::expectExceptionMessage('The PR links needs to be a string');
static::expectExceptionMessageIsOrContains('The PR links needs to be a string');

$tester = new CommandTester($cmd);
$tester->execute(['pr' => []]);
Expand Down
6 changes: 3 additions & 3 deletions tests/Command/GitlabCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testRunWithoutToken(): void
unset($_SERVER['DANGER_GITLAB_TOKEN']);
}

$cmd = new GitlabCommand($this->createMock(Gitlab::class), new ConfigLoader(), new Runner());
$cmd = new GitlabCommand(static::createStub(Gitlab::class), new ConfigLoader(), new Runner());
$output = new BufferedOutput();
$cmd->run(new ArgvInput(['danger', 'test', '1']), $output);

Expand All @@ -36,10 +36,10 @@ public function testInvalidConfig(): void
{
$_SERVER['DANGER_GITLAB_TOKEN'] = '1';

$cmd = new GitlabCommand($this->createMock(Gitlab::class), new ConfigLoader(), new Runner());
$cmd = new GitlabCommand(static::createStub(Gitlab::class), new ConfigLoader(), new Runner());

static::expectException(\InvalidArgumentException::class);
static::expectExceptionMessage('Invalid config option given');
static::expectExceptionMessageIsOrContains('Invalid config option given');

$input = new ArgvInput(['danger', 'https://github.com']);
$input->bind($cmd->getDefinition());
Expand Down
10 changes: 5 additions & 5 deletions tests/Command/LocalCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class LocalCommandTest extends TestCase
{
public function testInvalidConfig(): void
{
$cmd = new LocalCommand(new ConfigLoader(), new Runner(), $this->createMock(LocalPlatform::class));
$cmd = new LocalCommand(new ConfigLoader(), new Runner(), static::createStub(LocalPlatform::class));

static::expectException(\InvalidArgumentException::class);
static::expectExceptionMessage('Invalid config option given');
static::expectExceptionMessageIsOrContains('Invalid config option given');

$input = new ArgvInput(['danger']);
$input->bind($cmd->getDefinition());
Expand All @@ -36,10 +36,10 @@ public function testInvalidConfig(): void

public function testInvalidRoot(): void
{
$cmd = new LocalCommand(new ConfigLoader(), new Runner(), $this->createMock(LocalPlatform::class));
$cmd = new LocalCommand(new ConfigLoader(), new Runner(), static::createStub(LocalPlatform::class));

static::expectException(\InvalidArgumentException::class);
static::expectExceptionMessage('Invalid root option given');
static::expectExceptionMessageIsOrContains('Invalid root option given');

$input = new ArgvInput(['danger']);
$input->bind($cmd->getDefinition());
Expand Down Expand Up @@ -72,7 +72,7 @@ public function testCommand(): void
(new Filesystem())->remove($tmpDir);
(new Process(['git', 'clone', 'file://' . $tmpDirTarget, $tmpDir]))->mustRun();

$cmd = new LocalCommand(new ConfigLoader(), new Runner(), $this->createMock(LocalPlatform::class));
$cmd = new LocalCommand(new ConfigLoader(), new Runner(), static::createStub(LocalPlatform::class));

$input = new ArgvInput(['danger', '--config=' . \dirname(__DIR__) . '/configs/empty.php', '--root=' . $tmpDir]);
$input->bind($cmd->getDefinition());
Expand Down
4 changes: 2 additions & 2 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testGetReportLevelNotice(): void
{
$config = new Config();

$context = new Context($this->createMock(AbstractPlatform::class));
$context = new Context(static::createStub(AbstractPlatform::class));
$context->notice('test');

static::assertSame(Config::REPORT_LEVEL_NOTICE, $config->getReportLevel($context));
Expand All @@ -65,7 +65,7 @@ public function testGetReportLevelNone(): void
{
$config = new Config();

$context = new Context($this->createMock(AbstractPlatform::class));
$context = new Context(static::createStub(AbstractPlatform::class));

static::assertSame(Config::REPORT_LEVEL_NONE, $config->getReportLevel($context));
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Platform/Github/GithubCommenterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testCommentUsingProxyFails(): void

static::expectException(\RuntimeException::class);

$commenter = new GithubCommenter($this->createMock(Client::class), $client);
$commenter = new GithubCommenter(static::createStub(Client::class), $client);
$commenter->comment(
'test',
'test',
Expand All @@ -50,7 +50,7 @@ public function testCommentUsingProxy(): void
new MockResponse('{"html_url": "https://test.de"}', ['http_response' => 200, 'response_headers' => ['content-type' => 'application/json']]),
]);

$commenter = new GithubCommenter($this->createMock(Client::class), $client);
$commenter = new GithubCommenter(static::createStub(Client::class), $client);
static::assertSame('https://test.de', $commenter->comment(
'test',
'test',
Expand All @@ -66,7 +66,7 @@ public function testRemoveCommentUsingProxy(): void
new MockResponse('{}', ['http_response' => 200, 'response_headers' => ['content-type' => 'application/json']]),
]);

$commenter = new GithubCommenter($this->createMock(Client::class), $client);
$commenter = new GithubCommenter(static::createStub(Client::class), $client);
$commenter->remove(
'test',
'test',
Expand Down
20 changes: 10 additions & 10 deletions tests/Platform/Github/GithubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function testRemovePost(): void

public function testLabels(): void
{
$commenter = $this->createMock(GithubCommenter::class);
$commenter = static::createStub(GithubCommenter::class);

$httpClient = new MockHttpClient([
new MockResponse((string) file_get_contents(__DIR__ . '/payloads/pr.json'), ['http_code' => 200, 'response_headers' => ['content-type' => 'application/json']]),
Expand All @@ -179,7 +179,7 @@ public function testLabels(): void

public function testLabelsWithoutPermission(): void
{
$commenter = $this->createMock(GithubCommenter::class);
$commenter = static::createStub(GithubCommenter::class);

$httpClient = new MockHttpClient([
new MockResponse((string) file_get_contents(__DIR__ . '/payloads/pr.json'), ['http_code' => 200, 'response_headers' => ['content-type' => 'application/json']]),
Expand All @@ -202,7 +202,7 @@ public function testLabelsWithoutPermission(): void

public function testAddLabelOtherErrorNotIgnored(): void
{
$commenter = $this->createMock(GithubCommenter::class);
$commenter = static::createStub(GithubCommenter::class);

$httpClient = new MockHttpClient([
new MockResponse((string) file_get_contents(__DIR__ . '/payloads/pr.json'), ['http_code' => 200, 'response_headers' => ['content-type' => 'application/json']]),
Expand All @@ -217,14 +217,14 @@ public function testAddLabelOtherErrorNotIgnored(): void
$github->load('FriendsOfShopware/FroshPluginUploader', '144');

static::expectException(\RuntimeException::class);
static::expectExceptionMessage('Permission Denied');
static::expectExceptionMessageIsOrContains('Permission Denied');

$github->addLabels('Test');
}

public function testRemoveLabelOtherErrorNotIgnored(): void
{
$commenter = $this->createMock(GithubCommenter::class);
$commenter = static::createStub(GithubCommenter::class);

$httpClient = new MockHttpClient([
new MockResponse((string) file_get_contents(__DIR__ . '/payloads/pr.json'), ['http_code' => 200, 'response_headers' => ['content-type' => 'application/json']]),
Expand All @@ -239,14 +239,14 @@ public function testRemoveLabelOtherErrorNotIgnored(): void
$github->load('FriendsOfShopware/FroshPluginUploader', '144');

static::expectException(\RuntimeException::class);
static::expectExceptionMessage('Permission Denied');
static::expectExceptionMessageIsOrContains('Permission Denied');

$github->removeLabels('Test');
}

public function testHasDangerComment(): void
{
$commenter = $this->createMock(GithubCommenter::class);
$commenter = static::createStub(GithubCommenter::class);
$commenter->method('getCommentIds')->willReturn([1]);

$httpClient = new MockHttpClient([
Expand All @@ -265,7 +265,7 @@ public function testHasDangerComment(): void

public function testFetchingHeadFile(): void
{
$commenter = $this->createMock(GithubCommenter::class);
$commenter = static::createStub(GithubCommenter::class);
$commenter->method('getCommentIds')->willReturn([1]);

$httpClient = new MockHttpClient([
Expand All @@ -286,7 +286,7 @@ public function testFetchingHeadFile(): void

public function testFetchingHeadFileFails(): void
{
$commenter = $this->createMock(GithubCommenter::class);
$commenter = static::createStub(GithubCommenter::class);
$commenter->method('getCommentIds')->willReturn([1]);

$httpClient = new MockHttpClient([
Expand All @@ -302,7 +302,7 @@ public function testFetchingHeadFileFails(): void
$github->load('FriendsOfShopware/FroshPluginUploader', '144');

static::expectException(CouldNotGetFileContentException::class);
static::expectExceptionMessage('Could not get content of file composer.json');
static::expectExceptionMessageIsOrContains('Could not get content of file composer.json');

$github->pullRequest->getFileContent('composer.json');
}
Expand Down
10 changes: 5 additions & 5 deletions tests/Platform/Gitlab/GitlabTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function testLabels(): void

$client = Client::createWithHttpClient(new Psr18Client($mockHttpClient));

$gitlab = new Gitlab($client, $this->createMock(GitlabCommenter::class));
$gitlab = new Gitlab($client, static::createStub(GitlabCommenter::class));
$gitlab->load('test', '1');

$gitlab->removeLabels('Test');
Expand All @@ -177,7 +177,7 @@ public function testHasDangerComment(): void
]);

$client = Client::createWithHttpClient(new Psr18Client($mockHttpClient));
$commenter = $this->createMock(GitlabCommenter::class);
$commenter = static::createStub(GitlabCommenter::class);
$commenter->method('getRelevantNoteIds')->willReturn([1, 2, 3]);

$gitlab = new Gitlab($client, $commenter);
Expand All @@ -195,7 +195,7 @@ public function testFetchingHeadFile(): void

$client = Client::createWithHttpClient(new Psr18Client($mockHttpClient));

$gitlab = new Gitlab($client, $this->createMock(GitlabCommenter::class));
$gitlab = new Gitlab($client, static::createStub(GitlabCommenter::class));
$gitlab->load('test', '1');

$file = $gitlab->pullRequest->getFileContent('composer.json');
Expand All @@ -211,11 +211,11 @@ public function testFetchingHeadFileFails(): void

$client = Client::createWithHttpClient(new Psr18Client($mockHttpClient));

$gitlab = new Gitlab($client, $this->createMock(GitlabCommenter::class));
$gitlab = new Gitlab($client, static::createStub(GitlabCommenter::class));
$gitlab->load('test', '1');

static::expectException(CouldNotGetFileContentException::class);
static::expectExceptionMessage('Could not get content of file composer.json');
static::expectExceptionMessageIsOrContains('Could not get content of file composer.json');

$gitlab->pullRequest->getFileContent('composer.json');
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Platform/PlatformDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class PlatformDetectorTest extends TestCase
{
public function testUnknown(): void
{
$detector = new PlatformDetector($this->createMock(Github::class), $this->createMock(Gitlab::class));
$detector = new PlatformDetector(static::createStub(Github::class), static::createStub(Gitlab::class));
static::expectException(UnsupportedCIException::class);
static::expectExceptionMessage('Could not detect CI Platform');
static::expectExceptionMessageIsOrContains('Could not detect CI Platform');
$detector->detect();
}

Expand All @@ -31,7 +31,7 @@ public function testGithub(): void
$github = $this->createMock(Github::class);
$github->expects(static::once())->method('load');

$detector = new PlatformDetector($github, $this->createMock(Gitlab::class));
$detector = new PlatformDetector($github, static::createStub(Gitlab::class));
static::assertSame($github, $detector->detect());

unset($_SERVER['GITHUB_REPOSITORY'], $_SERVER['GITHUB_PULL_REQUEST_ID'], $_SERVER['GITHUB_TOKEN']);
Expand All @@ -47,7 +47,7 @@ public function testGitlab(): void
$gitlab = $this->createMock(Gitlab::class);
$gitlab->expects(static::once())->method('load');

$detector = new PlatformDetector($this->createMock(Github::class), $gitlab);
$detector = new PlatformDetector(static::createStub(Github::class), $gitlab);
static::assertSame($gitlab, $detector->detect());

unset($_SERVER['GITLAB_CI'], $_SERVER['CI_PROJECT_ID'], $_SERVER['CI_MERGE_REQUEST_IID'], $_SERVER['DANGER_GITLAB_TOKEN']);
Expand Down
4 changes: 2 additions & 2 deletions tests/Renderer/HTMLRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ class HTMLRendererTest extends TestCase
public function testRenderEmpty(): void
{
$renderer = new HTMLRenderer();
static::assertSame(HTMLRenderer::MARKER, $renderer->convert(new Context($this->createMock(Github::class))));
static::assertSame(HTMLRenderer::MARKER, $renderer->convert(new Context(static::createStub(Github::class))));
}

public function testRenderFailure(): void
{
$renderer = new HTMLRenderer();
$context = new Context($this->createMock(Github::class));
$context = new Context(static::createStub(Github::class));
$context->failure('Test');

static::assertStringContainsString(HTMLRenderer::MARKER, $renderer->convert($context));
Expand Down
Loading
Loading