Skip to content

Commit

Permalink
- v2
Browse files Browse the repository at this point in the history
  • Loading branch information
emreakay committed Mar 18, 2024
1 parent 55cdac5 commit c144d99
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/Models/AIssue.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function setReporter(IssueActorModelContract $issueActorModel): void
{
if ($this->connections('issue_reporter')) {
$this->connections('issue_reporter')
->each(fn (Model $connection) => $connection->delete());
->each(fn(Model $connection) => $connection->delete());
}

$this->connectTo($issueActorModel, 'issue_reporter');

Check failure on line 101 in src/Models/AIssue.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $model of method AuroraWebSoftware\AIssue\Models\AIssue::connectTo() expects AuroraWebSoftware\Connective\Contracts\ConnectiveContract&Illuminate\Database\Eloquent\Model, AuroraWebSoftware\AIssue\Contracts\IssueActorModelContract given.
Expand All @@ -105,7 +105,7 @@ public function removeReporter(): void
{
if ($this->connections('issue_reporter')) {
$this->connections('issue_reporter')
->each(fn (Model $connection) => $connection->delete());
->each(fn(Model $connection) => $connection->delete());
}
}

Expand All @@ -122,7 +122,7 @@ public function setResponsible(IssueActorModelContract $issueActorModel): void
{
if ($this->connections('issue_responsible')) {
$this->connections('issue_responsible')
->each(fn (Model $connection) => $connection->delete());
->each(fn(Model $connection) => $connection->delete());
}

$this->connectTo($issueActorModel, 'issue_responsible');

Check failure on line 128 in src/Models/AIssue.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $model of method AuroraWebSoftware\AIssue\Models\AIssue::connectTo() expects AuroraWebSoftware\Connective\Contracts\ConnectiveContract&Illuminate\Database\Eloquent\Model, AuroraWebSoftware\AIssue\Contracts\IssueActorModelContract given.
Expand All @@ -132,7 +132,7 @@ public function removeResponsible(): void
{
if ($this->connections('issue_responsible')) {
$this->connections('issue_responsible')
->each(fn (Model $connection) => $connection->delete());
->each(fn(Model $connection) => $connection->delete());
}
}

Expand Down Expand Up @@ -174,7 +174,7 @@ public function removeObserver(IssueActorModelContract $issueActorModel): void
}
}

public function removeAllObservers(IssueActorModelContract $issueActorModel): void
public function removeAllObservers(): void
{
foreach ($this->getObservers() as $observer) {
$observer->delete();
Expand Down
93 changes: 91 additions & 2 deletions tests/Unit/AIssueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,94 @@
->toHaveCount(2);
});

// todo state değişimleri
// remove'lar
it('can create an issue and make transition and add or remove actors and due date', function () {

/**
* @var User&ConnectiveContract $user1
*/
$user1 = User::create(['name' => 'user 1']);
$user2 = User::create(['name' => 'user 2']);
$user3 = User::create(['name' => 'user 3']);
$user4 = User::create(['name' => 'user 4']);

$data = ['summary' => 'summary', 'description' => 'descr'];

/**
* @var AIssue $issue
*/
$issue = AIssue::create($data);
$issue->applyWorkflow('simple');

$issue->setReporter($user1);

expect()
->and($user1->getActingIssues('issue_reporter'))
->toHaveCount(1)
->and($issue->getReporter()?->getId())
->toBe($user1->getId());

$issue->removeReporter();

expect()
->and($user1->getActingIssues('issue_reporter'))
->toHaveCount(0);

$issue->setResponsible($user2);

expect()
->and($user2->getActingIssues('issue_responsible'))
->toHaveCount(1)
->and($issue->getResponsible()?->getId())
->toBe($user2->getId());

$issue->removeResponsible();

expect()
->and($user2->getActingIssues('issue_responsible'))
->toHaveCount(0);

$issue->addObserver($user3);
$issue->addObserver($user4);

expect()
->and($issue->getObservers())
->toHaveCount(2);

$issue->removeObserver($user3);

expect()
->and($issue->getObservers())
->toHaveCount(1);

$issue->removeObserver($user4);

expect()
->and($issue->getObservers())
->toHaveCount(0);

$issue->addObserver($user3);
$issue->addObserver($user4);

$issue->removeAllObservers();

expect()
->and($issue->getObservers())
->toHaveCount(0);

$issue->setDueDate(Carbon::today());

expect()
->and($issue->getDueDate()?->format('Y-m-d'))
->toEqual(Carbon::today()->format('Y-m-d'));

$issue->removeDueDate();

expect()
->and($issue->getDueDate())
->toBeNull();

$issue->transitionTo(toState: 'state2', logHistoryTransitionAction: false);

expect($issue->currentState())->toEqual('state2');

});

0 comments on commit c144d99

Please sign in to comment.