Skip to content

Commit

Permalink
add cases.findBySection
Browse files Browse the repository at this point in the history
  • Loading branch information
Seretos committed Oct 25, 2018
1 parent 9d74539 commit d4ec5c4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/api/Cases.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ public function all(int $projectId, int $suiteId, int $sectionId = null)
return $this->connector->send_get('get_cases/' . $this->encodePath($projectId) . '&suite_id=' . $this->encodePath($suiteId) . '&section_id=' . $this->encodePath($sectionId));
}

public function findBySection(int $projectId, int $suiteId, int $sectionId = null){
$cases = $this->all($projectId,$suiteId,$sectionId);
$resultCases = [];
foreach ($cases as $case) {
if($case['section_id'] === $sectionId){
$resultCases[] = $case;
}
}
return $resultCases;
}

public function get(int $caseId)
{
return $this->connector->send_get('get_case/' . $this->encodePath($caseId));
Expand Down
18 changes: 18 additions & 0 deletions tests/api/CasesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ public function all(){
$this->assertSame([['id' => 1,'name' => 'case1'],['id' => 2,'name' => 'case2']],$this->cases->all(1,2,3));
}

/**
* @test
*/
public function findBySection(){
$this->mockApiConnector->expects($this->at(0))
->method('send_get')
->with('get_cases/1&suite_id=2&section_id=3')
->will($this->returnValue([['id' => 1,'name' => 'case1','section_id' => null],['id' => 2,'name' => 'case2','section_id' => null],['id' => 3,'name' => 'case2','section_id' => 3]]));

$this->mockApiConnector->expects($this->at(1))
->method('send_get')
->with('get_cases/1&suite_id=2&section_id=')
->will($this->returnValue([['id' => 1,'name' => 'case1','section_id' => null],['id' => 2,'name' => 'case2','section_id' => null],['id' => 3,'name' => 'case2','section_id' => 3]]));

$this->assertSame([['id' => 3,'name' => 'case2','section_id' => 3]],$this->cases->findBySection(1,2,3));
$this->assertSame([['id' => 1,'name' => 'case1','section_id' => null],['id' => 2,'name' => 'case2','section_id' => null]],$this->cases->findBySection(1,2));
}

/**
* @test
*/
Expand Down

0 comments on commit d4ec5c4

Please sign in to comment.