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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

###> phpunit/phpunit ###
/phpunit.xml
.phpunit.result.cache
.phpunit.cache/
###< phpunit/phpunit ###
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"require-dev": {
"happyr/service-mocking": "^1.0",
"symfony/browser-kit": "^7.4",
"phpunit/phpunit": "^9.5",
"phpunit/phpunit": "^12.4",
"symfony/web-profiler-bundle": "^7.4"
},
"config": {
Expand Down
673 changes: 310 additions & 363 deletions composer.lock

Large diffs are not rendered by default.

1,295 changes: 1,295 additions & 0 deletions config/reference.php

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="tests/bootstrap.php">
<coverage processUncoveredFiles="true">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.4/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="tests/bootstrap.php" cacheDirectory=".phpunit.cache">
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</source>
<php>
<ini name="error_reporting" value="-1"/>
<server name="APP_ENV" value="test" force="true"/>
Expand Down
6 changes: 0 additions & 6 deletions symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,6 @@
"sebastian/cli-parser": {
"version": "1.0.1"
},
"sebastian/code-unit": {
"version": "1.0.8"
},
"sebastian/code-unit-reverse-lookup": {
"version": "2.0.3"
},
"sebastian/comparator": {
"version": "4.0.6"
},
Expand Down
2 changes: 1 addition & 1 deletion tests/Api/Label/GithubLabelApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function setUp(): void

$resultPager = $this->getMockBuilder(ResultPager::class)
->disableOriginalConstructor()
->setMethods(['fetchAll'])
->onlyMethods(['fetchAll'])
->getMock();
$resultPager->method('fetchAll')->willReturnCallback(fn () => $this->backendApi->all('x', 'y'));

Expand Down
22 changes: 14 additions & 8 deletions tests/Api/Status/GitHubStatusApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,21 @@ public function testSetIssueStatusRemovesExcessStatuses()
->with(1234)
->willReturn(['Bug', 'Status: Needs Review', 'Status: Needs Work']);

$removedLabels = [];
$this->labelsApi->expects($this->exactly(2))
->method('removeIssueLabel')
->withConsecutive(
[1234, 'Status: Needs Review'],
[1234, 'Status: Needs Work']
);
->willReturnCallback(function ($issueNumber, $label) use (&$removedLabels) {
$removedLabels[] = [$issueNumber, $label];
});

$this->labelsApi->expects($this->once())
->method('addIssueLabel')
->with(1234, 'Status: Reviewed');

$this->api->setIssueStatus(1234, Status::REVIEWED, $this->repository);

$this->assertContains([1234, 'Status: Needs Review'], $removedLabels);
$this->assertContains([1234, 'Status: Needs Work'], $removedLabels);
}

public function testSetIssueStatusDoesNothingIfAlreadySet()
Expand Down Expand Up @@ -145,18 +148,21 @@ public function testSetIssueStatusRemovesUnconfirmedWhenBugIsReviewed()
->with(1234)
->willReturn(['Bug', 'Status: Needs Review', 'Unconfirmed']);

$removedLabels = [];
$this->labelsApi->expects($this->exactly(2))
->method('removeIssueLabel')
->withConsecutive(
[1234, 'Status: Needs Review'],
[1234, 'Unconfirmed']
);
->willReturnCallback(function ($issueNumber, $label) use (&$removedLabels) {
$removedLabels[] = [$issueNumber, $label];
});

$this->labelsApi->expects($this->once())
->method('addIssueLabel')
->with(1234, 'Status: Reviewed');

$this->api->setIssueStatus(1234, Status::REVIEWED, $this->repository);

$this->assertContains([1234, 'Status: Needs Review'], $removedLabels);
$this->assertContains([1234, 'Unconfirmed'], $removedLabels);
}

