Skip to content

Commit

Permalink
feat: #4 create iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkcup committed Oct 23, 2021
1 parent 2de53a4 commit 668e585
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"require-dev": {
"fakerphp/faker": "^1.16",
"mockery/mockery": "^1.4",
"phpmd/phpmd": "^2.10",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.6"
Expand Down
2 changes: 1 addition & 1 deletion src/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Core
protected string $token;
protected Client $client;

public function __construct(string $token, Client $client = null)
public function __construct(string $token = '', Client $client = null)
{
$this->token = $token;
$this->client = $client ?? new Client();
Expand Down
19 changes: 19 additions & 0 deletions src/Iteration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Coding;

class Iteration
{
private Core $core;

public function __construct(string $token, Core $core = null)
{
$this->core = $core ?? new Core($token);
}

public function create(array $data)
{
$response = $this->core->request('CreateIteration', $data);
return $response['Iteration'];
}
}
31 changes: 31 additions & 0 deletions tests/IterationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Coding\Tests;

use Coding\Core;
use Coding\Iteration;

class IterationTest extends TestCase
{
public function testCreateSuccess()
{
$coreMock = \Mockery::mock(Core::class, [])->makePartial();

$response = json_decode(
file_get_contents($this->dataPath('CreateIterationResponse.json')),
true
)['Response'];
$data = [
'ProjectName' => $this->projectName,
'Name' => $this->faker->title,
];
$coreMock->shouldReceive('request')->times(1)->withArgs([
'CreateIteration',
$data
])->andReturn($response);

$iteration = new Iteration($this->token, $coreMock);
$result = $iteration->create($data);
$this->assertEquals($response['Iteration'], $result);
}
}

0 comments on commit 668e585

Please sign in to comment.