From b2b1e7dc8f7585356e7e055f1a26166cda47544f Mon Sep 17 00:00:00 2001 From: emreakay Date: Tue, 6 Sep 2022 16:20:41 +0300 Subject: [PATCH 01/31] changelog deleted --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9364fe9..f134465 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ Before using this, please make sure that you published the config files. ## Changelog -Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. +Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.. ## Contributing From 1ee76d4116f378f8795956db9711bb0d0b8fc204 Mon Sep 17 00:00:00 2001 From: emreakay Date: Tue, 6 Sep 2022 16:22:41 +0300 Subject: [PATCH 02/31] changelog added --- .github/workflows/update-changelog.yml | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/update-changelog.yml diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml new file mode 100644 index 0000000..b20f3b6 --- /dev/null +++ b/.github/workflows/update-changelog.yml @@ -0,0 +1,28 @@ +name: "Update Changelog" + +on: + release: + types: [released] + +jobs: + update: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + ref: main + + - name: Update Changelog + uses: stefanzweifel/changelog-updater-action@v1 + with: + latest-version: ${{ github.event.release.name }} + release-notes: ${{ github.event.release.body }} + + - name: Commit updated CHANGELOG + uses: stefanzweifel/git-auto-commit-action@v4 + with: + branch: main + commit_message: Update CHANGELOG + file_pattern: CHANGELOG.md From 671fc1086d4dd4905d4c242ac8cc8f908760cf72 Mon Sep 17 00:00:00 2001 From: emreakay Date: Tue, 6 Sep 2022 16:26:43 +0300 Subject: [PATCH 03/31] changelog added --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f134465..6461789 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ Before using this, please make sure that you published the config files. ## Changelog -Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.. +Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently... ## Contributing From 0bf3ba004e01aca551fb7ad1e8e734b12b862e1f Mon Sep 17 00:00:00 2001 From: emreakay Date: Tue, 6 Sep 2022 16:28:40 +0300 Subject: [PATCH 04/31] changelog added --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6461789..61c9c5b 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ Before using this, please make sure that you published the config files. ## Changelog -Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently... +Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.... ## Contributing From 5c40a1535ada053beea96aa12b5a8927c5ed5fcf Mon Sep 17 00:00:00 2001 From: emreakay Date: Tue, 6 Sep 2022 16:50:46 +0300 Subject: [PATCH 05/31] changelog added --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 61c9c5b..9364fe9 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ Before using this, please make sure that you published the config files. ## Changelog -Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.... +Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. ## Contributing From 8075912bf3a49bfa6f1ab6bf43fe8e72ad9a118e Mon Sep 17 00:00:00 2001 From: emreakay Date: Tue, 6 Sep 2022 13:51:24 +0000 Subject: [PATCH 06/31] Fix styling --- database/migrations/create_aissue_tables.php | 5 ++--- src/AIssueServiceProvider.php | 3 +-- tests/Unit/AIssueTest.php | 1 - 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/database/migrations/create_aissue_tables.php b/database/migrations/create_aissue_tables.php index 103dfd2..c1117c7 100644 --- a/database/migrations/create_aissue_tables.php +++ b/database/migrations/create_aissue_tables.php @@ -34,12 +34,11 @@ public function up() $table->string('description'); $table->timestamps(); }); - } - public function down(){ + public function down() + { Schema::dropIfExists('aissue_issues'); Schema::dropIfExists('aissue_issue_types'); } - }; diff --git a/src/AIssueServiceProvider.php b/src/AIssueServiceProvider.php index 6a98958..18e98fb 100644 --- a/src/AIssueServiceProvider.php +++ b/src/AIssueServiceProvider.php @@ -28,7 +28,6 @@ public function boot() parent::boot(); // load packages migrations - $this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); - + $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); } } diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index 52348d8..10d0ca5 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -4,7 +4,6 @@ $this->assertTrue(true); }); - test('passOrAbort', function () { expect(1)->toBeTruthy(); }); From 67cc68fb100040eb2d81eb65ae3c35c7a537f037 Mon Sep 17 00:00:00 2001 From: emreakay Date: Tue, 6 Sep 2022 17:49:30 +0300 Subject: [PATCH 07/31] contracts and exceptions created --- README-todo.md | 7 ++++ src/AIssue.php | 1 + src/Contracts/AIssueContract.php | 40 +++++++++++++++++++ .../TransitionPermissionException.php | 11 +++++ .../TransitionStatusNotFoundException.php | 9 +++++ src/Traits/AIssue.php | 0 6 files changed, 68 insertions(+) create mode 100644 README-todo.md create mode 100644 src/Contracts/AIssueContract.php create mode 100644 src/Exceptions/TransitionPermissionException.php create mode 100644 src/Exceptions/TransitionStatusNotFoundException.php create mode 100644 src/Traits/AIssue.php diff --git a/README-todo.md b/README-todo.md new file mode 100644 index 0000000..25ce28b --- /dev/null +++ b/README-todo.md @@ -0,0 +1,7 @@ + - contract + - service + - trait + - config dosyası, status'ler, permissionlar, permiissoon policychecker + - publishler + - yetki konteolleri + - board diff --git a/src/AIssue.php b/src/AIssue.php index 63c819f..8f2cfb1 100755 --- a/src/AIssue.php +++ b/src/AIssue.php @@ -4,4 +4,5 @@ class AIssue { + } diff --git a/src/Contracts/AIssueContract.php b/src/Contracts/AIssueContract.php new file mode 100644 index 0000000..53b3c85 --- /dev/null +++ b/src/Contracts/AIssueContract.php @@ -0,0 +1,40 @@ + + */ + public function getTransitionableStatuses(): array; + + /** + * @param string $status + * @throws TransitionStatusNotFoundException + * @throws TransitionPermissionException + * @return bool + */ + public function makeTransition(string $status): bool; +} diff --git a/src/Exceptions/TransitionPermissionException.php b/src/Exceptions/TransitionPermissionException.php new file mode 100644 index 0000000..c107ba6 --- /dev/null +++ b/src/Exceptions/TransitionPermissionException.php @@ -0,0 +1,11 @@ + Date: Tue, 6 Sep 2022 14:50:11 +0000 Subject: [PATCH 08/31] Fix styling --- src/AIssue.php | 1 - src/Contracts/AIssueContract.php | 5 +++-- src/Exceptions/TransitionPermissionException.php | 2 -- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/AIssue.php b/src/AIssue.php index 8f2cfb1..63c819f 100755 --- a/src/AIssue.php +++ b/src/AIssue.php @@ -4,5 +4,4 @@ class AIssue { - } diff --git a/src/Contracts/AIssueContract.php b/src/Contracts/AIssueContract.php index 53b3c85..895767a 100644 --- a/src/Contracts/AIssueContract.php +++ b/src/Contracts/AIssueContract.php @@ -31,10 +31,11 @@ public function getAIssueType(): string; public function getTransitionableStatuses(): array; /** - * @param string $status + * @param string $status + * @return bool + * * @throws TransitionStatusNotFoundException * @throws TransitionPermissionException - * @return bool */ public function makeTransition(string $status): bool; } diff --git a/src/Exceptions/TransitionPermissionException.php b/src/Exceptions/TransitionPermissionException.php index c107ba6..1d8b35b 100644 --- a/src/Exceptions/TransitionPermissionException.php +++ b/src/Exceptions/TransitionPermissionException.php @@ -4,8 +4,6 @@ use Illuminate\Auth\AuthenticationException; - class TransitionPermissionException extends AuthenticationException { - } From 5cc2199c8f517a5080b56217bb32f8984e31765c Mon Sep 17 00:00:00 2001 From: Emrullah Numan Sinan Date: Tue, 6 Sep 2022 17:54:08 +0300 Subject: [PATCH 09/31] test --- database/migrations/create_aissue_tables.php | 12 ++--- src/Models/AIssue.php | 49 ++++++++++++++++++ tests/Unit/AIssueTest.php | 53 +++++++++++++++++++- 3 files changed, 106 insertions(+), 8 deletions(-) create mode 100644 src/Models/AIssue.php diff --git a/database/migrations/create_aissue_tables.php b/database/migrations/create_aissue_tables.php index c1117c7..826649e 100644 --- a/database/migrations/create_aissue_tables.php +++ b/database/migrations/create_aissue_tables.php @@ -12,17 +12,17 @@ public function up() $table->bigIncrements('id'); $table->string('code')->nullable(); $table->string('model_type'); - $table->bigIncrements('model_id'); - $table->bigIncrements('assignee_id'); - $table->bigIncrements('creater_id'); - $table->bigIncrements('issue_type_id'); + $table->bigInteger('model_id'); + $table->bigInteger('assignee_id'); + $table->bigInteger('creater_id'); + $table->bigInteger('issue_type_id'); $table->string('summary'); $table->string('description'); - $table->bigIncrements('priority'); + $table->bigInteger('priority'); $table->string('status'); $table->dateTime('duedate'); $table->boolean('archived'); - $table->bigIncrements('archived_by'); + $table->bigInteger('archived_by'); $table->dateTime('archived_at'); $table->timestamps(); }); diff --git a/src/Models/AIssue.php b/src/Models/AIssue.php new file mode 100644 index 0000000..59a1f52 --- /dev/null +++ b/src/Models/AIssue.php @@ -0,0 +1,49 @@ +assertTrue(true); +use AuroraWebSoftware\AAuth\Models\AIssue; +use Illuminate\Support\Facades\Artisan; + +beforeEach(function () { + Artisan::call('migrate:fresh'); + }); test('passOrAbort', function () { expect(1)->toBeTruthy(); }); + +test('can get one specified issue', function () { + //AAuth::organizationNodes(); + // todo + expect(1)->toBeTruthy(); +}); + +it(description: 'stores the data correctly in the database') + ->tap( + fn (): AIssue => AIssue::create( + [ + 'id' => 1, + 'code' => '', + 'model_type' => 'test', + 'model_id' => 1, + 'assignee_id' => 1, + 'creater_id' => 1, + 'issue_type_id' => 1, + 'summary' => 'test', + 'description' => 'test', + 'status' => 'true', + 'duedate' => '', + 'archived' => true, + 'archived_by' => 1, + 'archived_at' => '', + ] + ) + )->assertDatabaseHas('aissues', [ + 'approvalable_type' => 'App\Models\FakeModel', + 'approvalable_id' => 1, + 'state' => ApprovalStatus::Pending, + ]); + + + + + + + + + + + + + From a8274ba0eebef6ead60bce4a0e00ff570c30f6e9 Mon Sep 17 00:00:00 2001 From: emreakay Date: Tue, 6 Sep 2022 19:02:20 +0300 Subject: [PATCH 10/31] contracts and exceptions created --- src/Traits/AIssue.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Traits/AIssue.php b/src/Traits/AIssue.php index e69de29..23fed04 100644 --- a/src/Traits/AIssue.php +++ b/src/Traits/AIssue.php @@ -0,0 +1,27 @@ + + */ + public function getTransitionableStatuses(): array { + + } + + /** + * @param string $status + * @throws TransitionStatusNotFoundException + * @throws TransitionPermissionException + * @return bool + */ + public function makeTransition(string $status): { + + } + +} From 15628e7063b802ad2484f87e0141acebeee6747f Mon Sep 17 00:00:00 2001 From: Emrullah Numan Sinan Date: Wed, 7 Sep 2022 17:37:54 +0300 Subject: [PATCH 11/31] test --- src/AIssueServiceProvider.php | 1 - tests/Unit/AIssueTest.php | 42 ++++++++++++++--------------------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/AIssueServiceProvider.php b/src/AIssueServiceProvider.php index 18e98fb..d0f6a78 100644 --- a/src/AIssueServiceProvider.php +++ b/src/AIssueServiceProvider.php @@ -26,7 +26,6 @@ public function configurePackage(Package $package): void public function boot() { parent::boot(); - // load packages migrations $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); } diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index 6c21639..4a96a30 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -6,6 +6,22 @@ beforeEach(function () { Artisan::call('migrate:fresh'); + $this->aissueData = [ + 'id' => 1, + 'code' => '', + 'model_type' => 'test', + 'model_id' => 1, + 'assignee_id' => 1, + 'creater_id' => 1, + 'issue_type_id' => 1, + 'summary' => 'test', + 'description' => 'test', + 'status' => 'true', + 'duedate' => '', + 'archived' => true, + 'archived_by' => 1, + 'archived_at' => '', + ]; }); test('passOrAbort', function () { @@ -18,31 +34,7 @@ expect(1)->toBeTruthy(); }); -it(description: 'stores the data correctly in the database') - ->tap( - fn (): AIssue => AIssue::create( - [ - 'id' => 1, - 'code' => '', - 'model_type' => 'test', - 'model_id' => 1, - 'assignee_id' => 1, - 'creater_id' => 1, - 'issue_type_id' => 1, - 'summary' => 'test', - 'description' => 'test', - 'status' => 'true', - 'duedate' => '', - 'archived' => true, - 'archived_by' => 1, - 'archived_at' => '', - ] - ) - )->assertDatabaseHas('aissues', [ - 'approvalable_type' => 'App\Models\FakeModel', - 'approvalable_id' => 1, - 'state' => ApprovalStatus::Pending, - ]); + From 5f32bc6349f9b79973963c399b76b011ac92cd79 Mon Sep 17 00:00:00 2001 From: emreakay Date: Wed, 7 Sep 2022 18:26:23 +0300 Subject: [PATCH 12/31] - tests created - some fixes --- config/aissue.php | 14 ++++- database/migrations/create_aissue_tables.php | 11 +--- src/AIssue.php | 3 + ...ueContract.php => AIssueModelContract.php} | 18 +----- src/Models/AIssue.php | 58 +++++++------------ tests/Unit/AIssueTest.php | 14 ++++- 6 files changed, 53 insertions(+), 65 deletions(-) rename src/Contracts/{AIssueContract.php => AIssueModelContract.php} (55%) diff --git a/config/aissue.php b/config/aissue.php index b14e74c..275ed0b 100644 --- a/config/aissue.php +++ b/config/aissue.php @@ -1,6 +1,18 @@ fn($permission): bool => true, + 'issueTypes' => [ + 'task' => [ + 'statuses' => + [ + 'todo' => ['sort' => 1, 'permission' => 'todo_perm'], + 'in_progress' => ['sort' => 2, 'permission' => 'in_progress_perm'], + 'done' => ['sort' => 3, 'permission' => 'done_perm'], + ] + ], + ], ]; diff --git a/database/migrations/create_aissue_tables.php b/database/migrations/create_aissue_tables.php index 826649e..f2846e8 100644 --- a/database/migrations/create_aissue_tables.php +++ b/database/migrations/create_aissue_tables.php @@ -15,7 +15,7 @@ public function up() $table->bigInteger('model_id'); $table->bigInteger('assignee_id'); $table->bigInteger('creater_id'); - $table->bigInteger('issue_type_id'); + $table->string('issue_type'); $table->string('summary'); $table->string('description'); $table->bigInteger('priority'); @@ -26,19 +26,10 @@ public function up() $table->dateTime('archived_at'); $table->timestamps(); }); - - Schema::create('aissue_issue_types', function (Blueprint $table) { - $table->bigIncrements('id'); - $table->string('workflow'); - $table->string('name'); - $table->string('description'); - $table->timestamps(); - }); } public function down() { Schema::dropIfExists('aissue_issues'); - Schema::dropIfExists('aissue_issue_types'); } }; diff --git a/src/AIssue.php b/src/AIssue.php index 63c819f..f6e197b 100755 --- a/src/AIssue.php +++ b/src/AIssue.php @@ -4,4 +4,7 @@ class AIssue { + + + } diff --git a/src/Contracts/AIssueContract.php b/src/Contracts/AIssueModelContract.php similarity index 55% rename from src/Contracts/AIssueContract.php rename to src/Contracts/AIssueModelContract.php index 895767a..29ba22c 100644 --- a/src/Contracts/AIssueContract.php +++ b/src/Contracts/AIssueModelContract.php @@ -6,9 +6,9 @@ use AuroraWebSoftware\AIssue\Exceptions\TransitionStatusNotFoundException; /** - * AIssueContract + * AIssueModelContract */ -interface AIssueContract +interface AIssueModelContract { /** * @return string @@ -24,18 +24,4 @@ public function getAIssueModelId(): string; * @return string */ public function getAIssueType(): string; - - /** - * @return array - */ - public function getTransitionableStatuses(): array; - - /** - * @param string $status - * @return bool - * - * @throws TransitionStatusNotFoundException - * @throws TransitionPermissionException - */ - public function makeTransition(string $status): bool; } diff --git a/src/Models/AIssue.php b/src/Models/AIssue.php index 59a1f52..7717f98 100644 --- a/src/Models/AIssue.php +++ b/src/Models/AIssue.php @@ -1,49 +1,35 @@ + */ + public function getTransitionableStatuses(): array + { + // config('aissue') + } + + /** + * @param string $status + * @return bool + * @throws TransitionStatusNotFoundException + * @throws TransitionPermissionException + */ + public function makeTransition(string $status): bool + { + // statusü değiştircek + } + } diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index 4a96a30..baf1f22 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -24,10 +24,20 @@ ]; }); -test('passOrAbort', function () { - expect(1)->toBeTruthy(); +test('can read aissue config', function () { + $this->assertNotNull(config('aissue')); +}); + +test('can access policy method', function () { + $this->assertTrue(config('aissue')['policyMethod'] instanceof \Closure); }); +test('can access policy method works', function () { + $this->assertTrue(config('aissue')['policyMethod']('test permission')); +}); + + + test('can get one specified issue', function () { //AAuth::organizationNodes(); // todo From 61190219946958797e41c909407c0f2b5ca080a3 Mon Sep 17 00:00:00 2001 From: emreakay Date: Wed, 7 Sep 2022 18:42:09 +0300 Subject: [PATCH 13/31] - tests created - some fixes --- config/aissue.php | 9 +++------ src/AIssue.php | 22 ++++++++++++++++++++++ src/Models/AIssue.php | 2 ++ src/Traits/AIssue.php | 21 +++------------------ 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/config/aissue.php b/config/aissue.php index 275ed0b..4e75121 100644 --- a/config/aissue.php +++ b/config/aissue.php @@ -7,12 +7,9 @@ 'policyMethod' => fn($permission): bool => true, 'issueTypes' => [ 'task' => [ - 'statuses' => - [ - 'todo' => ['sort' => 1, 'permission' => 'todo_perm'], - 'in_progress' => ['sort' => 2, 'permission' => 'in_progress_perm'], - 'done' => ['sort' => 3, 'permission' => 'done_perm'], - ] + 'todo' => ['sort' => 1, 'permission' => 'todo_perm'], + 'in_progress' => ['sort' => 2, 'permission' => 'in_progress_perm'], + 'done' => ['sort' => 3, 'permission' => 'done_perm'], ], ], ]; diff --git a/src/AIssue.php b/src/AIssue.php index f6e197b..1a6e2bc 100755 --- a/src/AIssue.php +++ b/src/AIssue.php @@ -4,7 +4,29 @@ class AIssue { + public function createIssue(): \AuroraWebSoftware\AIssue\Models\AIssue + { + } + + public function canMakeTransition(\AuroraWebSoftware\AIssue\Models\AIssue $issue, $status): bool + { + $permission = config('aissue')['issueTypes']['$issue->issueType'][$status]['permission']; + if (config('aissue')['policyMethod']($permission)) { + return true; + } + return false; + } + + public function makeTransition(\AuroraWebSoftware\AIssue\Models\AIssue $issue, $status): \AuroraWebSoftware\AIssue\Models\AIssue + { + if ($this->canMakeTransition($issue, $status)) { + $issue->status = $status; + $issue->save(); + } + return $issue; + } + } diff --git a/src/Models/AIssue.php b/src/Models/AIssue.php index 7717f98..c03f5b1 100644 --- a/src/Models/AIssue.php +++ b/src/Models/AIssue.php @@ -12,6 +12,8 @@ class AIssue extends Model use HasFactory; public $guarded = []; + public string $issueType; + public string $status; /** * @return array diff --git a/src/Traits/AIssue.php b/src/Traits/AIssue.php index 23fed04..a4e6ed7 100644 --- a/src/Traits/AIssue.php +++ b/src/Traits/AIssue.php @@ -2,26 +2,11 @@ namespace AuroraWebSoftware\AIssue\Traits; -use AuroraWebSoftware\AIssue\Exceptions\TransitionPermissionException; -use AuroraWebSoftware\AIssue\Exceptions\TransitionStatusNotFoundException; +use AuroraWebSoftware\AIssue\Models\AIssue; -trait AIssue { +trait AIssueModel { - /** - * @return array - */ - public function getTransitionableStatuses(): array { + public function createIssue() : AIssue { } - - /** - * @param string $status - * @throws TransitionStatusNotFoundException - * @throws TransitionPermissionException - * @return bool - */ - public function makeTransition(string $status): { - - } - } From c16b669d6049877be745414eeb120c84ccfef401 Mon Sep 17 00:00:00 2001 From: emreakay Date: Wed, 7 Sep 2022 15:42:46 +0000 Subject: [PATCH 14/31] Fix styling --- config/aissue.php | 3 +-- src/AIssue.php | 12 +++++------- src/Contracts/AIssueModelContract.php | 3 --- src/Models/AIssue.php | 6 ++++-- src/Traits/AIssue.php | 8 ++++---- tests/Unit/AIssueTest.php | 18 ------------------ 6 files changed, 14 insertions(+), 36 deletions(-) diff --git a/config/aissue.php b/config/aissue.php index 4e75121..0beb691 100644 --- a/config/aissue.php +++ b/config/aissue.php @@ -2,9 +2,8 @@ // config for AuroraWebSoftware/AIssue - return [ - 'policyMethod' => fn($permission): bool => true, + 'policyMethod' => fn ($permission): bool => true, 'issueTypes' => [ 'task' => [ 'todo' => ['sort' => 1, 'permission' => 'todo_perm'], diff --git a/src/AIssue.php b/src/AIssue.php index 1a6e2bc..edcaa0f 100755 --- a/src/AIssue.php +++ b/src/AIssue.php @@ -4,29 +4,27 @@ class AIssue { - public function createIssue(): \AuroraWebSoftware\AIssue\Models\AIssue + public function createIssue(): Models\AIssue { - - - } - public function canMakeTransition(\AuroraWebSoftware\AIssue\Models\AIssue $issue, $status): bool + public function canMakeTransition(Models\AIssue $issue, $status): bool { $permission = config('aissue')['issueTypes']['$issue->issueType'][$status]['permission']; if (config('aissue')['policyMethod']($permission)) { return true; } + return false; } - public function makeTransition(\AuroraWebSoftware\AIssue\Models\AIssue $issue, $status): \AuroraWebSoftware\AIssue\Models\AIssue + public function makeTransition(Models\AIssue $issue, $status): Models\AIssue { if ($this->canMakeTransition($issue, $status)) { $issue->status = $status; $issue->save(); } + return $issue; } - } diff --git a/src/Contracts/AIssueModelContract.php b/src/Contracts/AIssueModelContract.php index 29ba22c..eb1cea8 100644 --- a/src/Contracts/AIssueModelContract.php +++ b/src/Contracts/AIssueModelContract.php @@ -2,9 +2,6 @@ namespace AuroraWebSoftware\AIssue\Contracts; -use AuroraWebSoftware\AIssue\Exceptions\TransitionPermissionException; -use AuroraWebSoftware\AIssue\Exceptions\TransitionStatusNotFoundException; - /** * AIssueModelContract */ diff --git a/src/Models/AIssue.php b/src/Models/AIssue.php index c03f5b1..a97a29f 100644 --- a/src/Models/AIssue.php +++ b/src/Models/AIssue.php @@ -12,7 +12,9 @@ class AIssue extends Model use HasFactory; public $guarded = []; + public string $issueType; + public string $status; /** @@ -24,8 +26,9 @@ public function getTransitionableStatuses(): array } /** - * @param string $status + * @param string $status * @return bool + * * @throws TransitionStatusNotFoundException * @throws TransitionPermissionException */ @@ -33,5 +36,4 @@ public function makeTransition(string $status): bool { // statusü değiştircek } - } diff --git a/src/Traits/AIssue.php b/src/Traits/AIssue.php index a4e6ed7..4700c7d 100644 --- a/src/Traits/AIssue.php +++ b/src/Traits/AIssue.php @@ -4,9 +4,9 @@ use AuroraWebSoftware\AIssue\Models\AIssue; -trait AIssueModel { - - public function createIssue() : AIssue { - +trait AIssueModel +{ + public function createIssue(): AIssue + { } } diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index baf1f22..c89f589 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -1,6 +1,5 @@ assertTrue(config('aissue')['policyMethod']('test permission')); }); - - test('can get one specified issue', function () { //AAuth::organizationNodes(); // todo expect(1)->toBeTruthy(); }); - - - - - - - - - - - - - - - From b4b41f87c87ab5dc3947de1b7092a418cb722739 Mon Sep 17 00:00:00 2001 From: emreakay Date: Wed, 7 Sep 2022 18:49:55 +0300 Subject: [PATCH 15/31] - AIssue class --- src/AIssue.php | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/AIssue.php b/src/AIssue.php index 1a6e2bc..4d9a1eb 100755 --- a/src/AIssue.php +++ b/src/AIssue.php @@ -4,14 +4,19 @@ class AIssue { - public function createIssue(): \AuroraWebSoftware\AIssue\Models\AIssue + public function createIssue(): Models\AIssue { } - public function canMakeTransition(\AuroraWebSoftware\AIssue\Models\AIssue $issue, $status): bool + /** + * @param Models\AIssue $issue + * @param $status + * @return bool + */ + public function canMakeTransition(Models\AIssue $issue, $status): bool { $permission = config('aissue')['issueTypes']['$issue->issueType'][$status]['permission']; if (config('aissue')['policyMethod']($permission)) { @@ -20,7 +25,12 @@ public function canMakeTransition(\AuroraWebSoftware\AIssue\Models\AIssue $issue return false; } - public function makeTransition(\AuroraWebSoftware\AIssue\Models\AIssue $issue, $status): \AuroraWebSoftware\AIssue\Models\AIssue + /** + * @param Models\AIssue $issue + * @param $status + * @return Models\AIssue + */ + public function makeTransition(Models\AIssue $issue, $status): Models\AIssue { if ($this->canMakeTransition($issue, $status)) { $issue->status = $status; @@ -29,4 +39,21 @@ public function makeTransition(\AuroraWebSoftware\AIssue\Models\AIssue $issue, $ return $issue; } + + /** + * @param Models\AIssue $issue + * @return array + */ + public function getTransitionableStatuses(Models\AIssue $issue) : array { + + $statuses = []; + foreach ( config('aissue')['issueTypes'][$issue->issueType] as $index => $item) { + + if ($this->canMakeTransition($issue, $index)) { + $statuses[] = $index; + } + } + return $statuses; + } + } From fb713298bfd1f4c81bb2978cc77401535cda0ae4 Mon Sep 17 00:00:00 2001 From: emreakay Date: Wed, 7 Sep 2022 15:52:05 +0000 Subject: [PATCH 16/31] Fix styling --- src/AIssue.php | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/AIssue.php b/src/AIssue.php index 4d9a1eb..c2ebf54 100755 --- a/src/AIssue.php +++ b/src/AIssue.php @@ -6,13 +6,10 @@ class AIssue { public function createIssue(): Models\AIssue { - - - } /** - * @param Models\AIssue $issue + * @param Models\AIssue $issue * @param $status * @return bool */ @@ -22,11 +19,12 @@ public function canMakeTransition(Models\AIssue $issue, $status): bool if (config('aissue')['policyMethod']($permission)) { return true; } + return false; } /** - * @param Models\AIssue $issue + * @param Models\AIssue $issue * @param $status * @return Models\AIssue */ @@ -36,24 +34,23 @@ public function makeTransition(Models\AIssue $issue, $status): Models\AIssue $issue->status = $status; $issue->save(); } + return $issue; } - /** - * @param Models\AIssue $issue + * @param Models\AIssue $issue * @return array */ - public function getTransitionableStatuses(Models\AIssue $issue) : array { - + public function getTransitionableStatuses(Models\AIssue $issue): array + { $statuses = []; - foreach ( config('aissue')['issueTypes'][$issue->issueType] as $index => $item) { - + foreach (config('aissue')['issueTypes'][$issue->issueType] as $index => $item) { if ($this->canMakeTransition($issue, $index)) { $statuses[] = $index; } } + return $statuses; } - } From bac4df63a5794a0b4e790c7529c8ca03d19d889e Mon Sep 17 00:00:00 2001 From: Emrullah Numan Sinan Date: Thu, 8 Sep 2022 13:41:24 +0300 Subject: [PATCH 17/31] Aissue create test --- src/AIssue.php | 4 +++- src/Models/AIssue.php | 1 + tests/Unit/AIssueTest.php | 42 +++++++++++++++++++++++++-------------- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/AIssue.php b/src/AIssue.php index c2ebf54..4c17102 100755 --- a/src/AIssue.php +++ b/src/AIssue.php @@ -4,8 +4,10 @@ class AIssue { - public function createIssue(): Models\AIssue + + public static function createIssue($data): Models\AIssue { + return Models\AIssue::create($data); } /** diff --git a/src/Models/AIssue.php b/src/Models/AIssue.php index a97a29f..4b027fe 100644 --- a/src/Models/AIssue.php +++ b/src/Models/AIssue.php @@ -12,6 +12,7 @@ class AIssue extends Model use HasFactory; public $guarded = []; + protected $table = 'aissue_issues'; public string $issueType; diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index c89f589..6c08c0c 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -1,26 +1,38 @@ aissueData = [ - 'id' => 1, - 'code' => '', - 'model_type' => 'test', - 'model_id' => 1, - 'assignee_id' => 1, - 'creater_id' => 1, - 'issue_type_id' => 1, - 'summary' => 'test', - 'description' => 'test', - 'status' => 'true', - 'duedate' => '', - 'archived' => true, - 'archived_by' => 1, - 'archived_at' => '', + // arrange + $data = [ + 'code'=>'test', + 'model_type'=>'test', + 'model_id'=>1, + 'assignee_id'=>1, + 'creater_id'=>1, + 'issue_type'=>'test', + 'summary'=>'test', + 'description'=>'test', + 'priority'=>1, + 'status'=>'test', + 'duedate'=>'2022-09-08 09:04:15', + 'archived'=>true, + 'archived_by'=>'test', + 'archived_at'=>'2022-09-08 09:04:15', ]; + + $createdAissue = AuroraWebSoftware\AIssue\AIssue::createIssue($data); + + $isExist = AIssue::where('id','=',$createdAissue->id)->exists(); + $this->assertTrue($isExist); + + //2022-09-08 09:04:15 }); test('can read aissue config', function () { From c49b2a4e4d53402ac2bd6b4cd0900e489629d6a3 Mon Sep 17 00:00:00 2001 From: nusinan Date: Thu, 8 Sep 2022 10:42:24 +0000 Subject: [PATCH 18/31] Fix styling --- src/AIssue.php | 1 - src/Models/AIssue.php | 1 + tests/Unit/AIssueTest.php | 31 +++++++++++++++---------------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/AIssue.php b/src/AIssue.php index 4c17102..75ebd64 100755 --- a/src/AIssue.php +++ b/src/AIssue.php @@ -4,7 +4,6 @@ class AIssue { - public static function createIssue($data): Models\AIssue { return Models\AIssue::create($data); diff --git a/src/Models/AIssue.php b/src/Models/AIssue.php index 4b027fe..21382af 100644 --- a/src/Models/AIssue.php +++ b/src/Models/AIssue.php @@ -12,6 +12,7 @@ class AIssue extends Model use HasFactory; public $guarded = []; + protected $table = 'aissue_issues'; public string $issueType; diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index 6c08c0c..c234843 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -8,28 +8,27 @@ }); test('can create aissue', function () { - // arrange $data = [ - 'code'=>'test', - 'model_type'=>'test', - 'model_id'=>1, - 'assignee_id'=>1, - 'creater_id'=>1, - 'issue_type'=>'test', - 'summary'=>'test', - 'description'=>'test', - 'priority'=>1, - 'status'=>'test', - 'duedate'=>'2022-09-08 09:04:15', - 'archived'=>true, - 'archived_by'=>'test', - 'archived_at'=>'2022-09-08 09:04:15', + 'code' => 'test', + 'model_type' => 'test', + 'model_id' => 1, + 'assignee_id' => 1, + 'creater_id' => 1, + 'issue_type' => 'test', + 'summary' => 'test', + 'description' => 'test', + 'priority' => 1, + 'status' => 'test', + 'duedate' => '2022-09-08 09:04:15', + 'archived' => true, + 'archived_by' => 'test', + 'archived_at' => '2022-09-08 09:04:15', ]; $createdAissue = AuroraWebSoftware\AIssue\AIssue::createIssue($data); - $isExist = AIssue::where('id','=',$createdAissue->id)->exists(); + $isExist = AIssue::where('id', '=', $createdAissue->id)->exists(); $this->assertTrue($isExist); //2022-09-08 09:04:15 From 2de89a63e26eae3efb8ad8a99bb7dd19333111fc Mon Sep 17 00:00:00 2001 From: Emrullah Numan Sinan Date: Thu, 8 Sep 2022 15:00:50 +0300 Subject: [PATCH 19/31] Aissue create test --- tests/Unit/AIssueTest.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index c234843..4749835 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -5,11 +5,7 @@ beforeEach(function () { Artisan::call('migrate:fresh'); -}); - -test('can create aissue', function () { - // arrange - $data = [ + $this->data = [ 'code' => 'test', 'model_type' => 'test', 'model_id' => 1, @@ -26,12 +22,7 @@ 'archived_at' => '2022-09-08 09:04:15', ]; - $createdAissue = AuroraWebSoftware\AIssue\AIssue::createIssue($data); - - $isExist = AIssue::where('id', '=', $createdAissue->id)->exists(); - $this->assertTrue($isExist); - - //2022-09-08 09:04:15 + $this->aissue = new AuroraWebSoftware\AIssue\AIssue(); }); test('can read aissue config', function () { @@ -51,3 +42,9 @@ // todo expect(1)->toBeTruthy(); }); + +test('can create aissue', function () { + $createdAissue = $this->aissue->createIssue($this->data); + $isExist = AIssue::where('id', '=', $createdAissue->id)->exists(); + $this->assertTrue($isExist); +}); From cb3f057546e81096d870557782834483903aa7fe Mon Sep 17 00:00:00 2001 From: Emrullah Numan Sinan Date: Thu, 8 Sep 2022 15:04:14 +0300 Subject: [PATCH 20/31] Aissue can transition test --- src/AIssue.php | 2 +- tests/Unit/AIssueTest.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/AIssue.php b/src/AIssue.php index 75ebd64..b4d1e5b 100755 --- a/src/AIssue.php +++ b/src/AIssue.php @@ -16,7 +16,7 @@ public static function createIssue($data): Models\AIssue */ public function canMakeTransition(Models\AIssue $issue, $status): bool { - $permission = config('aissue')['issueTypes']['$issue->issueType'][$status]['permission']; + $permission = config('aissue')['issueTypes']['task'][$status]['permission']; if (config('aissue')['policyMethod']($permission)) { return true; } diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index 4749835..8d77524 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -48,3 +48,9 @@ $isExist = AIssue::where('id', '=', $createdAissue->id)->exists(); $this->assertTrue($isExist); }); + +test('can make transition', function () { + $createdAissue = $this->aissue->createIssue($this->data); + $transition = $this->aissue->makeTransition($createdAissue,'todo'); + $this->assertTrue($transition->status == 'todo'); +}); From 10b26b4b268359a5e4d68f84af1558f3d0fa6b61 Mon Sep 17 00:00:00 2001 From: nusinan Date: Thu, 8 Sep 2022 12:04:49 +0000 Subject: [PATCH 21/31] Fix styling --- tests/Unit/AIssueTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index 8d77524..0bbcbbc 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -51,6 +51,6 @@ test('can make transition', function () { $createdAissue = $this->aissue->createIssue($this->data); - $transition = $this->aissue->makeTransition($createdAissue,'todo'); + $transition = $this->aissue->makeTransition($createdAissue, 'todo'); $this->assertTrue($transition->status == 'todo'); }); From 2b7dfe795e4078cf61b53409163b17f7112dec09 Mon Sep 17 00:00:00 2001 From: Emrullah Numan Sinan Date: Thu, 8 Sep 2022 15:17:17 +0300 Subject: [PATCH 22/31] test --- tests/Unit/AIssueTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index 0bbcbbc..38b68dd 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -51,6 +51,12 @@ test('can make transition', function () { $createdAissue = $this->aissue->createIssue($this->data); - $transition = $this->aissue->makeTransition($createdAissue, 'todo'); + $transition = $this->aissue->makeTransition($createdAissue,'todo'); $this->assertTrue($transition->status == 'todo'); }); + +test('can get transitionable statuses', function () { + $createdAissue = $this->aissue->createIssue($this->data); + $transitionableStatuses = $this->aissue->getTransitionableStatuses($createdAissue); + // $this->assertTrue($transition->status == 'todo'); +}); From 0f6b304987cc7e1a3e8f7d2ce85b5a428e95f5c6 Mon Sep 17 00:00:00 2001 From: nusinan Date: Thu, 8 Sep 2022 12:17:56 +0000 Subject: [PATCH 23/31] Fix styling --- tests/Unit/AIssueTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index 38b68dd..1c9248a 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -51,12 +51,12 @@ test('can make transition', function () { $createdAissue = $this->aissue->createIssue($this->data); - $transition = $this->aissue->makeTransition($createdAissue,'todo'); + $transition = $this->aissue->makeTransition($createdAissue, 'todo'); $this->assertTrue($transition->status == 'todo'); }); test('can get transitionable statuses', function () { $createdAissue = $this->aissue->createIssue($this->data); $transitionableStatuses = $this->aissue->getTransitionableStatuses($createdAissue); - // $this->assertTrue($transition->status == 'todo'); + // $this->assertTrue($transition->status == 'todo'); }); From 0b502862c8c9931ed2fff98f923e12efd9d244aa Mon Sep 17 00:00:00 2001 From: Emrullah Numan Sinan Date: Fri, 9 Sep 2022 16:21:20 +0300 Subject: [PATCH 24/31] test --- src/AIssue.php | 2 -- tests/Unit/AIssueTest.php | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/AIssue.php b/src/AIssue.php index b4d1e5b..38ef3ae 100755 --- a/src/AIssue.php +++ b/src/AIssue.php @@ -20,7 +20,6 @@ public function canMakeTransition(Models\AIssue $issue, $status): bool if (config('aissue')['policyMethod']($permission)) { return true; } - return false; } @@ -35,7 +34,6 @@ public function makeTransition(Models\AIssue $issue, $status): Models\AIssue $issue->status = $status; $issue->save(); } - return $issue; } diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index 1c9248a..e312ef0 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -45,8 +45,7 @@ test('can create aissue', function () { $createdAissue = $this->aissue->createIssue($this->data); - $isExist = AIssue::where('id', '=', $createdAissue->id)->exists(); - $this->assertTrue($isExist); + $this->assertDatabaseHas('aissue_issues', $this->data); }); test('can make transition', function () { From 832f645c0bbff0935725c12ba3c46cbd6e769352 Mon Sep 17 00:00:00 2001 From: nusinan Date: Fri, 9 Sep 2022 13:22:06 +0000 Subject: [PATCH 25/31] Fix styling --- src/AIssue.php | 2 ++ tests/Unit/AIssueTest.php | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/AIssue.php b/src/AIssue.php index 38ef3ae..b4d1e5b 100755 --- a/src/AIssue.php +++ b/src/AIssue.php @@ -20,6 +20,7 @@ public function canMakeTransition(Models\AIssue $issue, $status): bool if (config('aissue')['policyMethod']($permission)) { return true; } + return false; } @@ -34,6 +35,7 @@ public function makeTransition(Models\AIssue $issue, $status): Models\AIssue $issue->status = $status; $issue->save(); } + return $issue; } diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index e312ef0..42d0997 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -1,6 +1,5 @@ Date: Tue, 13 Sep 2022 18:14:37 +0300 Subject: [PATCH 26/31] - traits created - facade created - phpunit fixed --- database/migrations/create_aissue_tables.php | 13 ++-- docker-compose.yml | 4 +- src/AIssue.php | 13 +++- src/Contracts/AIssueModelContract.php | 11 ++- src/Facades/AIssue.php | 4 ++ src/Traits/AIssue.php | 12 ---- src/Traits/AIssueModelTrait.php | 74 ++++++++++++++++++++ tests/Models/Issueable.php | 46 ++++++++++++ tests/TestCase.php | 3 +- tests/Unit/AIssueTest.php | 20 ++++++ 10 files changed, 172 insertions(+), 28 deletions(-) delete mode 100644 src/Traits/AIssue.php create mode 100644 src/Traits/AIssueModelTrait.php create mode 100644 tests/Models/Issueable.php diff --git a/database/migrations/create_aissue_tables.php b/database/migrations/create_aissue_tables.php index f2846e8..06ebcae 100644 --- a/database/migrations/create_aissue_tables.php +++ b/database/migrations/create_aissue_tables.php @@ -10,20 +10,19 @@ public function up() { Schema::create('aissue_issues', function (Blueprint $table) { $table->bigIncrements('id'); - $table->string('code')->nullable(); $table->string('model_type'); $table->bigInteger('model_id'); $table->bigInteger('assignee_id'); $table->bigInteger('creater_id'); $table->string('issue_type'); $table->string('summary'); - $table->string('description'); - $table->bigInteger('priority'); + $table->string('description')->nullable(); + $table->bigInteger('priority')->default(1); $table->string('status'); - $table->dateTime('duedate'); - $table->boolean('archived'); - $table->bigInteger('archived_by'); - $table->dateTime('archived_at'); + $table->dateTime('duedate')->nullable(); + $table->boolean('archived')->default(false); + $table->bigInteger('archived_by')->nullable(); + $table->dateTime('archived_at')->nullable(); $table->timestamps(); }); } diff --git a/docker-compose.yml b/docker-compose.yml index 68369dd..4b4e486 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: ports: - "33062:3306" volumes: - - ~/apps/mariadb-aissue:/var/lib/mysql + - ~/apps/mariadb-aissue2:/var/lib/mysql environment: - MYSQL_ROOT_PASSWORD=aissue - MYSQL_PASSWORD=aissue @@ -17,4 +17,4 @@ networks: driver: bridge ipam: config: - - subnet: 172.16.57.0/24 + - subnet: 172.16.54.0/24 diff --git a/src/AIssue.php b/src/AIssue.php index b4d1e5b..c51a953 100755 --- a/src/AIssue.php +++ b/src/AIssue.php @@ -2,9 +2,15 @@ namespace AuroraWebSoftware\AIssue; +use AuroraWebSoftware\AIssue\Exceptions\TransitionPermissionException; + class AIssue { - public static function createIssue($data): Models\AIssue + /** + * @param $data + * @return Models\AIssue + */ + public function createIssue($data): Models\AIssue { return Models\AIssue::create($data); } @@ -25,9 +31,10 @@ public function canMakeTransition(Models\AIssue $issue, $status): bool } /** - * @param Models\AIssue $issue + * @param Models\AIssue $issue * @param $status * @return Models\AIssue + * @throws TransitionPermissionException */ public function makeTransition(Models\AIssue $issue, $status): Models\AIssue { @@ -36,7 +43,7 @@ public function makeTransition(Models\AIssue $issue, $status): Models\AIssue $issue->save(); } - return $issue; + throw new TransitionPermissionException(); } /** diff --git a/src/Contracts/AIssueModelContract.php b/src/Contracts/AIssueModelContract.php index eb1cea8..70e09cb 100644 --- a/src/Contracts/AIssueModelContract.php +++ b/src/Contracts/AIssueModelContract.php @@ -10,15 +10,20 @@ interface AIssueModelContract /** * @return string */ - public function getAIssueModelType(): string; + public static function getAIssueType(): string; /** * @return string */ - public function getAIssueModelId(): string; + public static function getAIssueDefaultStatus(): string; + + /** + * @return string + */ + public static function getAIssueModelType(): string; /** * @return string */ - public function getAIssueType(): string; + public function getAIssueModelId(): string; } diff --git a/src/Facades/AIssue.php b/src/Facades/AIssue.php index d73ef7f..3d8c8a1 100644 --- a/src/Facades/AIssue.php +++ b/src/Facades/AIssue.php @@ -6,6 +6,10 @@ /** * @see \AuroraWebSoftware\AIssue\AIssue + * @method static createIssue($data): \AuroraWebSoftware\AIssue\Models\AIssue + * @method static canMakeTransition(\AuroraWebSoftware\AIssue\Models\AIssue $issue, $status): bool + * @method static makeTransition(\AuroraWebSoftware\AIssue\Models\AIssue $issue, $status): \AuroraWebSoftware\AIssue\Models\AIssue + * @method static getTransitionableStatuses(\AuroraWebSoftware\AIssue\Models\AIssue $issue) */ class AIssue extends Facade { diff --git a/src/Traits/AIssue.php b/src/Traits/AIssue.php deleted file mode 100644 index 4700c7d..0000000 --- a/src/Traits/AIssue.php +++ /dev/null @@ -1,12 +0,0 @@ - 'test', + 'model_type' => static::getAIssueModelType(), + 'model_id' => $this->id, + 'assignee_id' => $assigneeId, + 'creater_id' => $createrId, + 'issue_type' => static::getAIssueType(), + 'summary' => $summary, + 'description' => $description, + 'priority' => $priority, + 'status' => static::getAIssueDefaultStatus(), + 'duedate' => $duedate, + ]; + + return AIssue::createIssue($data); + } + + /** + * @param $status + * @return bool + */ + public function canMakeTransition($status): bool + { + return AIssue::canMakeTransition($this, $status); + } + + /** + * @param $status + * @return \AuroraWebSoftware\AIssue\Models\AIssue + */ + public function makeTransition($status): \AuroraWebSoftware\AIssue\Models\AIssue + { + return AIssue::makeTransition($this, $status); + } + + /** + * @param \AuroraWebSoftware\AIssue\Models\AIssue $issue + * @return array + */ + public function getTransitionableStatuses(\AuroraWebSoftware\AIssue\Models\AIssue $issue): array + { + return AIssue::getTransitionableStatuses($this); + } + + +} diff --git a/tests/Models/Issueable.php b/tests/Models/Issueable.php new file mode 100644 index 0000000..522193a --- /dev/null +++ b/tests/Models/Issueable.php @@ -0,0 +1,46 @@ +id; + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 3b6c9bb..40ce6f6 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -26,7 +26,8 @@ protected function getPackageProviders($app) public function getEnvironmentSetUp($app) { - config()->set('database.default', 'testing'); + //config()->set('database.default', 'testing'); + config()->set('database.default', 'mysql'); /* $migration = include __DIR__.'/../database/migrations/create_aissue_table.php.stub'; diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index 42d0997..c965dee 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -1,9 +1,19 @@ id(); + $table->string('name'); + $table->timestamps(); + }); + $this->data = [ 'code' => 'test', 'model_type' => 'test', @@ -58,3 +68,13 @@ $transitionableStatuses = $this->aissue->getTransitionableStatuses($createdAissue); // $this->assertTrue($transition->status == 'todo'); }); + + +test('x', function () { + + $createdModel = Issueable::create( + ['name' => 'asd'] + ); + + +}); From b28ce91997daf480211c00e3e5a7e2035caeeb62 Mon Sep 17 00:00:00 2001 From: emreakay Date: Tue, 13 Sep 2022 15:16:13 +0000 Subject: [PATCH 27/31] Fix styling --- src/AIssue.php | 3 ++- src/Facades/AIssue.php | 1 + src/Traits/AIssueModelTrait.php | 26 +++++++++++--------------- tests/Unit/AIssueTest.php | 4 ---- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/AIssue.php b/src/AIssue.php index c51a953..3a9e74d 100755 --- a/src/AIssue.php +++ b/src/AIssue.php @@ -31,9 +31,10 @@ public function canMakeTransition(Models\AIssue $issue, $status): bool } /** - * @param Models\AIssue $issue + * @param Models\AIssue $issue * @param $status * @return Models\AIssue + * * @throws TransitionPermissionException */ public function makeTransition(Models\AIssue $issue, $status): Models\AIssue diff --git a/src/Facades/AIssue.php b/src/Facades/AIssue.php index 3d8c8a1..5c63e03 100644 --- a/src/Facades/AIssue.php +++ b/src/Facades/AIssue.php @@ -6,6 +6,7 @@ /** * @see \AuroraWebSoftware\AIssue\AIssue + * * @method static createIssue($data): \AuroraWebSoftware\AIssue\Models\AIssue * @method static canMakeTransition(\AuroraWebSoftware\AIssue\Models\AIssue $issue, $status): bool * @method static makeTransition(\AuroraWebSoftware\AIssue\Models\AIssue $issue, $status): \AuroraWebSoftware\AIssue\Models\AIssue diff --git a/src/Traits/AIssueModelTrait.php b/src/Traits/AIssueModelTrait.php index 76cade9..8b3faec 100644 --- a/src/Traits/AIssueModelTrait.php +++ b/src/Traits/AIssueModelTrait.php @@ -2,30 +2,28 @@ namespace AuroraWebSoftware\AIssue\Traits; - use AuroraWebSoftware\AIssue\Facades\AIssue; use Illuminate\Support\Carbon; trait AIssueModelTrait { /** - * @param int $assigneeId - * @param int $createrId - * @param string $summary - * @param string $description - * @param int $priority - * @param Carbon $duedate + * @param int $assigneeId + * @param int $createrId + * @param string $summary + * @param string $description + * @param int $priority + * @param Carbon $duedate * @return \AuroraWebSoftware\AIssue\Models\AIssue */ public function createIssue( - int $assigneeId, - int $createrId, + int $assigneeId, + int $createrId, string $summary, string $description, - int $priority, + int $priority, Carbon $duedate, - ): \AuroraWebSoftware\AIssue\Models\AIssue - { + ): \AuroraWebSoftware\AIssue\Models\AIssue { $data = [ 'code' => 'test', 'model_type' => static::getAIssueModelType(), @@ -62,13 +60,11 @@ public function makeTransition($status): \AuroraWebSoftware\AIssue\Models\AIssue } /** - * @param \AuroraWebSoftware\AIssue\Models\AIssue $issue + * @param \AuroraWebSoftware\AIssue\Models\AIssue $issue * @return array */ public function getTransitionableStatuses(\AuroraWebSoftware\AIssue\Models\AIssue $issue): array { return AIssue::getTransitionableStatuses($this); } - - } diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index c965dee..ffc284f 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -69,12 +69,8 @@ // $this->assertTrue($transition->status == 'todo'); }); - test('x', function () { - $createdModel = Issueable::create( ['name' => 'asd'] ); - - }); From 6050d6e5fc14fa5b15f637eab230d56581d52921 Mon Sep 17 00:00:00 2001 From: emreakay Date: Wed, 14 Sep 2022 11:48:49 +0300 Subject: [PATCH 28/31] - traits fixed - phpunit and pest fixed --- src/AIssue.php | 2 +- src/AIssueServiceProvider.php | 5 ++++ src/Contracts/AIssueModelContract.php | 12 +++----- src/Models/AIssue.php | 40 +++++++++++++++++---------- src/Traits/AIssueModelTrait.php | 38 ++++--------------------- tests/Models/Issueable.php | 18 +++++------- tests/Unit/AIssueTest.php | 36 ++++++++---------------- 7 files changed, 60 insertions(+), 91 deletions(-) diff --git a/src/AIssue.php b/src/AIssue.php index c51a953..60bc28b 100755 --- a/src/AIssue.php +++ b/src/AIssue.php @@ -53,7 +53,7 @@ public function makeTransition(Models\AIssue $issue, $status): Models\AIssue public function getTransitionableStatuses(Models\AIssue $issue): array { $statuses = []; - foreach (config('aissue')['issueTypes'][$issue->issueType] as $index => $item) { + foreach (config('aissue')['issueTypes'][$issue->getIssueType()] as $index => $item) { if ($this->canMakeTransition($issue, $index)) { $statuses[] = $index; } diff --git a/src/AIssueServiceProvider.php b/src/AIssueServiceProvider.php index d0f6a78..95e5a7e 100644 --- a/src/AIssueServiceProvider.php +++ b/src/AIssueServiceProvider.php @@ -28,5 +28,10 @@ public function boot() parent::boot(); // load packages migrations $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); + + + $this->publishes([ + __DIR__ . '/../config' => config_path(), + ], 'aissue-config'); } } diff --git a/src/Contracts/AIssueModelContract.php b/src/Contracts/AIssueModelContract.php index 70e09cb..c05a085 100644 --- a/src/Contracts/AIssueModelContract.php +++ b/src/Contracts/AIssueModelContract.php @@ -8,14 +8,10 @@ interface AIssueModelContract { /** + * @param string $issueType * @return string */ - public static function getAIssueType(): string; - - /** - * @return string - */ - public static function getAIssueDefaultStatus(): string; + public static function getAIssueDefaultStatus(string $issueType): string; /** * @return string @@ -23,7 +19,7 @@ public static function getAIssueDefaultStatus(): string; public static function getAIssueModelType(): string; /** - * @return string + * @return int */ - public function getAIssueModelId(): string; + public function getAIssueModelId(): int; } diff --git a/src/Models/AIssue.php b/src/Models/AIssue.php index 21382af..92f6113 100644 --- a/src/Models/AIssue.php +++ b/src/Models/AIssue.php @@ -2,8 +2,6 @@ namespace AuroraWebSoftware\AIssue\Models; -use AuroraWebSoftware\AIssue\Exceptions\TransitionPermissionException; -use AuroraWebSoftware\AIssue\Exceptions\TransitionStatusNotFoundException; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -12,30 +10,44 @@ class AIssue extends Model use HasFactory; public $guarded = []; + public string $status; + public string $issue_type; protected $table = 'aissue_issues'; - public string $issueType; + /** + * @return string + */ + public function getIssueType(): string + { + return $this->issue_type; + } - public string $status; + /** + * @param $status + * @return bool + */ + public function canMakeTransition($status): bool + { + return \AuroraWebSoftware\AIssue\Facades\AIssue::canMakeTransition($this, $status); + } /** - * @return array + * @param $status + * @return AIssue */ - public function getTransitionableStatuses(): array + public function makeTransition($status): AIssue { - // config('aissue') + return \AuroraWebSoftware\AIssue\Facades\AIssue::makeTransition($this, $status); } /** - * @param string $status - * @return bool - * - * @throws TransitionStatusNotFoundException - * @throws TransitionPermissionException + * @param AIssue $issue + * @return array */ - public function makeTransition(string $status): bool + public function getTransitionableStatuses(AIssue $issue): array { - // statusü değiştircek + return \AuroraWebSoftware\AIssue\Facades\AIssue::getTransitionableStatuses($this); } + } diff --git a/src/Traits/AIssueModelTrait.php b/src/Traits/AIssueModelTrait.php index 76cade9..7e0c354 100644 --- a/src/Traits/AIssueModelTrait.php +++ b/src/Traits/AIssueModelTrait.php @@ -11,6 +11,7 @@ trait AIssueModelTrait /** * @param int $assigneeId * @param int $createrId + * @param string $issueType * @param string $summary * @param string $description * @param int $priority @@ -20,6 +21,7 @@ trait AIssueModelTrait public function createIssue( int $assigneeId, int $createrId, + string $issueType, string $summary, string $description, int $priority, @@ -27,48 +29,18 @@ public function createIssue( ): \AuroraWebSoftware\AIssue\Models\AIssue { $data = [ - 'code' => 'test', 'model_type' => static::getAIssueModelType(), - 'model_id' => $this->id, + 'model_id' => $this->getAIssueModelId(), 'assignee_id' => $assigneeId, 'creater_id' => $createrId, - 'issue_type' => static::getAIssueType(), + 'issue_type' => $issueType, 'summary' => $summary, 'description' => $description, 'priority' => $priority, - 'status' => static::getAIssueDefaultStatus(), + 'status' => static::getAIssueDefaultStatus($issueType), 'duedate' => $duedate, ]; return AIssue::createIssue($data); } - - /** - * @param $status - * @return bool - */ - public function canMakeTransition($status): bool - { - return AIssue::canMakeTransition($this, $status); - } - - /** - * @param $status - * @return \AuroraWebSoftware\AIssue\Models\AIssue - */ - public function makeTransition($status): \AuroraWebSoftware\AIssue\Models\AIssue - { - return AIssue::makeTransition($this, $status); - } - - /** - * @param \AuroraWebSoftware\AIssue\Models\AIssue $issue - * @return array - */ - public function getTransitionableStatuses(\AuroraWebSoftware\AIssue\Models\AIssue $issue): array - { - return AIssue::getTransitionableStatuses($this); - } - - } diff --git a/tests/Models/Issueable.php b/tests/Models/Issueable.php index 522193a..923e77b 100644 --- a/tests/Models/Issueable.php +++ b/tests/Models/Issueable.php @@ -6,6 +6,9 @@ use AuroraWebSoftware\AIssue\Traits\AIssueModelTrait; use Illuminate\Database\Eloquent\Model; +/** + * @property-read int $id + */ class Issueable extends Model implements AIssueModelContract { use AIssueModelTrait; @@ -13,17 +16,10 @@ class Issueable extends Model implements AIssueModelContract protected $fillable = ['name']; /** + * @param string $issueType * @return string */ - public static function getAIssueType(): string - { - return 'task'; - } - - /** - * @return string - */ - public static function getAIssueDefaultStatus(): string + public static function getAIssueDefaultStatus(string $issueType): string { return 'todo'; } @@ -37,9 +33,9 @@ public static function getAIssueModelType(): string } /** - * @return string + * @return int */ - public function getAIssueModelId(): string + public function getAIssueModelId(): int { return $this->id; } diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index c965dee..61211ae 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -14,24 +14,6 @@ $table->timestamps(); }); - $this->data = [ - 'code' => 'test', - 'model_type' => 'test', - 'model_id' => 1, - 'assignee_id' => 1, - 'creater_id' => 1, - 'issue_type' => 'test', - 'summary' => 'test', - 'description' => 'test', - 'priority' => 1, - 'status' => 'test', - 'duedate' => '2022-09-08 09:04:15', - 'archived' => true, - 'archived_by' => 'test', - 'archived_at' => '2022-09-08 09:04:15', - ]; - - $this->aissue = new AuroraWebSoftware\AIssue\AIssue(); }); test('can read aissue config', function () { @@ -53,8 +35,18 @@ }); test('can create aissue', function () { - $createdAissue = $this->aissue->createIssue($this->data); - $this->assertDatabaseHas('aissue_issues', $this->data); + + $createdModel = Issueable::create( + ['name' => 'test isuable model 1'] + ); + + $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 1', 'asdasd', 1, \Illuminate\Support\Carbon::now()); + + $this->assertEquals( + \AuroraWebSoftware\AIssue\Models\AIssue::where('id', '=', $createdIssueModel->id )->first()->summary, + $createdIssueModel->summary + ); + }); test('can make transition', function () { @@ -72,9 +64,5 @@ test('x', function () { - $createdModel = Issueable::create( - ['name' => 'asd'] - ); - }); From 92b2638fc07687bc4d1d2c2b57a5eb46768eec6d Mon Sep 17 00:00:00 2001 From: emreakay Date: Wed, 14 Sep 2022 08:50:10 +0000 Subject: [PATCH 29/31] Fix styling --- src/AIssueServiceProvider.php | 3 +-- src/Contracts/AIssueModelContract.php | 2 +- src/Models/AIssue.php | 5 +++-- src/Traits/AIssueModelTrait.php | 24 +++++++++++------------- tests/Models/Issueable.php | 2 +- tests/Unit/AIssueTest.php | 8 +------- 6 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/AIssueServiceProvider.php b/src/AIssueServiceProvider.php index 95e5a7e..6b862df 100644 --- a/src/AIssueServiceProvider.php +++ b/src/AIssueServiceProvider.php @@ -29,9 +29,8 @@ public function boot() // load packages migrations $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); - $this->publishes([ - __DIR__ . '/../config' => config_path(), + __DIR__.'/../config' => config_path(), ], 'aissue-config'); } } diff --git a/src/Contracts/AIssueModelContract.php b/src/Contracts/AIssueModelContract.php index c05a085..0f0db58 100644 --- a/src/Contracts/AIssueModelContract.php +++ b/src/Contracts/AIssueModelContract.php @@ -8,7 +8,7 @@ interface AIssueModelContract { /** - * @param string $issueType + * @param string $issueType * @return string */ public static function getAIssueDefaultStatus(string $issueType): string; diff --git a/src/Models/AIssue.php b/src/Models/AIssue.php index 92f6113..75d1dab 100644 --- a/src/Models/AIssue.php +++ b/src/Models/AIssue.php @@ -10,7 +10,9 @@ class AIssue extends Model use HasFactory; public $guarded = []; + public string $status; + public string $issue_type; protected $table = 'aissue_issues'; @@ -42,12 +44,11 @@ public function makeTransition($status): AIssue } /** - * @param AIssue $issue + * @param AIssue $issue * @return array */ public function getTransitionableStatuses(AIssue $issue): array { return \AuroraWebSoftware\AIssue\Facades\AIssue::getTransitionableStatuses($this); } - } diff --git a/src/Traits/AIssueModelTrait.php b/src/Traits/AIssueModelTrait.php index 7e0c354..8508241 100644 --- a/src/Traits/AIssueModelTrait.php +++ b/src/Traits/AIssueModelTrait.php @@ -2,32 +2,30 @@ namespace AuroraWebSoftware\AIssue\Traits; - use AuroraWebSoftware\AIssue\Facades\AIssue; use Illuminate\Support\Carbon; trait AIssueModelTrait { /** - * @param int $assigneeId - * @param int $createrId - * @param string $issueType - * @param string $summary - * @param string $description - * @param int $priority - * @param Carbon $duedate + * @param int $assigneeId + * @param int $createrId + * @param string $issueType + * @param string $summary + * @param string $description + * @param int $priority + * @param Carbon $duedate * @return \AuroraWebSoftware\AIssue\Models\AIssue */ public function createIssue( - int $assigneeId, - int $createrId, + int $assigneeId, + int $createrId, string $issueType, string $summary, string $description, - int $priority, + int $priority, Carbon $duedate, - ): \AuroraWebSoftware\AIssue\Models\AIssue - { + ): \AuroraWebSoftware\AIssue\Models\AIssue { $data = [ 'model_type' => static::getAIssueModelType(), 'model_id' => $this->getAIssueModelId(), diff --git a/tests/Models/Issueable.php b/tests/Models/Issueable.php index 923e77b..eb747f5 100644 --- a/tests/Models/Issueable.php +++ b/tests/Models/Issueable.php @@ -16,7 +16,7 @@ class Issueable extends Model implements AIssueModelContract protected $fillable = ['name']; /** - * @param string $issueType + * @param string $issueType * @return string */ public static function getAIssueDefaultStatus(string $issueType): string diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index 61211ae..31eb8a6 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -13,7 +13,6 @@ $table->string('name'); $table->timestamps(); }); - }); test('can read aissue config', function () { @@ -35,7 +34,6 @@ }); test('can create aissue', function () { - $createdModel = Issueable::create( ['name' => 'test isuable model 1'] ); @@ -43,10 +41,9 @@ $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 1', 'asdasd', 1, \Illuminate\Support\Carbon::now()); $this->assertEquals( - \AuroraWebSoftware\AIssue\Models\AIssue::where('id', '=', $createdIssueModel->id )->first()->summary, + \AuroraWebSoftware\AIssue\Models\AIssue::where('id', '=', $createdIssueModel->id)->first()->summary, $createdIssueModel->summary ); - }); test('can make transition', function () { @@ -61,8 +58,5 @@ // $this->assertTrue($transition->status == 'todo'); }); - test('x', function () { - - }); From 767db11c2b147ae813b29ba5743635d02e70e6d8 Mon Sep 17 00:00:00 2001 From: emreakay Date: Wed, 14 Sep 2022 14:58:30 +0300 Subject: [PATCH 30/31] - traits fixed - phpunit and pest fixed --- README-contr.md | 9 +++ database/migrations/create_aissue_tables.php | 4 +- phpstan.neon.dist | 2 +- src/AIssue.php | 14 ++--- src/AIssueServiceProvider.php | 5 +- src/Contracts/AIssueModelContract.php | 2 +- src/Models/AIssue.php | 17 ++--- src/Traits/AIssueModelTrait.php | 28 +++++---- tests/Models/Issueable.php | 2 +- tests/Unit/AIssueTest.php | 65 +++++++++++++++++--- 10 files changed, 105 insertions(+), 43 deletions(-) diff --git a/README-contr.md b/README-contr.md index 258cd57..349508a 100644 --- a/README-contr.md +++ b/README-contr.md @@ -1 +1,10 @@ todo + + + +```shell +composer analyse +composer test +composer test-coverage +composer format +``` diff --git a/database/migrations/create_aissue_tables.php b/database/migrations/create_aissue_tables.php index 06ebcae..7332285 100644 --- a/database/migrations/create_aissue_tables.php +++ b/database/migrations/create_aissue_tables.php @@ -6,7 +6,7 @@ return new class extends Migration { - public function up() + public function up(): void { Schema::create('aissue_issues', function (Blueprint $table) { $table->bigIncrements('id'); @@ -27,7 +27,7 @@ public function up() }); } - public function down() + public function down(): void { Schema::dropIfExists('aissue_issues'); } diff --git a/phpstan.neon.dist b/phpstan.neon.dist index a91953b..32a2dd0 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,7 +2,7 @@ includes: - phpstan-baseline.neon parameters: - level: 4 + level: 8 paths: - src - config diff --git a/src/AIssue.php b/src/AIssue.php index b336e09..4abcd38 100755 --- a/src/AIssue.php +++ b/src/AIssue.php @@ -7,22 +7,22 @@ class AIssue { /** - * @param $data + * @param array $data * @return Models\AIssue */ - public function createIssue($data): Models\AIssue + public function createIssue(array $data): Models\AIssue { return Models\AIssue::create($data); } /** * @param Models\AIssue $issue - * @param $status + * @param string $status * @return bool */ - public function canMakeTransition(Models\AIssue $issue, $status): bool + public function canMakeTransition(Models\AIssue $issue, string $status): bool { - $permission = config('aissue')['issueTypes']['task'][$status]['permission']; + $permission = config('aissue')['issueTypes'][$issue->getIssueType()][$status]['permission']; if (config('aissue')['policyMethod']($permission)) { return true; } @@ -32,12 +32,12 @@ public function canMakeTransition(Models\AIssue $issue, $status): bool /** * @param Models\AIssue $issue - * @param $status + * @param string $status * @return Models\AIssue * * @throws TransitionPermissionException */ - public function makeTransition(Models\AIssue $issue, $status): Models\AIssue + public function makeTransition(Models\AIssue $issue, string $status): Models\AIssue { if ($this->canMakeTransition($issue, $status)) { $issue->status = $status; diff --git a/src/AIssueServiceProvider.php b/src/AIssueServiceProvider.php index 95e5a7e..7694069 100644 --- a/src/AIssueServiceProvider.php +++ b/src/AIssueServiceProvider.php @@ -23,15 +23,14 @@ public function configurePackage(Package $package): void // ->hasCommand(AIssueCommand::class); } - public function boot() + public function boot(): void { parent::boot(); // load packages migrations $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); - $this->publishes([ - __DIR__ . '/../config' => config_path(), + __DIR__.'/../config' => config_path(), ], 'aissue-config'); } } diff --git a/src/Contracts/AIssueModelContract.php b/src/Contracts/AIssueModelContract.php index c05a085..0f0db58 100644 --- a/src/Contracts/AIssueModelContract.php +++ b/src/Contracts/AIssueModelContract.php @@ -8,7 +8,7 @@ interface AIssueModelContract { /** - * @param string $issueType + * @param string $issueType * @return string */ public static function getAIssueDefaultStatus(string $issueType): string; diff --git a/src/Models/AIssue.php b/src/Models/AIssue.php index 92f6113..7ddf060 100644 --- a/src/Models/AIssue.php +++ b/src/Models/AIssue.php @@ -5,13 +5,15 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +/** + * @property-read string $status + * @property-read string $issue_type + */ class AIssue extends Model { use HasFactory; public $guarded = []; - public string $status; - public string $issue_type; protected $table = 'aissue_issues'; @@ -24,30 +26,29 @@ public function getIssueType(): string } /** - * @param $status + * @param string $status * @return bool */ - public function canMakeTransition($status): bool + public function canMakeTransition(string $status): bool { return \AuroraWebSoftware\AIssue\Facades\AIssue::canMakeTransition($this, $status); } /** - * @param $status + * @param string $status * @return AIssue */ - public function makeTransition($status): AIssue + public function makeTransition(string $status): AIssue { return \AuroraWebSoftware\AIssue\Facades\AIssue::makeTransition($this, $status); } /** - * @param AIssue $issue + * @param AIssue $issue * @return array */ public function getTransitionableStatuses(AIssue $issue): array { return \AuroraWebSoftware\AIssue\Facades\AIssue::getTransitionableStatuses($this); } - } diff --git a/src/Traits/AIssueModelTrait.php b/src/Traits/AIssueModelTrait.php index 7e0c354..aa6c824 100644 --- a/src/Traits/AIssueModelTrait.php +++ b/src/Traits/AIssueModelTrait.php @@ -2,32 +2,34 @@ namespace AuroraWebSoftware\AIssue\Traits; - use AuroraWebSoftware\AIssue\Facades\AIssue; use Illuminate\Support\Carbon; trait AIssueModelTrait { /** - * @param int $assigneeId - * @param int $createrId - * @param string $issueType - * @param string $summary - * @param string $description - * @param int $priority - * @param Carbon $duedate + * @param int $assigneeId + * @param int $createrId + * @param string $issueType + * @param string $summary + * @param string $description + * @param int $priority + * @param Carbon $duedate * @return \AuroraWebSoftware\AIssue\Models\AIssue */ public function createIssue( - int $assigneeId, - int $createrId, + int $assigneeId, + int $createrId, string $issueType, string $summary, string $description, - int $priority, + int $priority, Carbon $duedate, - ): \AuroraWebSoftware\AIssue\Models\AIssue - { + ): \AuroraWebSoftware\AIssue\Models\AIssue { + + // todo issueType Kontrolü + // todo status yetki kontrolü + $data = [ 'model_type' => static::getAIssueModelType(), 'model_id' => $this->getAIssueModelId(), diff --git a/tests/Models/Issueable.php b/tests/Models/Issueable.php index 923e77b..eb747f5 100644 --- a/tests/Models/Issueable.php +++ b/tests/Models/Issueable.php @@ -16,7 +16,7 @@ class Issueable extends Model implements AIssueModelContract protected $fillable = ['name']; /** - * @param string $issueType + * @param string $issueType * @return string */ public static function getAIssueDefaultStatus(string $issueType): string diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index 61211ae..27d0cdc 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -1,8 +1,10 @@ timestamps(); }); + + $mockPolicyFunction = function ($permission): bool { + if ($permission == 'todo_perm' || $permission == 'in_progress_perm') { + return true; + } + return false; + }; + + Config::set('aissue.policyMethod', $mockPolicyFunction); + }); test('can read aissue config', function () { @@ -34,22 +46,64 @@ expect(1)->toBeTruthy(); }); -test('can create aissue', function () { - +test('can create aissue for a model', function () { $createdModel = Issueable::create( ['name' => 'test isuable model 1'] ); - $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 1', 'asdasd', 1, \Illuminate\Support\Carbon::now()); + $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 1.1', 'asdasd', 1, \Illuminate\Support\Carbon::now()); $this->assertEquals( - \AuroraWebSoftware\AIssue\Models\AIssue::where('id', '=', $createdIssueModel->id )->first()->summary, + AIssue::where('id', '=', $createdIssueModel->id)->first()->summary, $createdIssueModel->summary ); +}); + + +test('can check make transition for todo', function () { + + $createdModel = Issueable::create( + ['name' => 'test isuable model 2'] + ); + + /** @var AIssue $createdIssueModel */ + $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 2.1', 'asdasd', 1, \Illuminate\Support\Carbon::now()); + + $this->assertTrue($createdIssueModel->canMakeTransition('todo')); +}); + +test('can check make transition for in_progress', function () { + + $createdModel = Issueable::create( + ['name' => 'test isuable model 3'] + ); + /** @var AIssue $createdIssueModel */ + $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 2.1', 'asdasd', 1, \Illuminate\Support\Carbon::now()); + + $this->assertTrue($createdIssueModel->canMakeTransition('in_progress')); +}); + +test('can check make transition for done', function () { + + $createdModel = Issueable::create( + ['name' => 'test isuable model 4'] + ); + + /** @var AIssue $createdIssueModel */ + $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 2.1', 'asdasd', 1, \Illuminate\Support\Carbon::now()); + + $this->assertFalse($createdIssueModel->canMakeTransition('done')); }); test('can make transition', function () { + + $createdModel = Issueable::create( + ['name' => 'test isuable model 1'] + ); + + $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 1', 'asdasd', 1, \Illuminate\Support\Carbon::now()); + $createdAissue = $this->aissue->createIssue($this->data); $transition = $this->aissue->makeTransition($createdAissue, 'todo'); $this->assertTrue($transition->status == 'todo'); @@ -61,8 +115,5 @@ // $this->assertTrue($transition->status == 'todo'); }); - test('x', function () { - - }); From c5835e5b4dd0247374daf8909b4e1ce4b83c5a2d Mon Sep 17 00:00:00 2001 From: emreakay Date: Wed, 14 Sep 2022 15:06:40 +0300 Subject: [PATCH 31/31] - traits fixed - phpunit and pest fixed --- src/Models/AIssue.php | 2 +- src/Traits/AIssueModelTrait.php | 1 - tests/Unit/AIssueTest.php | 33 +++------------------------------ 3 files changed, 4 insertions(+), 32 deletions(-) diff --git a/src/Models/AIssue.php b/src/Models/AIssue.php index 7ddf060..d3e535a 100644 --- a/src/Models/AIssue.php +++ b/src/Models/AIssue.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model; /** - * @property-read string $status + * @property string $status * @property-read string $issue_type */ class AIssue extends Model diff --git a/src/Traits/AIssueModelTrait.php b/src/Traits/AIssueModelTrait.php index aa6c824..6c936f9 100644 --- a/src/Traits/AIssueModelTrait.php +++ b/src/Traits/AIssueModelTrait.php @@ -26,7 +26,6 @@ public function createIssue( int $priority, Carbon $duedate, ): \AuroraWebSoftware\AIssue\Models\AIssue { - // todo issueType Kontrolü // todo status yetki kontrolü diff --git a/tests/Unit/AIssueTest.php b/tests/Unit/AIssueTest.php index 27d0cdc..e28469e 100644 --- a/tests/Unit/AIssueTest.php +++ b/tests/Unit/AIssueTest.php @@ -16,16 +16,15 @@ $table->timestamps(); }); - $mockPolicyFunction = function ($permission): bool { if ($permission == 'todo_perm' || $permission == 'in_progress_perm') { return true; } + return false; }; Config::set('aissue.policyMethod', $mockPolicyFunction); - }); test('can read aissue config', function () { @@ -36,8 +35,8 @@ $this->assertTrue(config('aissue')['policyMethod'] instanceof \Closure); }); -test('can access policy method works', function () { - $this->assertTrue(config('aissue')['policyMethod']('test permission')); +test('can access policy method works for todo', function () { + $this->assertTrue(config('aissue')['policyMethod']('todo_perm')); }); test('can get one specified issue', function () { @@ -59,9 +58,7 @@ ); }); - test('can check make transition for todo', function () { - $createdModel = Issueable::create( ['name' => 'test isuable model 2'] ); @@ -73,7 +70,6 @@ }); test('can check make transition for in_progress', function () { - $createdModel = Issueable::create( ['name' => 'test isuable model 3'] ); @@ -85,7 +81,6 @@ }); test('can check make transition for done', function () { - $createdModel = Issueable::create( ['name' => 'test isuable model 4'] ); @@ -95,25 +90,3 @@ $this->assertFalse($createdIssueModel->canMakeTransition('done')); }); - -test('can make transition', function () { - - $createdModel = Issueable::create( - ['name' => 'test isuable model 1'] - ); - - $createdIssueModel = $createdModel->createIssue(1, 1, 'task', 'test isssue 1', 'asdasd', 1, \Illuminate\Support\Carbon::now()); - - $createdAissue = $this->aissue->createIssue($this->data); - $transition = $this->aissue->makeTransition($createdAissue, 'todo'); - $this->assertTrue($transition->status == 'todo'); -}); - -test('can get transitionable statuses', function () { - $createdAissue = $this->aissue->createIssue($this->data); - $transitionableStatuses = $this->aissue->getTransitionableStatuses($createdAissue); - // $this->assertTrue($transition->status == 'todo'); -}); - -test('x', function () { -});