Skip to content
This repository was archived by the owner on Oct 21, 2020. It is now read-only.

Commit ab5454d

Browse files
author
Huseyin KELES
authored
Merge pull request #6 from Werkspot/JCB_Sprint-selector
Jcb sprint selector
2 parents 08862fa + b28ddb9 commit ab5454d

File tree

10 files changed

+215
-18
lines changed

10 files changed

+215
-18
lines changed

config/graphql/schema/Query.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ Query:
88
@=service("League\\Tactician\\CommandBus").handle(
99
newObject("Werkspot\\JiraDashboard\\TeamWidget\\Domain\\GetTeamsQuery")
1010
)
11+
teamWidgetSprints:
12+
type: "[Sprint]"
13+
resolve: >
14+
@=service("League\\Tactician\\CommandBus").handle(
15+
newObject("Werkspot\\JiraDashboard\\TeamWidget\\Domain\\GetSprintsQuery")
16+
)
1117
1218
sprintWidget:
1319
type: Sprint

src/Werkspot/JiraDashboard/SharedKernel/Infrastructure/Messaging/CommandBus/Tactician/TacticianCommandBusFactory.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
use Werkspot\JiraDashboard\SprintWidget\Domain\AddNewSprintCommand;
3131
use Werkspot\JiraDashboard\SprintWidget\Domain\GetActiveSprintByTeamQuery;
3232
use Werkspot\JiraDashboard\TeamWidget\Application\AddTeamCommandHandler;
33+
use Werkspot\JiraDashboard\TeamWidget\Application\GetSprintsQueryHandler;
3334
use Werkspot\JiraDashboard\TeamWidget\Application\GetTeamsQueryHandler;
3435
use Werkspot\JiraDashboard\TeamWidget\Domain\AddTeamCommand;
36+
use Werkspot\JiraDashboard\TeamWidget\Domain\GetSprintsQuery;
3537
use Werkspot\JiraDashboard\TeamWidget\Domain\GetTeamsQuery;
3638

