add: more tests

This commit is contained in:
Michael 2024-08-14 12:46:25 +02:00
parent ce7f620984
commit fcd76cf130
11 changed files with 232 additions and 15 deletions

View file

@ -89,9 +89,9 @@ class CsvAgentCostTest extends TestCase
// Ricordarsi che all'esecuzione della funzione, è gia stata dedotta la percentuale interna
$expected = [
'Agent A' => '02:00:00',
'Agent A costo' => 619.21, // 120 minutes * 5.0
'Agent A costo' => 618.67, // 120 minutes * 5.0
'Agent B' => '03:00:00',
'Agent B costo' => 928.8, // 180 minutes * 5.0
'Agent B costo' => 928.0, // 180 minutes * 5.0
];
$result = $this->csv_agent_cost->calculate_agents_cost($array, $agents_time, $minute_cost);
@ -143,7 +143,7 @@ class CsvAgentCostTest extends TestCase
public function testSelectCorrectCostCalculatesCostCorrectly()
{
// percentuale dedotta impostata nel setup
// percentuale dedotta impostata nel setup di questa classe
// Costo orario per cliente con issue high, 75.5€/h
$array = [
'Progetto' => 'Progetto Test',
@ -172,7 +172,7 @@ class CsvAgentCostTest extends TestCase
$expected_result = $array;
$expected_result = array_merge($array, [
'agentTest' => '00:10:00',
'agentTest costo' => 11.4
'agentTest costo' => 11.34
]);
// Call the method being tested

View file

@ -2,14 +2,44 @@
namespace Tests\Http\Controllers\CsvController\CsvCostCalc;
use App\Http\Controllers\CsvController\CsvCostCalc\CsvSumTotalsCalc;
use App\Http\Controllers\CsvController\CsvCostCalc\CsvMinuteCostCalc;
use App\Http\Controllers\CsvController\CsvCostCalc\CsvTotalCostCalc;
use PHPUnit\Framework\TestCase;
class CsvSumTotalsCalcTest extends TestCase
{
protected function setUp(): void
{
$this->CsvTotalCostCalc = new CsvTotalCostCalc();
$this->mockCsvMinuteCostCalc = $this->createMock(CsvMinuteCostCalc::class);
$this->CsvTotalCostCalc->CsvMinuteCostCalc = $this->mockCsvMinuteCostCalc;
}
public function testSum_costs()
{
$array = [
'Request By'=>'RequestBy/Client',
'Priority'=>'Priority/High',
];
$total_time = 3600;
//Valori presi dalla classe di test di CsvMinuteCostCalcTest
$this->mockCsvMinuteCostCalc
->expects($this->once())
->method('select_correct_cost')
->with('RequestBy/Client', 'Priority/High')
->willReturn(1.26); // Mocked return value
$expected = [
'Request By'=>'RequestBy/Client',
'Priority'=>'Priority/High',
'Tempo totale'=>'01:00:00',
'Costo totale'=>75.61,
];
$result = $this->CsvTotalCostCalc->total_time_cost($array, $total_time);
$this->assertEquals($expected, $result);
}
}

View file

@ -2,14 +2,45 @@
namespace Tests\Http\Controllers\CsvController\CsvCostCalc;
use App\Http\Controllers\CsvController\CsvCostCalc\CsvMinuteCostCalc;
use App\Http\Controllers\CsvController\CsvCostCalc\CsvTotalCostCalc;
use PHPUnit\Framework\TestCase;
class CsvTotalCostCalcTest extends TestCase
{
public function testTotal_time_cost()
{
protected function setUp(): void
{
$this->CsvTotalCostCalc = new CsvTotalCostCalc();
$this->mockCsvMinuteCostCalc = $this->createMock(CsvMinuteCostCalc::class);
$this->CsvTotalCostCalc->CsvMinuteCostCalc = $this->mockCsvMinuteCostCalc;
}
public function testSum_costs()
{
$array = [
'Request By'=>'RequestBy/Client',
'Priority'=>'Priority/High',
];
$total_time = 3600;
//Valori presi dalla classe di test di CsvMinuteCostCalcTest
$this->mockCsvMinuteCostCalc
->expects($this->once())
->method('select_correct_cost')
->with('RequestBy/Client', 'Priority/High')
->willReturn(1.26); // Mocked return value
$expected = [
'Request By'=>'RequestBy/Client',
'Priority'=>'Priority/High',
'Tempo totale'=>'01:00:00',
'Costo totale'=>75.61,
];
$result = $this->CsvTotalCostCalc->total_time_cost($array, $total_time);
$this->assertEquals($expected, $result);
}
}