|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +namespace Werkspot\Tests\JiraDashboard\BurndownWidget\Unit\Domain; |
| 5 | + |
| 6 | +use DateTimeImmutable; |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | +use Werkspot\JiraDashboard\BurndownWidget\Domain\BurndownWidget; |
| 9 | +use Werkspot\JiraDashboard\BurndownWidget\Domain\RemainingPoints; |
| 10 | +use Werkspot\JiraDashboard\BurndownWidget\Infrastructure\Persistence\InMemory\RemainingPoints\RemainingPointsRepositoryInMemoryAdapter; |
| 11 | +use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Sprint\Sprint; |
| 12 | +use Werkspot\JiraDashboard\SharedKernel\Domain\Model\Team\Team; |
| 13 | +use Werkspot\JiraDashboard\SharedKernel\Domain\ValueObject\Id; |
| 14 | +use Werkspot\JiraDashboard\SharedKernel\Domain\ValueObject\PositiveNumber; |
| 15 | +use Werkspot\JiraDashboard\SharedKernel\Domain\ValueObject\ShortText; |
| 16 | +use Werkspot\JiraDashboard\SharedKernel\Infrastructure\Persistence\InMemory\Sprint\SprintRepositoryInMemoryAdapter; |
| 17 | + |
| 18 | +class BurndownWidgetTest extends TestCase |
| 19 | +{ |
| 20 | + /** |
| 21 | + * @test |
| 22 | + */ |
| 23 | + public function getRemainingPointsBySprint_whenThereIsASprint_shouldReturnRemainingPointsCollectionOrderedByDate() |
| 24 | + { |
| 25 | + $sprintRepository = $this->getSprintRepository(); |
| 26 | + $activeSprint = $sprintRepository->findActive(); |
| 27 | + |
| 28 | + $remainingPointsRepository = $this->getRemainingPointsRepository($activeSprint); |
| 29 | + |
| 30 | + $burndownWidget = new BurndownWidget($sprintRepository, $remainingPointsRepository); |
| 31 | + $remainingPointsCollection = $burndownWidget->getRemainingPointsBySprint($activeSprint); |
| 32 | + |
| 33 | + $this->assertCount(10, $remainingPointsCollection); |
| 34 | + $this->assertInstanceOf(RemainingPoints::class, $remainingPointsCollection[0]); |
| 35 | + $this->assertTrue(($remainingPointsCollection[0])->getDate() < ($remainingPointsCollection[1])->getDate()); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * @test |
| 40 | + */ |
| 41 | + public function saveNewRemainingPoints_whenDataIsValid_shouldSaveNewRemainingStoryPointsDataToPersistence() |
| 42 | + { |
| 43 | + $sprintRepository = $this->getSprintRepository(); |
| 44 | + $activeSprint = $sprintRepository->findActive(); |
| 45 | + |
| 46 | + $remainingPointsRepository = $this->getRemainingPointsRepository($activeSprint); |
| 47 | + |
| 48 | + $today = new DateTimeImmutable('today'); |
| 49 | + |
| 50 | + $newRemainingPointsValue = PositiveNumber::create(0); |
| 51 | + $newRemainingPoints = new RemainingPoints($activeSprint, $today, $newRemainingPointsValue); |
| 52 | + |
| 53 | + $burndownWidget = new BurndownWidget($sprintRepository, $remainingPointsRepository); |
| 54 | + $burndownWidget->saveRemainingPoints($newRemainingPoints); |
| 55 | + |
| 56 | + $remainingPointsCollection = $remainingPointsRepository->findBySprint($activeSprint); |
| 57 | + |
| 58 | + $this->assertCount(11, $remainingPointsCollection); |
| 59 | + $this->assertEquals($newRemainingPointsValue, ($remainingPointsCollection[10])->getValue()); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * @test |
| 64 | + */ |
| 65 | + public function saveRemainingPoints_whenDateAlreadyExists_shouldUpdateRemainingPointsData() |
| 66 | + { |
| 67 | + $sprintRepository = $this->getSprintRepository(); |
| 68 | + $activeSprint = $sprintRepository->findActive(); |
| 69 | + |
| 70 | + $remainingPointsRepository = $this->getRemainingPointsRepository($activeSprint); |
| 71 | + |
| 72 | + $today = new DateTimeImmutable('today - 1 days'); |
| 73 | + |
| 74 | + $updatedRemainingPoints = new RemainingPoints($activeSprint, $today, PositiveNumber::create(0)); |
| 75 | + |
| 76 | + $burndownWidget = new BurndownWidget($sprintRepository, $remainingPointsRepository); |
| 77 | + $burndownWidget->saveRemainingPoints($updatedRemainingPoints); |
| 78 | + |
| 79 | + $savedRemainingPoints = $remainingPointsRepository->findBySprint($activeSprint); |
| 80 | + |
| 81 | + $this->assertEquals($updatedRemainingPoints, $savedRemainingPoints[9]); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * @throws \Exception |
| 86 | + */ |
| 87 | + private function getSprintRepository(): SprintRepositoryInMemoryAdapter |
| 88 | + { |
| 89 | + $sprintRepository = new SprintRepositoryInMemoryAdapter([ |
| 90 | + new Sprint( |
| 91 | + Id::create(), |
| 92 | + ShortText::create('Sprint title'), |
| 93 | + new Team( |
| 94 | + Id::create(), |
| 95 | + ShortText::create('Team name') |
| 96 | + ), |
| 97 | + new DateTimeImmutable('today - 10 days'), |
| 98 | + new DateTimeImmutable('today'), |
| 99 | + PositiveNumber::create(1) |
| 100 | + ), |
| 101 | + ]); |
| 102 | + |
| 103 | + return $sprintRepository; |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * @throws \Exception |
| 108 | + */ |
| 109 | + private function getRemainingPointsRepository(Sprint $sprint): RemainingPointsRepositoryInMemoryAdapter |
| 110 | + { |
| 111 | + $remainingPointsRepository = new RemainingPointsRepositoryInMemoryAdapter([ |
| 112 | + new RemainingPoints($sprint, new DateTimeImmutable('today - 10 days'), PositiveNumber::create(30)), |
| 113 | + new RemainingPoints($sprint, new DateTimeImmutable('today - 9 days'), PositiveNumber::create(25)), |
| 114 | + new RemainingPoints($sprint, new DateTimeImmutable('today - 8 days'), PositiveNumber::create(24)), |
| 115 | + new RemainingPoints($sprint, new DateTimeImmutable('today - 7 days'), PositiveNumber::create(19)), |
| 116 | + new RemainingPoints($sprint, new DateTimeImmutable('today - 6 days'), PositiveNumber::create(10)), |
| 117 | + new RemainingPoints($sprint, new DateTimeImmutable('today - 5 days'), PositiveNumber::create(9)), |
| 118 | + new RemainingPoints($sprint, new DateTimeImmutable('today - 4 days'), PositiveNumber::create(9)), |
| 119 | + new RemainingPoints($sprint, new DateTimeImmutable('today - 3 days'), PositiveNumber::create(8)), |
| 120 | + new RemainingPoints($sprint, new DateTimeImmutable('today - 2 days'), PositiveNumber::create(5)), |
| 121 | + new RemainingPoints($sprint, new DateTimeImmutable('today - 1 days'), PositiveNumber::create(3)), |
| 122 | + ]); |
| 123 | + |
| 124 | + return $remainingPointsRepository; |
| 125 | + } |
| 126 | +} |
0 commit comments