3739
final class TacticianCommandBusFactory
@@ -84,8 +86,9 @@ public function __construct(
8486
$inflector = new HandleInflector();
8587

8688
// register commands/queries
87-
$getTeamsQueryHandler = new GetTeamsQueryHandler($this->teamRepository);
88-
$addTeamCommandHandler = new AddTeamCommandHandler($this->teamRepository);
89+
$getTeamsQueryHandler = new GetTeamsQueryHandler($this->teamRepository, $this->sprintRepository);
90+
$getSprintsQueryHandler = new GetSprintsQueryHandler($this->teamRepository, $this->sprintRepository);
91+
$addTeamCommandHandler = new AddTeamCommandHandler($this->teamRepository, $this->sprintRepository);
8992

9093
$getConfidenceBySprintQueryHandler = new GetConfidenceBySprintQueryHandler($this->sprintRepository, $this->confidenceRepository);
9194
$saveConfidenceCommandHandler = new SaveConfidenceCommandHandler($this->sprintRepository, $this->confidenceRepository);
@@ -102,6 +105,7 @@ public function __construct(
102105
$locator = new InMemoryLocator();
103106

104107
$locator->addHandler($getTeamsQueryHandler, GetTeamsQuery::class);
108+
$locator->addHandler($getSprintsQueryHandler, GetSprintsQuery::class);
105109
$locator->addHandler($addTeamCommandHandler, AddTeamCommand::class);
106110

107111
$locator->addHandler($getConfidenceBySprintQueryHandler, GetConfidenceBySprintQuery::class);

src/Werkspot/JiraDashboard/SharedKernel/Infrastructure/Persistence/InMemory/Sprint/SprintRepositoryInMemoryAdapter.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ public function findAll(): ?array
5454
*/
5555
public function findAllByTeam(Id $teamId): ?array
5656
{
57-
$sprintArray = array_filter($this->inMemoryData, function (Sprint $sprint) use ($teamId) {
58-
if ($sprint->getTeam()->getId() == $teamId) {
59-
return $sprint;
60-
}
57+
$sprintArray = array_values(
58+
array_filter($this->inMemoryData, function (Sprint $sprint) use ($teamId) {
59+
if ($sprint->getTeam()->getId() == $teamId) {
60+
return $sprint;
61+
}
6162

62-
return false;
63-
});
63+
return false;
64+
})
65+
);
6466

6567
return $sprintArray;
6668
}

src/Werkspot/JiraDashboard/TeamWidget/Application/AddTeamCommandHandler.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace Werkspot\JiraDashboard\TeamWidget\Application;
55

6+
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Sprint\SprintRepositoryInterface;
67
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Team\Team;
78
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Team\TeamRepositoryInterface;
89
use Werkspot\JiraDashboard\SharedKernel\Domain\ValueObject\Id;
@@ -17,9 +18,15 @@ class AddTeamCommandHandler
1718
*/
1819
private $teamRepository;
1920

20-
public function __construct(TeamRepositoryInterface $teamRepository)
21+
/**
22+
* @var SprintRepositoryInterface
23+
*/
24+
private $sprintRepository;
25+
26+
public function __construct(TeamRepositoryInterface $teamRepository, SprintRepositoryInterface $sprintRepository)
2127
{
2228
$this->teamRepository = $teamRepository;
29+
$this->sprintRepository = $sprintRepository;
2330
}
2431

2532
public function handle(AddTeamCommand $command): void
@@ -28,7 +35,7 @@ public function handle(AddTeamCommand $command): void
2835

2936
$team = new Team(Id::create(), $teamName);
3037

31-
$teamWidget = new TeamWidget($this->teamRepository);
38+
$teamWidget = new TeamWidget($this->teamRepository, $this->sprintRepository);
3239
$teamWidget->addTeam($team);
3340
}
3441
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Werkspot\JiraDashboard\TeamWidget\Application;
5+
6+
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Sprint\SprintRepositoryInterface;
7+
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Team\Team;
8+
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Team\TeamRepositoryInterface;
9+
use Werkspot\JiraDashboard\SharedKernel\Domain\ValueObject\Id;
10+
use Werkspot\JiraDashboard\TeamWidget\Domain\GetSprintsQuery;
11+
use Werkspot\JiraDashboard\TeamWidget\Domain\TeamWidget;
12+
13+
class GetSprintsQueryHandler
14+
{
15+
/**
16+
* @var TeamRepositoryInterface
17+
*/
18+
private $teamRepository;
19+
20+
/**
21+
* @var SprintRepositoryInterface
22+
*/
23+
private $sprintRepository;
24+
25+
public function __construct(TeamRepositoryInterface $teamRepository, SprintRepositoryInterface $sprintRepository)
26+
{
27+
$this->teamRepository = $teamRepository;
28+
$this->sprintRepository = $sprintRepository;
29+
}
30+
31+
/**
32+
* @return Team[]
33+
*/
34+
public function handle(GetSprintsQuery $getSprintsQuery): array
35+
{
36+
$teamWidget = new TeamWidget($this->teamRepository, $this->sprintRepository);
37+
38+
$teamIdValue = $getSprintsQuery->getTeamId();
39+
40+
$team = $this->teamRepository->find(Id::create($teamIdValue));
41+
42+
return $teamWidget->getSprints($team);
43+
}
44+
}

src/Werkspot/JiraDashboard/TeamWidget/Application/GetTeamsQueryHandler.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace Werkspot\JiraDashboard\TeamWidget\Application;
55

6+
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Sprint\SprintRepositoryInterface;
67
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Team\Team;
78
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Team\TeamRepositoryInterface;
89
use Werkspot\JiraDashboard\TeamWidget\Domain\GetTeamsQuery;
@@ -15,17 +16,23 @@ class GetTeamsQueryHandler
1516
*/
1617
private $teamRepository;
1718

18-
public function __construct(TeamRepositoryInterface $teamRepository)
19+
/**
20+
* @var SprintRepositoryInterface
21+
*/
22+
private $sprintRepository;
23+
24+
public function __construct(TeamRepositoryInterface $teamRepository, SprintRepositoryInterface $sprintRepository)
1925
{
2026
$this->teamRepository = $teamRepository;
27+
$this->sprintRepository = $sprintRepository;
2128
}
2229

2330
/**
2431
* @return Team[]
2532
*/
2633
public function handle(GetTeamsQuery $getTeamsQuery): array
2734
{
28-
$teamWidget = new TeamWidget($this->teamRepository);
35+
$teamWidget = new TeamWidget($this->teamRepository, $this->sprintRepository);
2936

3037
return $teamWidget->getTeams();
3138
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Werkspot\JiraDashboard\TeamWidget\Domain;
5+
6+
class GetSprintsQuery
7+
{
8+
/**
9+
* @var string
10+
*/
11+
private $teamId;
12+
13+
public function __construct(string $teamId)
14+
{
15+
$this->teamId = $teamId;
16+
}
17+
18+
public function getTeamId(): string
19+
{
20+
return $this->teamId;
21+
}
22+
}

src/Werkspot/JiraDashboard/TeamWidget/Domain/TeamWidget.php

+17-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
namespace Werkspot\JiraDashboard\TeamWidget\Domain;
55

66
use Symfony\Component\HttpFoundation\Response;
7+
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Sprint\Sprint;
8+
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Sprint\SprintRepositoryInterface;
79
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Team\Team;
810
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Team\TeamRepositoryInterface;
911
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Widget\WidgetInterface;
@@ -15,9 +17,15 @@ class TeamWidget implements WidgetInterface
1517
*/
1618
private $teamRepository;
1719

18-
public function __construct(TeamRepositoryInterface $teamRepository)
20+
/**
21+
* @var SprintRepositoryInterface
22+
*/
23+
private $sprintRepository;
24+
25+
public function __construct(TeamRepositoryInterface $teamRepository, SprintRepositoryInterface $sprintRepository)
1926
{
2027
$this->teamRepository = $teamRepository;
28+
$this->sprintRepository = $sprintRepository;
2129
}
2230

2331
/**
@@ -37,4 +45,12 @@ public function render(): Response
3745
{
3846
return new Response('Achieved Sprints Widget');
3947
}
48+
49+
/**
50+
* @return Sprint[]|null
51+
*/
52+
public function getSprints(Team $team): ?array
53+
{
54+
return $this->sprintRepository->findAllByTeam($team->getId());
55+
}
4056
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Werkspot\Tests\JiraDashboard\TeamWidget\Integration;
5+
6+
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Sprint\Sprint;
7+
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Team\Team;
8+
use Werkspot\JiraDashboard\TeamWidget\Domain\GetSprintsQuery;
9+
use Werkspot\Tests\JiraDashboard\SharedKernel\Integration\IntegrationTestAbstract;
10+
11+
class GetSprintsQueryTest extends IntegrationTestAbstract
12+
{
13+
/**
14+
* @test
15+
*/
16+
public function getSprintsQuery_whenThereAreSomeSprints_shouldReturnSprintsData()
17+
{
18+
/** @var Team[] $allTeamsCollection */
19+
$allTeamsCollection = $this->teamRepositoryDoctrineAdapter->findAll();
20+
$team = array_shift($allTeamsCollection);
21+
22+
$getSprintsQuery = new GetSprintsQuery($team->getId()->id());
23+
$sprintsData = $this->commandBus->handle($getSprintsQuery);
24+
25+
$this->assertCount(1, $sprintsData);
26+
$this->assertInstanceOf(Sprint::class, array_shift($sprintsData));
27+
}
28+
}

tests/Werkspot/JiraDashboard/TeamWidget/Unit/Domain/TeamWidgetTest.php

+66-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
namespace Werkspot\Tests\JiraDashboard\TeamWidget\Unit\Domain;
55

66
use PHPUnit\Framework\TestCase;
7+
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Sprint\Sprint;
78
use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Team\Team;
89
use Werkspot\JiraDashboard\SharedKernel\Domain\ValueObject\Id;
10+
use Werkspot\JiraDashboard\SharedKernel\Domain\ValueObject\PositiveNumber;
911
use Werkspot\JiraDashboard\SharedKernel\Domain\ValueObject\ShortText;
12+
use Werkspot\JiraDashboard\SharedKernel\Infrastructure\Persistence\InMemory\Sprint\SprintRepositoryInMemoryAdapter;
1013
use Werkspot\JiraDashboard\SharedKernel\Infrastructure\Persistence\InMemory\Team\TeamRepositoryInMemoryAdapter;
1114
use Werkspot\JiraDashboard\TeamWidget\Domain\TeamWidget;
1215

@@ -18,8 +21,9 @@ class TeamWidgetTest extends TestCase
1821
public function getTeams_whenThereIsNoTeams_shouldReturnAnEmptyArray()
1922
{
2023
$teamRepository = new TeamRepositoryInMemoryAdapter([]);
24+
$sprintRepository = new SprintRepositoryInMemoryAdapter([]);
2125

22-
$teamWidget = new TeamWidget($teamRepository);
26+
$teamWidget = new TeamWidget($teamRepository, $sprintRepository);
2327

2428
self::assertEmpty($teamWidget->getTeams());
2529
}
@@ -43,7 +47,9 @@ public function getTeams_whenThereAreTeams_shouldReturnTeamCollection()
4347
$team2,
4448
]);
4549

