-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
imp: Display total spent time in tickets lists
- Loading branch information
1 parent
1ed9ade
commit 97189b5
Showing
6 changed files
with
262 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
<?php | ||
|
||
// This file is part of Bileto. | ||
// Copyright 2022-2024 Probesys | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
namespace App\Tests\Entity; | ||
|
||
use App\Entity\Ticket; | ||
use App\Tests\Factory; | ||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
//use PHPUnit\Framework\TestCase; | ||
use Zenstruck\Foundry\Test\Factories; | ||
use Zenstruck\Foundry\Test\ResetDatabase; | ||
|
||
class TicketTest extends WebTestCase | ||
{ | ||
use Factories; | ||
use ResetDatabase; | ||
|
||
public function testGetSumTimeSpentWithAccountedType(): void | ||
{ | ||
$contract = Factory\ContractFactory::createOne([ | ||
'timeAccountingUnit' => 30, | ||
]); | ||
$ticket = Factory\TicketFactory::createOne([ | ||
'contracts' => [$contract], | ||
]); | ||
$accountedTimeSpent1 = Factory\TimeSpentFactory::createOne([ | ||
'ticket' => $ticket, | ||
'realTime' => 15, | ||
'time' => 30, | ||
'contract' => $contract, | ||
]); | ||
$accountedTimeSpent2 = Factory\TimeSpentFactory::createOne([ | ||
'ticket' => $ticket, | ||
'realTime' => 5, | ||
'time' => 30, | ||
'contract' => $contract, | ||
]); | ||
$unaccountedTimeSpent1 = Factory\TimeSpentFactory::createOne([ | ||
'ticket' => $ticket, | ||
'realTime' => 15, | ||
'time' => 15, | ||
'contract' => null, | ||
]); | ||
$unaccountedTimeSpent2 = Factory\TimeSpentFactory::createOne([ | ||
'ticket' => $ticket, | ||
'realTime' => 5, | ||
'time' => 5, | ||
'contract' => null, | ||
]); | ||
|
||
$time = $ticket->getSumTimeSpent('accounted'); | ||
|
||
$this->assertSame(60, $time); | ||
} | ||
|
||
public function testGetSumTimeSpentWithUnaccountedType(): void | ||
{ | ||
$contract = Factory\ContractFactory::createOne([ | ||
'timeAccountingUnit' => 30, | ||
]); | ||
$ticket = Factory\TicketFactory::createOne([ | ||
'contracts' => [$contract], | ||
]); | ||
$accountedTimeSpent1 = Factory\TimeSpentFactory::createOne([ | ||
'ticket' => $ticket, | ||
'realTime' => 15, | ||
'time' => 30, | ||
'contract' => $contract, | ||
]); | ||
$accountedTimeSpent2 = Factory\TimeSpentFactory::createOne([ | ||
'ticket' => $ticket, | ||
'realTime' => 5, | ||
'time' => 30, | ||
'contract' => $contract, | ||
]); | ||
$unaccountedTimeSpent1 = Factory\TimeSpentFactory::createOne([ | ||
'ticket' => $ticket, | ||
'realTime' => 15, | ||
'time' => 15, | ||
'contract' => null, | ||
]); | ||
$unaccountedTimeSpent2 = Factory\TimeSpentFactory::createOne([ | ||
'ticket' => $ticket, | ||
'realTime' => 5, | ||
'time' => 5, | ||
'contract' => null, | ||
]); | ||
|
||
$time = $ticket->getSumTimeSpent('unaccounted'); | ||
|
||
$this->assertSame(20, $time); | ||
} | ||
|
||
public function testGetSumTimeSpentWithRealType(): void | ||
{ | ||
$contract = Factory\ContractFactory::createOne([ | ||
'timeAccountingUnit' => 30, | ||
]); | ||
$ticket = Factory\TicketFactory::createOne([ | ||
'contracts' => [$contract], | ||
]); | ||
$accountedTimeSpent1 = Factory\TimeSpentFactory::createOne([ | ||
'ticket' => $ticket, | ||
'realTime' => 15, | ||
'time' => 30, | ||
'contract' => $contract, | ||
]); | ||
$accountedTimeSpent2 = Factory\TimeSpentFactory::createOne([ | ||
'ticket' => $ticket, | ||
'realTime' => 5, | ||
'time' => 30, | ||
'contract' => $contract, | ||
]); | ||
$unaccountedTimeSpent1 = Factory\TimeSpentFactory::createOne([ | ||
'ticket' => $ticket, | ||
'realTime' => 15, | ||
'time' => 15, | ||
'contract' => null, | ||
]); | ||
$unaccountedTimeSpent2 = Factory\TimeSpentFactory::createOne([ | ||
'ticket' => $ticket, | ||
'realTime' => 5, | ||
'time' => 5, | ||
'contract' => null, | ||
]); | ||
|
||
$time = $ticket->getSumTimeSpent('real'); | ||
|
||
$this->assertSame(40, $time); | ||
} | ||
|
||
public function testGetSumTimeSpentWithAnotherType(): void | ||
{ | ||
$contract = Factory\ContractFactory::createOne([ | ||
'timeAccountingUnit' => 30, | ||
]); | ||
$ticket = Factory\TicketFactory::createOne([ | ||
'contracts' => [$contract], | ||
]); | ||
$accountedTimeSpent1 = Factory\TimeSpentFactory::createOne([ | ||
'ticket' => $ticket, | ||
'realTime' => 15, | ||
'time' => 30, | ||
'contract' => $contract, | ||
]); | ||
$accountedTimeSpent2 = Factory\TimeSpentFactory::createOne([ | ||
'ticket' => $ticket, | ||
'realTime' => 5, | ||
'time' => 30, | ||
'contract' => $contract, | ||
]); | ||
$unaccountedTimeSpent1 = Factory\TimeSpentFactory::createOne([ | ||
'ticket' => $ticket, | ||
'realTime' => 15, | ||
'time' => 15, | ||
'contract' => null, | ||
]); | ||
$unaccountedTimeSpent2 = Factory\TimeSpentFactory::createOne([ | ||
'ticket' => $ticket, | ||
'realTime' => 5, | ||
'time' => 5, | ||
'contract' => null, | ||
]); | ||
|
||
$this->expectException(\DomainException::class); | ||
|
||
/** @phpstan-ignore argument.type */ | ||
$ticket->getSumTimeSpent('invalid value'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters