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);
}
}

View file

@ -7,9 +7,93 @@ use PHPUnit\Framework\TestCase;
class CsvDataHandlingTest extends TestCase
{
protected function setUp(): void
{
$this->csv_data_handling = new CsvDataHandling();
$this->mockCsvMinuteCostCalc = $this->createMock(CsvMinuteCostCalc::class);
}
public function handleAgentIssue()
{
// Arrange
$agents_issue_time = [];
$time = ['user_name' => 'agent1', 'time' => 5];
// Act
$result = $this->csv_data_handling->handle_agent_issue($agents_issue_time, $time);
// Assert
$this->assertEquals(['agent1' => 5], $result);
// Act with another entry for the same agent
$time = ['user_name' => 'agent1', 'time' => 3];
$result = $this->csv_data_handling->handle_agent_issue($result, $time);
// Assert
$this->assertEquals(['agent1' => 8], $result);
// Act with a different agent
$time = ['user_name' => 'agent2', 'time' => 10];
$result = $this->csv_data_handling->handle_agent_issue($result, $time);
// Assert
$this->assertEquals(['agent1' => 8, 'agent2' => 10], $result);
}
public function getIssueTotalTime()
{
// Arrange
$issue_time = [
['user_name' => 'agent1', 'time' => 5],
['user_name' => 'agent1', 'time' => 3],
['user_name' => 'agent2', 'time' => 10],
];
// Act
list($total_time, $agents_issue_time) = $this->csv_data_handling->get_issue_total_time($issue_time);
// Assert
$this->assertEquals(18, $total_time);
$this->assertEquals(['agent1' => 8, 'agent2' => 10], $agents_issue_time);
}
public function testHandle_csv_time()
{
// Arrange
$array = [
'total_time_cost' => 0,
'agent_cost' => 0,
];
$issue = [
['id' => 1, 'title' => 'Issue 1'],
['id' => 2, 'title' => 'Issue 2'],
];
$issue_time = [
['user_name' => 'agent1', 'time' => 5],
['user_name' => 'agent1', 'time' => 3],
['user_name' => 'agent2', 'time' => 10],
];
$company_agents = [
['name' => 'agent1', 'cost_per_hour' => 50],
['name' => 'agent2', 'cost_per_hour' => 60],
];
$this->csv_data_handling->method('total_time_cost')
->with($array, 18)
->willReturn(['total_time_cost' => 1800]);
$this->csv_data_handling->method('agent_cost_calc')
->with($array, $company_agents, ['agent1' => 8, 'agent2' => 10])
->willReturn(['agent_cost' => 800]);
// Act
$result = $this->csv_data_handling->handle_csv_time($array, $issue, $issue_time, $company_agents);
// Assert
$this->assertEquals(['total_time_cost' => 1800, 'agent_cost' => 800], $result);
}
}

View file

@ -8,13 +8,80 @@ use PHPUnit\Framework\TestCase;
class CsvDataInitTest extends TestCase
{
protected function setUp(): void
{
$this->csv_data_init = new CsvDataInit();
}
public function testInitialize_csv_data()
{
$issue = [
'repository' => ['name' => 'test'],
'number' => 0,
'title' => 'test',
'html_url' => 'https://git.test.test/issue/0',
'created_at' => '2024-08-14-11:00:00',
'closed_at' => '2024-08-14-11:00:00',
'labels' => [
['name' => 'Priority/Low'],
['name' => 'RequestBy/Customer'],
['name' => 'Status/Resolved'],
],
'Kind' => '',
'RequestBy' => '',
'Priority' => '',
];
$result = $this->csv_data_init->initialize_csv_data($issue);
$expected = [
'Progetto' => 'test',
'#' => 0,
'Titolo' => 'test',
'URL' => 'https://git.test.test/issue/0',
'Aperto_il' => '2024-08-14-11:00:00',
'Chiuso_il' => '2024-08-14-11:00:00',
'Etichette' => 'Priority/Low,RequestBy/Customer,Status/Resolved,',
'Kind' => '',
'Request By' => '',
'Priority' => ''
];
$this->assertEquals($expected, $result);
}
public function testHandle_labels()
{
$array = [];
$issue_labels = [
[
'name' => 'Kind: Bug'
],
[
'name' => 'RequestBy: John Doe'
],
[
'name' => 'Priority: High'
],
[
'name' => 'Other Label'
]
];
// Call the handle_labels function
$result = $this->csv_data_init->handle_labels($array, $issue_labels);
// Assert the expected output
$this->assertArrayHasKey('Kind', $result);
$this->assertEquals('Kind: Bug', $result['Kind']);
$this->assertArrayHasKey('Request By', $result);
$this->assertEquals('RequestBy: John Doe', $result['Request By']);
$this->assertArrayHasKey('Priority', $result);
$this->assertEquals('Priority: High', $result['Priority']);
}
}