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
49 changes: 49 additions & 0 deletions spec/Fetch/Commit/GithubCommitCommitterFactorySpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace spec\Devboard\Github\Fetch\Commit;

use Devboard\Github\Fetch\Commit\GithubCommitCommitter;
use Devboard\Github\Fetch\Commit\GithubCommitCommitterFactory;
use PhpSpec\ObjectBehavior;

class GithubCommitCommitterFactorySpec extends ObjectBehavior
{
public function let()
{
$this->beConstructedWith();
}

public function it_is_initializable()
{
$this->shouldHaveType(GithubCommitCommitterFactory::class);
}

public function it_will_create_committer_from_given_branch_data()
{
$data = [
'commit' => [
'commit' => [
'committer' => [
'name' => 'John Smith',
'email' => 'nobody@example.com',
'date' => '2012-03-06T23:06:50Z',
],
],
'committer' => [
'login' => 'devboard-test',
'id' => 1,
'avatar_url' => 'avatar-url',
'gravatar_id' => '',
'url' => 'github-url',
'html_url' => 'github-html-url',
'type' => 'User',
'site_admin' => false,
],
],
];

$this->createFromBranchData($data)->shouldReturnAnInstanceOf(GithubCommitCommitter::class);
}
}
45 changes: 45 additions & 0 deletions src/Fetch/Commit/GithubCommitCommitterFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace Devboard\Github\Fetch\Commit;

use Devboard\Github\Commit\Committer\GithubCommitCommitterEmail;
use Devboard\Github\Commit\Committer\GithubCommitCommitterName;
use Devboard\Github\Commit\GithubCommitDate;
use Devboard\Github\User\GithubUserApiUrl;
use Devboard\Github\User\GithubUserAvatarUrl;
use Devboard\Github\User\GithubUserGravatarId;
use Devboard\Github\User\GithubUserHtmlUrl;
use Devboard\Github\User\GithubUserId;
use Devboard\Github\User\GithubUserLogin;
use Devboard\Github\User\GithubUserTypeFactory;

/**
* @see GithubCommitCommitterFactorySpec
* @see GithubCommitCommitterFactoryTest
*/
class GithubCommitCommitterFactory
{
public function createFromBranchData(array $data): GithubCommitCommitter
{
$committerInfo = $data['commit']['commit']['committer'];
$committerDetails = $data['commit']['committer'];

return new GithubCommitCommitter(
new GithubCommitCommitterName($committerInfo['name']),
new GithubCommitCommitterEmail($committerInfo['email']),
new GithubCommitDate($committerInfo['date']),
new GithubCommitCommitterDetails(
new GithubUserId($committerDetails['id']),
new GithubUserLogin($committerDetails['login']),
GithubUserTypeFactory::create($committerDetails['type']),
new GithubUserAvatarUrl($committerDetails['avatar_url']),
new GithubUserGravatarId($committerDetails['gravatar_id']),
new GithubUserHtmlUrl($committerDetails['html_url']),
new GithubUserApiUrl($committerDetails['url']),
$committerDetails['site_admin']
)
);
}
}
33 changes: 33 additions & 0 deletions tests/Fetch/Commit/GithubCommitCommitterFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace tests\Devboard\Github\Fetch\Commit;

use Devboard\Github\Fetch\Commit\GithubCommitCommitter;
use Devboard\Github\Fetch\Commit\GithubCommitCommitterFactory;
use tests\Devboard\Github\Fetch\TestData\TestDataProvider;

/**
* @covers \Devboard\Github\Fetch\Commit\GithubCommitCommitterFactory
* @group unit
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class GithubCommitCommitterFactoryTest extends \PHPUnit_Framework_TestCase
{
/** @dataProvider provideArguments */
public function testCreating(array $data)
{
$sut = new GithubCommitCommitterFactory();

$this->assertInstanceOf(GithubCommitCommitter::class, $sut->createFromBranchData($data));
}

public function provideArguments(): array
{
$provider = new TestDataProvider();

return $provider->getGitHubBranchesData();
}
}
30 changes: 27 additions & 3 deletions tests/Fetch/TestData/TestDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace tests\Devboard\Github\Fetch\TestData;

use Symfony\Component\Finder\Finder;

class TestDataProvider
{
private $repos = [
Expand All @@ -27,22 +29,44 @@ public function getRandomGitHubRepoData(): array
{
$repo = $this->repos[0];

return json_decode($this->loadContent($repo), true);
return json_decode($this->loadRepoContent($repo), true);
}

public function getGitHubRepoData(): array
{
$results = [];

foreach ($this->repos as $repo) {
$results[] = [json_decode($this->loadContent($repo), true)];
$results[] = [json_decode($this->loadRepoContent($repo), true)];
}

return $results;
}

public function getGitHubBranchesData(): array
{
$results = [];

foreach ($this->repos as $repo) {
$finder = new Finder();
$finder->files()->in(__DIR__.'/'.$repo.'/branches/');

foreach ($finder as $item) {
$branchName = str_replace('.json', '', $item->getRelativePathname());
$results[] = [json_decode($this->loadBranchContent($repo, $branchName), true)];
}
}

return $results;
}

private function loadContent(string $repo): string
private function loadRepoContent(string $repo): string
{
return file_get_contents(__DIR__.'/'.$repo.'/repo.json');
}

private function loadBranchContent(string $repo, string $branchName): string
{
return file_get_contents(__DIR__.'/'.$repo.'/branches/'.$branchName.'.json');
}
}