46-
$teamWidget = new TeamWidget($teamRepository);
50+
$sprintRepository = new SprintRepositoryInMemoryAdapter([]);
51+
52+
$teamWidget = new TeamWidget($teamRepository, $sprintRepository);
4753
$teams = $teamWidget->getTeams();
4854

4955
self::assertCount(2, $teams);
@@ -63,7 +69,9 @@ public function addTeam_whenThereIsNoTeams_shouldSaveNewTeamToPersistence()
6369
ShortText::create('Team name')
6470
);
6571

66-
$teamWidget = new TeamWidget($teamRepository);
72+
$sprintRepository = new SprintRepositoryInMemoryAdapter([]);
73+
74+
$teamWidget = new TeamWidget($teamRepository, $sprintRepository);
6775
$teamWidget->addTeam($team);
6876

6977
self::assertCount(1, $teamRepository->findAll());
@@ -94,7 +102,9 @@ public function addTeam_whenThereAreSome_shouldSaveNewTeamToPersistence()
94102
ShortText::create('Team name')
95103
);
96104

97-
$teamWidget = new TeamWidget($teamRepository);
105+
$sprintRepository = new SprintRepositoryInMemoryAdapter([]);
106+
107+
$teamWidget = new TeamWidget($teamRepository, $sprintRepository);
98108
$teamWidget->addTeam($team);
99109

