Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
Add tests for the feedback feature
Browse files Browse the repository at this point in the history
  • Loading branch information
atomiix committed Jun 26, 2020
1 parent 733829e commit 2e50440
Show file tree
Hide file tree
Showing 15 changed files with 1,696 additions and 163 deletions.
8 changes: 7 additions & 1 deletion app/config/services_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ services:
# Integration tests shouldn't post comments to github
Psr\Log\NullLogger:

Tests\AppBundle\Search\FakeRepository:
decorates: AppBundle\Search\RepositoryInterface

Tests\AppBundle\Organisations\FakeRepository:
- ['%repository_username%']

Tests\AppBundle\Comments\FakeCommentApi:
- '@Github\Api\Issue\Comments'
- '%repository_username%'
Expand All @@ -53,7 +59,7 @@ services:
- '@Tests\AppBundle\Commits\FakeRepository'
- '@validator'
- '@AppBundle\PullRequests\Repository'
- '@AppBundle\Organizations\Repository'
- '@Tests\AppBundle\Organisations\FakeRepository'
- '@Psr\Log\NullLogger'

AppBundle\Issues\Listener:
Expand Down
16 changes: 5 additions & 11 deletions src/AppBundle/Organizations/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Github\Api\Organization;
use Github\Exception\RuntimeException;

class Repository
class Repository implements RepositoryInterface
{
/**
* @var array list of teams (won't change during a request)
Expand All @@ -28,7 +28,7 @@ public function __construct(Organization $organizationApi, $repositoryOwner)
}

/**
* @return array
* {@inheritdoc}
*/
public function getTeams()
{
Expand All @@ -48,7 +48,7 @@ public function getTeams()
}

/**
* @param string $teamName
* {@inheritdoc}
*/
public function getTeam(string $teamName)
{
Expand All @@ -58,9 +58,7 @@ public function getTeam(string $teamName)
}

/**
* @param string $teamName
*
* @return \Guzzle\Http\EntityBodyInterface|mixed|string
* {@inheritdoc}
*/
public function getTeamMembers(string $teamName)
{
Expand All @@ -77,11 +75,7 @@ public function getTeamMembers(string $teamName)
}

/**
* Check if a user is a member of the organisation.
*
* @param string $userLogin
*
* @return bool
* {@inheritdoc}
*/
public function isMember(string $userLogin)
{
Expand Down
32 changes: 32 additions & 0 deletions src/AppBundle/Organizations/RepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace AppBundle\Organizations;

interface RepositoryInterface
{
/**
* @return array
*/
public function getTeams();

/**
* @param string $teamName
*/
public function getTeam(string $teamName);

/**
* @param string $teamName
*
* @return \Guzzle\Http\EntityBodyInterface|mixed|string
*/
public function getTeamMembers(string $teamName);

/**
* Check if a user is a member of the organisation.
*
* @param string $userLogin
*
* @return bool
*/
public function isMember(string $userLogin);
}
2 changes: 1 addition & 1 deletion src/AppBundle/PullRequests/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use AppBundle\Comments\CommentApiInterface;
use AppBundle\Commits\RepositoryInterface as CommitRepositoryInterface;
use AppBundle\Organizations\Repository as OrganizationRepository;
use AppBundle\Organizations\RepositoryInterface as OrganizationRepository;
use AppBundle\PullRequests\RepositoryInterface as PullRequestRepositoryInterface;
use DateInterval;
use DateTime;
Expand Down
2 changes: 1 addition & 1 deletion src/AppBundle/PullRequests/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace AppBundle\PullRequests;

use AppBundle\Search\Repository as SearchRepository;
use AppBundle\Search\RepositoryInterface as SearchRepository;
use DateInterval;
use DateTime;
use Github\Api\Issue\Comments as KnpCommentsApi;
Expand Down
11 changes: 3 additions & 8 deletions src/AppBundle/Search/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @doc https://github.com/KnpLabs/php-github-api/blob/master/doc/search.md
*/
class Repository
class Repository implements RepositoryInterface
{
/**
* @var Search
Expand Down Expand Up @@ -38,9 +38,7 @@ public function __construct(Search $searchApi, GraphQL $graphQL, string $reposit
}

/**
* @param array $filters
*
* @return array
* {@inheritdoc}
*/
public function getPullRequests($filters = []): array
{
Expand All @@ -56,10 +54,7 @@ public function getPullRequests($filters = []): array
}

/**
* @param $query
* @param array $variables
*
* @return array
* {@inheritdoc}
*/
public function graphQL($query, $variables = []): array
{
Expand Down
21 changes: 21 additions & 0 deletions src/AppBundle/Search/RepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace AppBundle\Search;

interface RepositoryInterface
{
/**
* @param array $filters
*
* @return array
*/
public function getPullRequests($filters = []): array;

/**
* @param $query
* @param array $variables
*
* @return array
*/
public function graphQL($query, $variables = []): array;
}
20 changes: 20 additions & 0 deletions tests/AppBundle/Controller/WebhookControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,26 @@ public function getTests()
],*/
],
];
$tests['Pull request from community merged'] = [
'pull_request',
'pull_request_community_merged.json',
[
[
'event' => 'pr_merged',
'action' => 'ask for feedback',
],
],
];
$tests['Pull request from community merged less that 30 days ago'] = [
'pull_request',
'pull_request_community_merged_30days_ago.json',
[],
];
$tests['Pull request from ps organisation merged'] = [
'pull_request',
'pull_request_organisation_merged.json',
[],
];
$tests['Pull request creation for critical bug'] = [
'issues',
'issues.labeled.bug.json',
Expand Down
35 changes: 35 additions & 0 deletions tests/AppBundle/Organisations/FakeRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Tests\AppBundle\Organisations;

use AppBundle\Organizations\RepositoryInterface;

class FakeRepository implements RepositoryInterface
{
private $members;

public function __construct($members = [])
{
$this->members = $members;
}

public function getTeams()
{
// TODO: Implement getTeams() method.
}

public function getTeam(string $teamName)
{
// TODO: Implement getTeam() method.
}

public function getTeamMembers(string $teamName)
{
// TODO: Implement getTeamMembers() method.
}

public function isMember(string $userLogin)
{
return \in_array($userLogin, $this->members, true);
}
}
141 changes: 0 additions & 141 deletions tests/AppBundle/PullRequests/FakeRepository.php

This file was deleted.

Loading

0 comments on commit 2e50440

Please sign in to comment.