Skip to content

Commit

Permalink
add result api
Browse files Browse the repository at this point in the history
  • Loading branch information
Seretos committed Oct 5, 2018
1 parent d5e8f2c commit 749cb19
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use seretos\testrail\api\Projects;
use seretos\testrail\api\Results;
use seretos\testrail\api\Sections;
use seretos\testrail\api\Statuses;
use seretos\testrail\api\Suites;
use seretos\testrail\api\Templates;
use seretos\testrail\api\Types;
Expand Down Expand Up @@ -91,6 +92,10 @@ public function results(){
return new Results($this->connector);
}

public function statuses(){
return new Statuses($this->connector);
}

public function api($name){
switch ($name){
case 'projects':
Expand All @@ -117,6 +122,8 @@ public function api($name){
return $this->configurations();
case 'results':
return $this->results();
case 'statuses':
return $this->statuses();
}
return null;
}
Expand Down
6 changes: 5 additions & 1 deletion src/api/Results.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@

class Results extends AbstractApi
{

public function create(int $runId, int $caseId, int $statusId){
$result = $this->connector->send_post('add_result_for_case/'.$this->encodePath($runId).'/'.$this->encodePath($caseId),
['status_id' => $statusId]);
return $result;
}
}
34 changes: 34 additions & 0 deletions src/api/Statuses.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Created by PhpStorm.
* User: aappen
* Date: 05.10.18
* Time: 13:42
*/

namespace seretos\testrail\api;


class Statuses extends AbstractApi
{
private $cache = null;

public function all()
{
if($this->cache === null) {
$this->cache = $this->connector->send_get('get_statuses');
}
return $this->cache;
}

public function findByName(string $name)
{
$states = $this->all();
foreach ($states as $state) {
if ($state['name'] === $name) {
return $state;
}
}
return [];
}
}
15 changes: 15 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use seretos\testrail\api\Projects;
use seretos\testrail\api\Results;
use seretos\testrail\api\Sections;
use seretos\testrail\api\Statuses;
use seretos\testrail\api\Suites;
use seretos\testrail\api\Templates;
use seretos\testrail\api\Types;
Expand Down Expand Up @@ -208,4 +209,18 @@ public function results(){
public function apiResults(){
$this->assertInstanceOf(Results::class,$this->client->api('results'));
}

/**
* @test
*/
public function statuses(){
$this->assertInstanceOf(Statuses::class,$this->client->statuses());
}

/**
* @test
*/
public function apiStatuses(){
$this->assertInstanceOf(Statuses::class,$this->client->api('statuses'));
}
}
9 changes: 7 additions & 2 deletions tests/api/ResultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ protected function setUp()
/**
* @test
*/
public function test(){
$this->assertSame('tst','tst');
public function create(){
$this->mockApiConnector->expects($this->once())
->method('send_post')
->with('add_result_for_case/1/2',['status_id' => 3])
->will($this->returnValue(['id' => 1,'name' => 'result1']));

$this->assertSame(['id' => 1,'name' => 'result1'],$this->results->create(1,2,3));
}
}
56 changes: 56 additions & 0 deletions tests/api/StatusesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

use PHPUnit\Framework\TestCase;
use seretos\testrail\api\Statuses;
use seretos\testrail\connector\ApiConnectorInterface;

/**
* Created by PhpStorm.
* User: aappen
* Date: 05.10.18
* Time: 13:45
*/

class StatusesTest extends TestCase
{
/**
* @var Statuses
*/
private $statuses;
/**
* @var ApiConnectorInterface|PHPUnit_Framework_MockObject_MockObject
*/
private $mockApiConnector;

protected function setUp()
{
parent::setUp();
$this->mockApiConnector = $this->getMockBuilder(ApiConnectorInterface::class)->disableOriginalConstructor()->getMock();

$this->statuses = new Statuses($this->mockApiConnector);
}

/**
* @test
*/
public function all(){
$this->mockApiConnector->expects($this->once())
->method('send_get')
->with('get_statuses')
->will($this->returnValue([['id' => 1,'name' => 'state1'],['id' => 2,'name' => 'state2']]));

$this->assertSame([['id' => 1,'name' => 'state1'],['id' => 2,'name' => 'state2']],$this->statuses->all());
}

/**
* @test
*/
public function findByName(){
$this->mockApiConnector->expects($this->once())
->method('send_get')
->with('get_statuses')
->will($this->returnValue([['id' => 1,'name' => 'state1'],['id' => 2,'name' => 'state2']]));

$this->assertSame(['id' => 2,'name' => 'state2'],$this->statuses->findByName('state2'));
}
}

0 comments on commit 749cb19

Please sign in to comment.