100110
self::assertCount(3, $teamRepository->findAll());
@@ -113,7 +123,9 @@ public function addTeam_whenTeamAlreadyExists_shouldUpdateTeamIntoPersistence()
113123

114124
$teamRepository = new TeamRepositoryInMemoryAdapter([]);
115125

116-
$teamWidget = new TeamWidget($teamRepository);
126+
$sprintRepository = new SprintRepositoryInMemoryAdapter([]);
127+
128+
$teamWidget = new TeamWidget($teamRepository, $sprintRepository);
117129
$teamWidget->addTeam($team);
118130

119131
self::assertEquals($team->getName(), $teamRepository->find($team->getId())->getName());
@@ -123,4 +135,53 @@ public function addTeam_whenTeamAlreadyExists_shouldUpdateTeamIntoPersistence()
123135

124136
self::assertEquals($team->getName(), $teamRepository->find($team->getId())->getName());
125137
}
138+
139+
/**
140+
* @test
141+
*/
142+
public function getSprints_whenThereIsNoSprints_shouldReturnAnEmptyCollection()
143+
{
144+
$team = new Team(
145+
Id::create(),
146+
ShortText::create('Team name')
147+
);
148+
149+
$teamRepository = new TeamRepositoryInMemoryAdapter([$team]);
150+
151+
$sprintRepository = new SprintRepositoryInMemoryAdapter([]);
152+
153+
$teamWidget = new TeamWidget($teamRepository, $sprintRepository);
154+
$sprintCollection = $teamWidget->getSprints($team);
155+
156+
$this->assertEquals([], $sprintCollection);
157+
}
158+
159+
/**
160+
* @test
161+
*/
162+
public function getSprints_whenThereAreSomeSprints_shouldReturnASprintCollection()
163+
{
164+
$team = new Team(
165+
Id::create(),
166+
ShortText::create('Team name')
167+
);
168+
169+
$sprint = new Sprint(
170+
Id::create(),
171+
ShortText::create('One title'),
172+
$team,
173+
new \DateTimeImmutable("now - 5 days"),
174+
new \DateTimeImmutable("now + 5 days"),
175+
PositiveNumber::create(0)
176+
);
177+
178+
$teamRepository = new TeamRepositoryInMemoryAdapter([$team]);
179+
180+
$sprintRepository = new SprintRepositoryInMemoryAdapter([$sprint]);
181+
182+
$teamWidget = new TeamWidget($teamRepository, $sprintRepository);
183+
$sprintCollection = $teamWidget->getSprints($team);
184+
185+
$this->assertEquals([$sprint], $sprintCollection);
186+
}
126187
}

0 commit comments

Comments
 (0)