Skip to content

Commit a1a7ad5

Browse files
committed
fixing a test bug where we need to clean off labels before trying
1 parent 3a1a744 commit a1a7ad5

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/Issues/GitHub/GitHubStatusApi.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ public function __construct(CachedLabelsApi $labelsApi, LoggerInterface $logger)
3636

3737
/**
3838
* @param int $issueNumber The GitHub issue number
39-
* @param string $newStatus A Status::* constant
39+
* @param string|null $newStatus A Status::* constant
4040
* @param Repository $repository
4141
*/
4242
public function setIssueStatus($issueNumber, $newStatus, Repository $repository)
4343
{
44-
if (!isset(self::$statusToLabel[$newStatus])) {
44+
if (null !== $newStatus && !isset(self::$statusToLabel[$newStatus])) {
4545
throw new \InvalidArgumentException(sprintf('Invalid status "%s"', $newStatus));
4646
}
4747

48-
$newLabel = self::$statusToLabel[$newStatus];
48+
$newLabel = $newStatus === null ? null : self::$statusToLabel[$newStatus];
4949
$this->logger->info(sprintf(
5050
'Fetching issue labels for issue %s, repository %s',
5151
$issueNumber,
@@ -86,7 +86,7 @@ public function setIssueStatus($issueNumber, $newStatus, Repository $repository)
8686
}
8787

8888
// Ignored if the label is already set
89-
if ($addLabel) {
89+
if ($addLabel && $newLabel) {
9090
$this->logger->debug(sprintf(
9191
'Adding label "%s" to issue %s on repository %s',
9292
$newLabel,

tests/Controller/WebhookControllerTest.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,38 @@
22

33
namespace App\Tests\Controller;
44

5+
use App\Issues\StatusApi;
6+
use App\Repository\Provider\RepositoryProviderInterface;
57
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
68

79
class WebhookControllerTest extends WebTestCase
810
{
11+
private $client;
12+
13+
public function setup()
14+
{
15+
if ($this->client) {
16+
return;
17+
}
18+
19+
$this->client = $this->createClient();
20+
$repository = self::$container->get(RepositoryProviderInterface::class);
21+
$statusApi = self::$container->get(StatusApi::class);
22+
23+
// the labels need to be off this issue for one test to pass
24+
$statusApi->setIssueStatus(
25+
5,
26+
null,
27+
$repository->getRepository('weaverryan/symfony')
28+
);
29+
}
30+
931
/**
1032
* @dataProvider getTests
1133
*/
1234
public function testIssueComment($eventHeader, $payloadFilename, $expectedResponse)
1335
{
14-
$client = $this->createClient();
36+
$client = $this->client;
1537
$body = file_get_contents(__DIR__.'/../webhook_examples/'.$payloadFilename);
1638
$client->request('POST', '/webhooks/github', [], [], ['HTTP_X-Github-Event' => $eventHeader], $body);
1739
$response = $client->getResponse();
@@ -36,7 +58,7 @@ public function getTests()
3658
'pull_request.opened.json',
3759
['pull_request' => 3, 'status_change' => 'needs_review', 'pr_labels' => ['Bug']],
3860
],
39-
'On issue labeled "bug"' => [
61+
'On issue labeled bug' => [
4062
'issues',
4163
'issues.labeled.bug.json',
4264
['issue' => 5, 'status_change' => 'needs_review'],

0 commit comments

Comments
 (0)