public function testGetIssueStatus()
Expand Down
10 changes: 6 additions & 4 deletions tests/Controller/WebhookControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Service\RepositoryProvider;
use Happyr\ServiceMocking\ServiceMock;
use Happyr\ServiceMocking\Test\RestoreServiceContainer;
use PHPUnit\Framework\Attributes\DataProvider;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class WebhookControllerTest extends WebTestCase
Expand Down Expand Up @@ -39,9 +40,7 @@ protected function setup(): void
$statusApi->setIssueStatus(2, null, $repository->getRepository('carsonbot-playground/symfony'));
}

/**
* @dataProvider getTests
*/
#[DataProvider('getTests')]
public function testIssueComment($eventHeader, $payloadFilename, $expectedResponse)
{
$client = $this->client;
Expand All @@ -56,7 +55,10 @@ public function testIssueComment($eventHeader, $payloadFilename, $expectedRespon
$this->assertSame($expectedResponse, $responseData);
}

public function getTests(): array
/**
* @return array<string, array{string, string, array<string, mixed>}>
*/
public static function getTests(): array
{
return [
'On issue commented' => [
Expand Down
8 changes: 5 additions & 3 deletions tests/Service/LabelNameExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
use App\Api\Label\StaticLabelApi;
use App\Model\Repository;
use App\Service\LabelNameExtractor;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;

class LabelNameExtractorTest extends TestCase
{
/**
* @dataProvider provideLabels
*/
#[DataProvider('provideLabels')]
public function testExtractLabels(array $expected, string $title)
{
$extractor = new LabelNameExtractor(new StaticLabelApi(), new NullLogger());
Expand All @@ -21,6 +20,9 @@ public function testExtractLabels(array $expected, string $title)
$this->assertSame($expected, $extractor->extractLabels($title, $repo));
}

/**
* @return iterable<array{list<string>, string}>
*/
public static function provideLabels(): iterable
{
yield [['Messenger'], '[Messenger] Foobar'];
Expand Down
4 changes: 2 additions & 2 deletions tests/Service/TaskHandler/CloseDraftHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public function testHandleNotDraft()
{
$prApi = $this->getMockBuilder(NullPullRequestApi::class)
->disableOriginalConstructor()
->setMethods(['show'])
->onlyMethods(['show'])
->getMock();
$prApi->expects($this->once())->method('show')->willReturn(['draft' => false]);

$issueApi = $this->getMockBuilder(NullIssueApi::class)
->disableOriginalConstructor()
->setMethods(['close'])
->onlyMethods(['close'])
->getMock();
$issueApi->expects($this->never())->method('close');

Expand Down
8 changes: 4 additions & 4 deletions tests/Service/TaskHandler/CloseStaleIssuesHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public function testHandleKeepOpen()
{
$labelApi = $this->getMockBuilder(NullLabelApi::class)
->disableOriginalConstructor()
->setMethods(['getIssueLabels', 'lastCommentWasMadeByBot'])
->onlyMethods(['getIssueLabels'])
->getMock();
$labelApi->expects($this->any())->method('getIssueLabels')->willReturn(['Bug', 'Keep open']);

$issueApi = $this->getMockBuilder(NullIssueApi::class)
->disableOriginalConstructor()
->setMethods(['close', 'lastCommentWasMadeByBot', 'show'])
->onlyMethods(['close', 'lastCommentWasMadeByBot', 'show'])
->getMock();
$issueApi->expects($this->any())->method('show')->willReturn(['state' => 'open']);
$issueApi->expects($this->any())->method('lastCommentWasMadeByBot')->willReturn(true);
Expand All @@ -40,13 +40,13 @@ public function testHandleComments()
{
$labelApi = $this->getMockBuilder(NullLabelApi::class)
->disableOriginalConstructor()
->setMethods(['getIssueLabels', 'lastCommentWasMadeByBot'])
->onlyMethods(['getIssueLabels'])
->getMock();
$labelApi->expects($this->any())->method('getIssueLabels')->willReturn(['Bug']);

$issueApi = $this->getMockBuilder(NullIssueApi::class)
->disableOriginalConstructor()
->setMethods(['close', 'lastCommentWasMadeByBot', 'show'])
->onlyMethods(['close', 'lastCommentWasMadeByBot', 'show'])
->getMock();
$issueApi->expects($this->any())->method('show')->willReturn(['state' => 'open']);
$issueApi->expects($this->any())->method('lastCommentWasMadeByBot')->willReturn(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ public function testHandleKeepOpen()
{
$labelApi = $this->getMockBuilder(NullLabelApi::class)
->disableOriginalConstructor()
->setMethods(['getIssueLabels', 'lastCommentWasMadeByBot'])
->onlyMethods(['getIssueLabels'])
->getMock();
$labelApi->expects($this->any())->method('getIssueLabels')->willReturn(['Bug', 'Keep open']);

$issueApi = $this->getMockBuilder(NullIssueApi::class)
->disableOriginalConstructor()
->setMethods(['close', 'lastCommentWasMadeByBot', 'show'])
->onlyMethods(['close', 'lastCommentWasMadeByBot', 'show'])
->getMock();
$issueApi->expects($this->any())->method('show')->willReturn(['state' => 'open']);
$issueApi->expects($this->any())->method('lastCommentWasMadeByBot')->willReturn(true);
$issueApi->expects($this->never())->method('close');

$scheduler = $this->getMockBuilder(TaskScheduler::class)
->disableOriginalConstructor()
->setMethods(['runLater'])
->onlyMethods(['runLater'])
->getMock();
$scheduler->expects($this->never())->method('runLater');

Expand All @@ -47,21 +47,21 @@ public function testHandleComments()
{
$labelApi = $this->getMockBuilder(NullLabelApi::class)
->disableOriginalConstructor()
->setMethods(['getIssueLabels', 'lastCommentWasMadeByBot'])
->onlyMethods(['getIssueLabels'])
->getMock();
$labelApi->expects($this->any())->method('getIssueLabels')->willReturn(['Bug']);

$issueApi = $this->getMockBuilder(NullIssueApi::class)
->disableOriginalConstructor()
->setMethods(['close', 'lastCommentWasMadeByBot', 'show'])
->onlyMethods(['close', 'lastCommentWasMadeByBot', 'show'])
->getMock();
$issueApi->expects($this->any())->method('show')->willReturn(['state' => 'open']);
$issueApi->expects($this->any())->method('lastCommentWasMadeByBot')->willReturn(false);
$issueApi->expects($this->never())->method('close');

$scheduler = $this->getMockBuilder(TaskScheduler::class)
->disableOriginalConstructor()
->setMethods(['runLater'])
->onlyMethods(['runLater'])
->getMock();
$scheduler->expects($this->never())->method('runLater');

Expand All @@ -75,21 +75,21 @@ public function testHandleStale()
{
$labelApi = $this->getMockBuilder(NullLabelApi::class)
->disableOriginalConstructor()
->setMethods(['getIssueLabels'])
->onlyMethods(['getIssueLabels'])
->getMock();
$labelApi->expects($this->any())->method('getIssueLabels')->willReturn(['Bug']);

$issueApi = $this->getMockBuilder(NullIssueApi::class)
->disableOriginalConstructor()
->setMethods(['close', 'lastCommentWasMadeByBot', 'show'])
->onlyMethods(['close', 'lastCommentWasMadeByBot', 'show'])
->getMock();
$issueApi->expects($this->any())->method('show')->willReturn(['state' => 'open']);
$issueApi->expects($this->any())->method('lastCommentWasMadeByBot')->willReturn(true);
$issueApi->expects($this->never())->method('close');

$scheduler = $this->getMockBuilder(TaskScheduler::class)
->disableOriginalConstructor()
->setMethods(['runLater'])
->onlyMethods(['runLater'])
->getMock();
$scheduler->expects($this->once())->method('runLater');

Expand Down
8 changes: 5 additions & 3 deletions tests/Service/WipParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@
namespace App\Tests\Service;

use App\Service\WipParser;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class WipParserTest extends TestCase
{
/**
* @dataProvider titlesProvider
*/
#[DataProvider('titlesProvider')]
public function testMatchTitle(bool $expected, string $title)
{
$this->assertSame($expected, WipParser::matchTitle($title));
}

/**
* @return iterable<array{bool, string}>
*/
public static function titlesProvider(): iterable
{
yield [true, '[WIP] foo'];
Expand Down
12 changes: 7 additions & 5 deletions tests/Subscriber/AutoLabelFromContentSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Model\Repository;
use App\Service\LabelNameExtractor;
use App\Subscriber\AutoLabelFromContentSubscriber;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;
use Symfony\Component\EventDispatcher\EventDispatcher;
Expand All @@ -25,7 +26,7 @@ protected function setUp(): void
{
$this->labelsApi = $this->getMockBuilder(StaticLabelApi::class)
->disableOriginalConstructor()
->setMethods(['addIssueLabels'])
->onlyMethods(['addIssueLabels'])
->getMock();

$autoLabelSubscriber = new AutoLabelFromContentSubscriber($this->labelsApi, new LabelNameExtractor($this->labelsApi, new NullLogger()));
Expand Down Expand Up @@ -59,9 +60,7 @@ public function testAutoLabelIssue()
$this->assertSame(['Messenger'], $responseData['issue_labels']);
}

/**
* @dataProvider getPRTests
*/
#[DataProvider('getPRTests')]
public function testAutoLabelPR($prTitle, $prBody, array $expectedNewLabels)
{
$this->labelsApi->expects($this->once())
Expand All @@ -87,7 +86,10 @@ public function testAutoLabelPR($prTitle, $prBody, array $expectedNewLabels)
$this->assertSame($expectedNewLabels, $responseData['pr_labels']);
}

public function getPRTests()
/**
* @return array<array{string, string, list<string>}>
*/
public static function getPRTests(): array
{
$tests = [];

Expand Down
7 changes: 3 additions & 4 deletions tests/Subscriber/AutoUpdateTitleWithLabelSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Model\Repository;
use App\Service\LabelNameExtractor;
use App\Subscriber\AutoUpdateTitleWithLabelSubscriber;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;
use Symfony\Component\EventDispatcher\EventDispatcher;
Expand All @@ -30,7 +31,7 @@ protected function setUp(): void
$labelsApi = new StaticLabelApi();
$this->pullRequestApi = $this->getMockBuilder(NullPullRequestApi::class)
->disableOriginalConstructor()
->setMethods(['show'])
->onlyMethods(['show'])
->getMock();

$store = $this->getMockBuilder(PersistingStoreInterface::class)->getMock();
Expand Down Expand Up @@ -295,9 +296,7 @@ public function testMultipleUnrecognizedBracketsWithRealLabels()
$this->assertSame('[Console][FrameworkBundle][TODO][WIP][Foo] Some title', $responseData['new_title']);
}

/**
* @dataProvider provideTitles
*/
#[DataProvider('provideTitles')]
public function testBundleNormalizationForSymfonyAi(string $inputTitle, string $expectedTitle)
{
$repository = new Repository('symfony', 'ai', null);
Expand Down
2 changes: 1 addition & 1 deletion tests/Subscriber/MilestoneNewPRSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function setUp(): void
$this->milestonesApi = $this->createMock(GithubMilestoneApi::class);
$this->symfonyVersionProvider = $this->getMockBuilder(SymfonyVersionProvider::class)
->disableOriginalConstructor()
->setMethods(['getCurrentVersion'])
->onlyMethods(['getCurrentVersion'])
->getMock();
$this->symfonyVersionProvider->method('getCurrentVersion')->willReturn('5.1');
$this->subscriber = new MilestoneNewPRSubscriber($this->milestonesApi, $this->symfonyVersionProvider);
Expand Down
Loading