Skip to content

Commit

Permalink
fix: pi records without a case no longer throw errors VOL-5297 (#499)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrew Newton <[email protected]>
  • Loading branch information
ilindsay and fibble authored Dec 6, 2024
1 parent 22cb471 commit 5b01069
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 35 deletions.
4 changes: 2 additions & 2 deletions app/api/module/Api/src/Entity/Pi/Pi.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,9 @@ private function isClosableWrittenOutcome()
/**
* Is this a Transport Manager Pi?
*/
public function isTm()
public function isTm(): bool
{
return $this->case->isTm();
return $this->case instanceof CasesEntity && $this->case->isTm();
}

/**
Expand Down
92 changes: 59 additions & 33 deletions app/api/test/module/Api/src/Entity/Pi/PiEntityTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Dvsa\OlcsTest\Api\Entity\Pi;

use Dvsa\Olcs\Api\Domain\Exception\ValidationException;
Expand Down Expand Up @@ -37,7 +39,7 @@ public function setUp(): void
/**
* test create
*/
public function testCreate()
public function testCreate(): void
{
$caseEntity = m::mock(CasesEntity::class);
$caseEntity->shouldReceive('isClosed')->andReturn(false);
Expand Down Expand Up @@ -82,7 +84,7 @@ public function testCreate()
/**
* test create throws exception when case is closed
*/
public function testCreateClosedCaseException()
public function testCreateClosedCaseException(): void
{
$this->expectException(\Dvsa\Olcs\Api\Domain\Exception\ForbiddenException::class);

Expand Down Expand Up @@ -116,7 +118,7 @@ public function testCreateClosedCaseException()
/**
* test agreed and legislation
*/
public function testAgreedAndLegislation()
public function testAgreedAndLegislation(): void
{
$agreedByTc = m::mock(PresidingTcEntity::class);
$agreedByTcRole = m::mock(RefData::class);
Expand Down Expand Up @@ -155,7 +157,7 @@ public function testAgreedAndLegislation()
/**
* test agreed and legislation accepts null for assignedCaseworker and ecmsFirstReceivedDate
*/
public function testAgreedAndLegislationNullValues()
public function testAgreedAndLegislationNullValues(): void
{
$agreedByTc = m::mock(PresidingTcEntity::class);
$agreedByTcRole = m::mock(RefData::class);
Expand Down Expand Up @@ -192,7 +194,7 @@ public function testAgreedAndLegislationNullValues()
/**
* test agreed and legislation throws exception when Pi is closed
*/
public function testAgreedAndLegislationClosedException()
public function testAgreedAndLegislationClosedException(): void
{
$this->expectException(\Dvsa\Olcs\Api\Domain\Exception\ForbiddenException::class);

Expand Down Expand Up @@ -225,7 +227,7 @@ public function testAgreedAndLegislationClosedException()
* @param string $inputDate
* @param \DateTime|null $entityDate
*/
public function testUpdatePiWithDecision($inputDate, $entityDate)
public function testUpdatePiWithDecision($inputDate, $entityDate): void
{
$decidedByTc = m::mock(PresidingTcEntity::class);
$decidedByTcRole = m::mock(RefData::class);
Expand Down Expand Up @@ -276,7 +278,7 @@ public function testUpdatePiWithDecision($inputDate, $entityDate)
* @param $decisionDate
* @param $hearingDate
*/
public function testUpdatePiWithDecisionDecisionBeforeHearing($expectException, $decisionDate, $hearingDate)
public function testUpdatePiWithDecisionDecisionBeforeHearing($expectException, $decisionDate, $hearingDate): void
{
$piHearing = m::mock(PiHearingEntity::class);
$piHearing->shouldReceive('getIsAdjourned')->andReturn('N');
Expand Down Expand Up @@ -314,7 +316,7 @@ public function testUpdatePiWithDecisionDecisionBeforeHearing($expectException,
}
}

public function dataProviderTestUpdatePiWithDecisionDecisionBeforeHearing()
public function dataProviderTestUpdatePiWithDecisionDecisionBeforeHearing(): array
{
return [
[false, null, null],
Expand All @@ -329,7 +331,7 @@ public function dataProviderTestUpdatePiWithDecisionDecisionBeforeHearing()
];
}

public function testUpdatePiWithDecisionClosedException()
public function testUpdatePiWithDecisionClosedException(): void
{
$this->expectException(\Dvsa\Olcs\Api\Domain\Exception\ForbiddenException::class);

Expand Down Expand Up @@ -360,7 +362,7 @@ public function testUpdatePiWithDecisionClosedException()
* @param string $inputDate
* @param \DateTime|null $entityDate
*/
public function testUpdateWrittenOutcomeNone($inputDate, $entityDate)
public function testUpdateWrittenOutcomeNone($inputDate, $entityDate): void
{
$writtenOutcome = m::mock(RefData::class);
$callUpLetterDate = $inputDate;
Expand All @@ -377,7 +379,7 @@ public function testUpdateWrittenOutcomeNone($inputDate, $entityDate)
$this->assertEquals(null, $this->entity->getWrittenReasonLetterDate());
}

public function testUpdateWrittenOutcomeNoneClosedException()
public function testUpdateWrittenOutcomeNoneClosedException(): void
{
$this->expectException(\Dvsa\Olcs\Api\Domain\Exception\ForbiddenException::class);

Expand All @@ -393,7 +395,7 @@ public function testUpdateWrittenOutcomeNoneClosedException()
* @param string $inputDate
* @param \DateTime|null $entityDate
*/
public function testUpdateWrittenOutcomeVerbalDecision($inputDate, $entityDate)
public function testUpdateWrittenOutcomeVerbalDecision($inputDate, $entityDate): void
{
$writtenOutcome = m::mock(RefData::class);
$callUpLetterDate = $inputDate;
Expand All @@ -416,7 +418,7 @@ public function testUpdateWrittenOutcomeVerbalDecision($inputDate, $entityDate)
$this->assertEquals(null, $this->entity->getWrittenReasonLetterDate());
}

public function testUpdateWrittenOutcomeVerbalClosedException()
public function testUpdateWrittenOutcomeVerbalClosedException(): void
{
$this->expectException(\Dvsa\Olcs\Api\Domain\Exception\ForbiddenException::class);

Expand All @@ -432,7 +434,7 @@ public function testUpdateWrittenOutcomeVerbalClosedException()
* @param string $inputDate
* @param \DateTime|null $entityDate
*/
public function testUpdateWrittenOutcomeDecision($inputDate, $entityDate)
public function testUpdateWrittenOutcomeDecision($inputDate, $entityDate): void
{
$writtenOutcome = m::mock(RefData::class);
$callUpLetterDate = $inputDate;
Expand All @@ -457,7 +459,7 @@ public function testUpdateWrittenOutcomeDecision($inputDate, $entityDate)
$this->assertEquals(null, $this->entity->getWrittenReasonLetterDate());
}

public function testUpdateWrittenOutcomeDecisionClosedException()
public function testUpdateWrittenOutcomeDecisionClosedException(): void
{
$this->expectException(\Dvsa\Olcs\Api\Domain\Exception\ForbiddenException::class);

Expand All @@ -473,7 +475,7 @@ public function testUpdateWrittenOutcomeDecisionClosedException()
* @param string $inputDate
* @param \DateTime|null $entityDate
*/
public function testUpdateWrittenOutcomeReason($inputDate, $entityDate)
public function testUpdateWrittenOutcomeReason($inputDate, $entityDate): void
{
$writtenOutcome = m::mock(RefData::class);
$callUpLetterDate = $inputDate;
Expand All @@ -498,7 +500,7 @@ public function testUpdateWrittenOutcomeReason($inputDate, $entityDate)
$this->assertEquals($entityDate, $this->entity->getWrittenReasonLetterDate());
}

public function testUpdateWrittenOutcomeReasonClosedException()
public function testUpdateWrittenOutcomeReasonClosedException(): void
{
$this->expectException(\Dvsa\Olcs\Api\Domain\Exception\ForbiddenException::class);

Expand All @@ -515,7 +517,7 @@ public function testUpdateWrittenOutcomeReasonClosedException()
* @param $closedDate
* @param $returnValue
*/
public function testCanCloseWithHearing($isCancelled, $closedDate, $returnValue)
public function testCanCloseWithHearing($isCancelled, $closedDate, $returnValue): void
{
$piHearing = m::mock(PiHearingEntity::class);
$piHearing->shouldReceive('getIsCancelled')->andReturn($isCancelled);
Expand All @@ -531,7 +533,7 @@ public function testCanCloseWithHearing($isCancelled, $closedDate, $returnValue)
$this->assertEquals($returnValue, $this->entity->canClose());
}

public function canCloseWithHearingProvider()
public function canCloseWithHearingProvider(): array
{
$date = '2015-12-25';

Expand All @@ -542,7 +544,7 @@ public function canCloseWithHearingProvider()
];
}

public function testCanCloseNoHearingNoOutcome()
public function testCanCloseNoHearingNoOutcome(): void
{
$this->entity->setPiHearings(new ArrayCollection());
$this->entity->setCallUpLetterDate(new \DateTime());
Expand All @@ -563,7 +565,7 @@ public function testCanCloseWithOutcome(
$decisionLetterSentDate,
$closedDate,
$returnValue
) {
): void {
$writtenOutcome = m::mock(RefData::class);
$writtenOutcome->shouldReceive('getId')->andReturn($writtenOutcomeId);
$this->entity->setClosedDate($closedDate);
Expand All @@ -580,7 +582,7 @@ public function testCanCloseWithOutcome(
$this->assertEquals($returnValue, $this->entity->canClose());
}

public function canCloseWithOutcomeProvider()
public function canCloseWithOutcomeProvider(): array
{
$date = '2015-12-25';

Expand All @@ -607,7 +609,7 @@ public function canCloseWithOutcomeProvider()
* @param $briefToTcDate
* @param $callUpLetterDate
*/
public function testCanCloseWithMissingGeneralSla($briefToTcDate, $callUpLetterDate)
public function testCanCloseWithMissingGeneralSla($briefToTcDate, $callUpLetterDate): void
{
$this->entity->setPiHearings(new ArrayCollection());
$this->entity->setCallUpLetterDate($briefToTcDate);
Expand All @@ -616,7 +618,7 @@ public function testCanCloseWithMissingGeneralSla($briefToTcDate, $callUpLetterD
$this->assertEquals(false, $this->entity->canClose());
}

public function canCloseWithMissingGeneralSlaProvider()
public function canCloseWithMissingGeneralSlaProvider(): array
{
$date = '2015-12-25';

Expand All @@ -629,7 +631,7 @@ public function canCloseWithMissingGeneralSlaProvider()
/**
* Tests closing a Pi
*/
public function testClose()
public function testClose(): void
{
$piHearing = m::mock(PiHearingEntity::class);
$piHearing->shouldReceive('getIsCancelled')->andReturn('Y');
Expand All @@ -641,7 +643,7 @@ public function testClose()
$this->assertInstanceOf('\DateTime', $this->entity->getClosedDate());
}

public function testCloseThrowsException()
public function testCloseThrowsException(): void
{
$this->expectException(\Dvsa\Olcs\Api\Domain\Exception\ForbiddenException::class);

Expand All @@ -653,7 +655,7 @@ public function testCloseThrowsException()
/**
* Tests reopen
*/
public function testReopen()
public function testReopen(): void
{
$this->entity->setClosedDate(new \DateTime());

Expand All @@ -662,7 +664,7 @@ public function testReopen()
$this->assertEquals(null, $this->entity->getClosedDate());
}

public function testReopenThrowsException()
public function testReopenThrowsException(): void
{
$this->expectException(\Dvsa\Olcs\Api\Domain\Exception\ForbiddenException::class);

Expand All @@ -680,7 +682,7 @@ public function testReopenThrowsException()
* @param string $isCancelled
* @param string|null $returnValue
*/
public function testGetHearingDate($hearingDate, $isAdjourned, $isCancelled, $returnValue)
public function testGetHearingDate($hearingDate, $isAdjourned, $isCancelled, $returnValue): void
{
$piHearing = m::mock(PiHearingEntity::class);
$piHearing->shouldReceive('getHearingDate')->andReturn($hearingDate);
Expand All @@ -695,7 +697,7 @@ public function testGetHearingDate($hearingDate, $isAdjourned, $isCancelled, $re
/**
* @return array
*/
public function dpGetHearingDateProvider()
public function dpGetHearingDateProvider(): array
{
$date = '2015-12-25';

Expand All @@ -710,7 +712,7 @@ public function dpGetHearingDateProvider()
/**
* Tests getCalculatedBundleValues
*/
public function testGetCalculatedBundleValues()
public function testGetCalculatedBundleValues(): void
{
$isTm = true;

Expand All @@ -731,12 +733,36 @@ public function testGetCalculatedBundleValues()
$this->assertEquals($expected, $this->entity->getCalculatedBundleValues());
}

/**
* @dataProvider isTmProvider
*/
public function testIsTm(bool $isTm): void
{
//test with no case attached
$this->entity->setCase(null);
$this->assertFalse($this->entity->isTm());

$case = m::mock(CasesEntity::class);
$case->shouldReceive('isTm')->andReturn($isTm);
$this->entity->setCase($case);

$this->assertEquals($isTm, $this->entity->isTm());
}

public function isTmProvider(): array
{
return [
[true],
[false]
];
}

/**
* provider to check dates are processed properly
*
* @return array
*/
public function dateProvider()
public function dateProvider(): array
{
$date = '2015-12-25';

Expand All @@ -749,7 +775,7 @@ public function dateProvider()
/**
* Tests flattenSlaTargetDates
*/
public function testFlattenSlaTargetDates()
public function testFlattenSlaTargetDates(): void
{
$date1 = new \DateTime('2015-03-14');

Expand Down

0 comments on commit 5b01069

Please sign in to comment.