add: more tests
This commit is contained in:
parent
ce7f620984
commit
fcd76cf130
11 changed files with 232 additions and 15 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue