Skip to content

Commit 7ba7816

Browse files
committed
tests
1 parent d5bb767 commit 7ba7816

File tree

10 files changed

+224
-35
lines changed

10 files changed

+224
-35
lines changed

tests/Feature/API/ApiClientCrudIssueTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace tests\Feature\API;
44

5-
use tests\Feature\API\TestCase\TestCaseIssueApiClientForUpdate;
5+
use tests\Feature\TestCase\TestCaseIssueApiClientForUpdate;
66

77
class ApiClientCrudIssueTest extends TestCaseIssueApiClientForUpdate {
88
//class ApiClientCrudIssueTest extends TestCaseProjectApiClientForUpdate {

tests/Feature/API/Trait/EntitySearch.php

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace tests\Feature\Copy;
4+
5+
use tests\Feature\TestCase\TestCaseTemporaryProject;
6+
use Takuya\BacklogApiClient\Backup\Copy\BacklogCopy;
7+
8+
class CopyBacklogProjectTest extends TestCaseTemporaryProject {
9+
protected function setUp (): void {
10+
parent::setUp(); // TODO: Change the autogenerated stub
11+
$this->api->enableLogging();
12+
}
13+
14+
protected function tearDown (): void {
15+
$this->api->disableLogging();
16+
parent::tearDown(); // TODO: Change the autogenerated stub
17+
}
18+
19+
20+
public function test_copy_project_and_issues_and_comments () {
21+
22+
23+
$projects = $this->api->getProjectList();
24+
$project = null;
25+
foreach ( $projects as $project ) {
26+
if(preg_match('/TAKU/',$project->projectKey)>0){
27+
dump($project);
28+
break;
29+
}
30+
}
31+
$src_project_id = $project->id;
32+
//スペースをまたぐ場合を想定する
33+
$src_cli = $this->api;
34+
$dst_cli = $this->api;
35+
$woker = new BacklogCopy($src_cli,$dst_cli);
36+
$woker->copyProject($src_project_id,$this->project_id);
37+
38+
$src_issue_list = $src_cli->issue_ids($src_project_id);
39+
$dst_issue_list = $dst_cli->issue_ids($this->project_id);
40+
$this->assertEquals(sizeof($src_issue_list),sizeof($dst_issue_list));
41+
//
42+
$src_wiki_list = $src_cli->getWikiPageList(['projectIdOrKey' =>$src_project_id]);
43+
$dst_wiki_list = $dst_cli->getWikiPageList(['projectIdOrKey' =>$this->project_id]);
44+
$this->assertEquals(sizeof($src_wiki_list),sizeof($dst_wiki_list));
45+
46+
47+
48+
49+
50+
51+
}
52+
53+
}

tests/Feature/DAV/DavTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace tests\Feature\DAV;
4+
5+
use tests\TestCase;
6+
use League\Flysystem\Filesystem;
7+
use League\Flysystem\WebDAV\WebDAVAdapter;
8+
use Sabre\DAV\Client;
9+
10+
class DavTest extends TestCase {
11+
12+
public function test_web_dav(){
13+
14+
15+
16+
}
17+
}

tests/Feature/API/TestCase/TestCaseIssueApiClientForUpdate.php renamed to tests/Feature/TestCase/TestCaseIssueApiClientForUpdate.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace tests\Feature\API\TestCase;
3+
namespace tests\Feature\TestCase;
44

55
class TestCaseIssueApiClientForUpdate extends TestCaseProjectApiClientForUpdate {
66

@@ -46,8 +46,8 @@ public function createIssue () {
4646
'description' => 'API経由で課題を作成しますー担当もします。',
4747
'issueTypeId' => $this->findIssueTypeId()->id,
4848
'priorityId' => 2,
49-
'notifiedUserId' => [$this->findAdminUser()->id],
50-
'assigneeId' => $this->findAdminUser()->id,
49+
'notifiedUserId' => [$this->myUserId()],
50+
'assigneeId' => $this->myUserId(),
5151
];
5252
$ret = $this->api->addIssue( $params );
5353
$this->issue_id = $ret->id;

tests/Feature/API/TestCase/TestCaseProjectApiClientForUpdate.php renamed to tests/Feature/TestCase/TestCaseProjectApiClientForUpdate.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
namespace tests\Feature\API\TestCase;
3+
namespace tests\Feature\TestCase;
44

55
use tests\TestCase;
6-
use tests\Feature\API\Trait\EntitySearch;
6+
use tests\Feature\TestCase\Trait\EntitySearch;
77

88
class TestCaseProjectApiClientForUpdate extends TestCase {
99
protected $project_id = null;
@@ -19,7 +19,7 @@ public function __construct ( ?string $name = null, array $data = [], $dataName
1919
$this->api->disableLogging();
2020
}
2121
protected function sample_jpeg_file(){
22-
$sample_filename = realpath(__DIR__.'/../../../sample-data/sample.jpg');
22+
$sample_filename = realpath(__DIR__.'/../../sample-data/sample.jpg');
2323
return [
2424
'name' => basename($sample_filename),
2525
'content'=> file_get_contents($sample_filename)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace tests\Feature\TestCase;
4+
5+
class TestCaseTemporaryProject extends TestCaseProjectApiClientForUpdate {
6+
protected function setUp (): void {
7+
parent::setUp();
8+
}
9+
10+
protected function tearDown (): void {
11+
parent::tearDown();
12+
}
13+
14+
15+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
4+
namespace tests\Feature\TestCase\Trait;
5+
trait EntitySearch {
6+
public function findIssueTypeId () {
7+
$api = $this->api;
8+
$project_id = $this->project_id ?? 91928;
9+
$list = $api->getIssueTypeList( $project_id );
10+
usort( $list, fn( $a, $b ) => $a->id <=> $b->id );
11+
return $list[0];
12+
}
13+
14+
public function findSampleIssueId(){
15+
return $this->findSampleIssue()->id;
16+
}
17+
public function findSampleIssue(){
18+
$api = $this->api;
19+
$project_id = $this->findProjectIdHasIssue();
20+
$issues = $api->getIssueList(['projectId'=>[$project_id],'sort'=>'updated','order'=>'desc','count'=>20]);
21+
shuffle($issues);
22+
return $issues[0];
23+
}
24+
public function findProjectIdHasIssue(){
25+
$api = $this->api;
26+
$projects = $api->getProjectList();
27+
shuffle($projects);
28+
foreach ( $projects as $project ) {
29+
$ret = $api->countIssue(['projectId'=>[$project->id]]);
30+
if($ret->count>0){
31+
return $project->id;
32+
}
33+
}
34+
return null;
35+
}
36+
public function findIssueHasVersion (){
37+
$api = $this->api;
38+
$projects = $api->getProjectList();
39+
shuffle($projects);
40+
foreach ( $projects as $project ) {
41+
$ret = $api->getVersionMilestoneList($project->id);
42+
if (sizeof($ret)>0){
43+
shuffle($ret);
44+
break;
45+
}
46+
}
47+
$id = $ret[0]->id;
48+
$list = $api->getIssueList(['versionId'=>[$id]]);
49+
if (empty($list)){return null;}
50+
return $list[0];
51+
}
52+
public function myUserId(){
53+
return $this->api->getOwnUser()->id;
54+
}
55+
public function findAdminUser () {
56+
if ( $this->admin_user ?? false ) {
57+
return $this->admin_user;
58+
}
59+
$api = $this->api;
60+
$list = $api->getUserList();
61+
$list = array_filter( $list, fn( $e ) => $e->roleType == 1 );
62+
usort($list,fn($a,$b)=>$a->id<=>$b->id);
63+
//usort( $list, fn( $a, $b ) => $b->id <=> $a->id );
64+
$this->admin_user = $list[0];
65+
return $this->admin_user;
66+
}
67+
68+
}

tests/Unit/Api/Updates/APIOfUpdateTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,35 @@
33
namespace tests\Unit\Api\Updates;
44

55
use tests\TestCase;
6+
use GuzzleHttp\Exception\RequestException;
67

78
class APIOfUpdateTest extends TestCase {
89
public function test_work(){
910
$this->assertTrue(true);
1011
}
1112
public function test_add_delete_project () {
1213
$api = $this->api_client();
13-
$params = ['form_params' => ['key' => 'API_SAMPLE', 'name' => 'APIから作成テスト']];
14+
$params = ['form_params' => ['key' => 'API_SAMPLE_'.rand(100,999), 'name' => 'APIから作成テスト']];
1415
$a = $api->addProject( $params );
16+
usleep(200);//ちょっとだけ待つ
17+
//
18+
$info = $api->getProject($a->id);
19+
$this->assertEquals($params['form_params']['name'],$info->name);
20+
$this->assertEquals($params['form_params']['key'],$info->projectKey);
21+
//
1522
$b = $api->deleteProject( $params['form_params']['key'] );
23+
usleep(200);//ちょっとだけ待つ
1624
$this->assertEquals( $a->id, $b->id );
25+
// 削除チェック
26+
$this->expectException(RequestException::class);
27+
$api->getProject($a->id);
28+
}
29+
public function test_remove_project(){
30+
$list =$this->model_client()->space()->my_projects();
31+
foreach ( $list as $item ) {
32+
if ($item->name == 'APIから作成テスト'){
33+
$this->api_client()->deleteProject($item->id);
34+
}
35+
}
1736
}
1837
}

tests/Unit/Utils/ArrayMapTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace tests\Unit\Utils;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use function Takuya\Utils\array_map_with_key;
7+
use function Takuya\Utils\array_map_on_keys;
8+
use function Takuya\Utils\array_subtract;
9+
use function Takuya\Utils\array_column_select;
10+
11+
class ArrayMapTest extends TestCase {
12+
13+
public function test_array_map_with_key () {
14+
$array = ['a' => 1, 'b' => 2];
15+
16+
$result = array_map_with_key( $array, fn( $k, $v ) => $k == 'b' ? $v*$v : $v );
17+
$this->assertEquals( ['a' => 1, 'b' => 4], $result );
18+
19+
$result = array_map_with_key( $array, fn( $k, $v ) => $v );
20+
$this->assertEquals( $array, $result );
21+
}
22+
23+
public function test_array_map_on_keys () {
24+
$array = ['a' => 1, 'b' => 2];
25+
$result = array_map_on_keys( ['a'], $array, fn( $e ) => $e*2 );
26+
$this->assertEquals( ['a' => 2, 'b' => 2], $result );
27+
}
28+
29+
public function test_array_subtract () {
30+
$p = [['a' => 1], ['b' => 1], ['c' => 1]];
31+
$q = [['a' => 1], ['b' => 1], ['d' => 1]];
32+
$r = array_subtract( $p, $q );
33+
$this->assertEquals( [['c' => 1]], $r );
34+
}
35+
36+
public function test_array_column_select () {
37+
$x = [
38+
['a' => 1, 'b' => 1, 'c' => 1],
39+
['a' => 2, 'b' => 2, 'c' => 2],
40+
];
41+
$y = array_column_select( ['a', 'b'], $x );
42+
$this->assertEquals( [['a' => 1, 'b' => 1,],['a' => 2, 'b' => 2,],], $y );
43+
}
44+
}

0 commit comments

Comments
 (0)