diff --git a/ProcessMaker/Console/Commands/CasesSync.php b/ProcessMaker/Console/Commands/CasesSync.php new file mode 100644 index 0000000000..e23d9ce0d4 --- /dev/null +++ b/ProcessMaker/Console/Commands/CasesSync.php @@ -0,0 +1,47 @@ +option('request_ids'); + $requestIds = $requestIds ? explode(',', $requestIds) : []; + + if (count($requestIds) > 0) { + $data = CaseSyncRepository::syncCases($requestIds); + + foreach ($data['successes'] as $value) { + $this->info('Case started synced ' . $value); + } + + foreach ($data['errors'] as $value) { + $this->error('Error syncing case started ' . $value); + } + } else { + $this->error('Please specify a list of request IDs.'); + } + } +} diff --git a/ProcessMaker/Repositories/CaseParticipatedRepository.php b/ProcessMaker/Repositories/CaseParticipatedRepository.php index 1a22abebe2..39fab26e2a 100644 --- a/ProcessMaker/Repositories/CaseParticipatedRepository.php +++ b/ProcessMaker/Repositories/CaseParticipatedRepository.php @@ -2,6 +2,7 @@ namespace ProcessMaker\Repositories; +use Illuminate\Support\Facades\Log; use ProcessMaker\Models\CaseParticipated; use ProcessMaker\Models\CaseStarted; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; @@ -44,7 +45,8 @@ public function create(CaseStarted $case, TokenInterface $token): void 'completed_at' => null, ]); } catch (\Exception $e) { - \Log::error($e->getMessage()); + Log::error('CaseException: ' . $e->getMessage()); + Log::error('CaseException: ' . $e->getTraceAsString()); } } @@ -73,7 +75,8 @@ public function update(CaseStarted $case, TokenInterface $token) 'participants' => $case->participants, ]); } catch (\Exception $e) { - \Log::error($e->getMessage()); + Log::error('CaseException: ' . $e->getMessage()); + Log::error('CaseException: ' . $e->getTraceAsString()); } } @@ -90,7 +93,8 @@ public function updateStatus(int $caseNumber, array $statusData) CaseParticipated::where('case_number', $caseNumber) ->update($statusData); } catch (\Exception $e) { - \Log::error($e->getMessage()); + Log::error('CaseException: ' . $e->getMessage()); + Log::error('CaseException: ' . $e->getTraceAsString()); } } diff --git a/ProcessMaker/Repositories/CaseRepository.php b/ProcessMaker/Repositories/CaseRepository.php index 7ef6ca49ec..f1b72d3b8d 100644 --- a/ProcessMaker/Repositories/CaseRepository.php +++ b/ProcessMaker/Repositories/CaseRepository.php @@ -3,6 +3,7 @@ namespace ProcessMaker\Repositories; use Carbon\Carbon; +use Illuminate\Support\Facades\Log; use ProcessMaker\Contracts\CaseRepositoryInterface; use ProcessMaker\Models\CaseStarted; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; @@ -12,6 +13,10 @@ class CaseRepository implements CaseRepositoryInterface { const CASE_STATUS_ACTIVE = 'ACTIVE'; + /** + * @var CaseParticipatedRepository + */ + protected CaseParticipatedRepository $caseParticipatedRepository; /** * This property is used to store an instance of `CaseStarted` * when a case started is updated. @@ -19,8 +24,9 @@ class CaseRepository implements CaseRepositoryInterface */ protected ?CaseStarted $case; - public function __construct(protected CaseParticipatedRepository $caseParticipatedRepository) + public function __construct() { + $this->caseParticipatedRepository = new CaseParticipatedRepository(); } /** * Store a new case started. @@ -31,8 +37,7 @@ public function __construct(protected CaseParticipatedRepository $caseParticipat public function create(ExecutionInstanceInterface $instance): void { if (is_null($instance->case_number)) { - \Log::error('Case number is required. instance: ' . $instance->getKey()); - + Log::error('case number is required, method=create, instance=' . $instance->getKey()); return; } @@ -58,8 +63,8 @@ public function create(ExecutionInstanceInterface $instance): void 'completed_at' => null, ]); } catch (\Exception $e) { - \Log::error($e->getMessage()); - \Log::error($e->getTraceAsString()); + Log::error('CaseException: ' . $e->getMessage()); + Log::error('CaseException: ' . $e->getTraceAsString()); } } @@ -72,19 +77,12 @@ public function create(ExecutionInstanceInterface $instance): void */ public function update(ExecutionInstanceInterface $instance, TokenInterface $token): void { - if (is_null($instance->case_number)) { - \Log::error('Case number is required. instance: ' . $instance->getKey()); - + if (!$this->checkIfCaseStartedExist($instance->case_number)) { + Log::error('case started not found, method=update, instance=' . $instance->getKey()); return; } try { - if (!$this->checkIfCaseStartedExist($instance->case_number)) { - \Log::error('Case number not found. instance: ' . $instance->id); - - return; - } - $this->case->case_title = $instance->case_title; $this->case->case_status = $instance->status === self::CASE_STATUS_ACTIVE ? 'IN_PROGRESS' : $instance->status; $this->case->request_tokens = CaseUtils::storeRequestTokens($token->getKey(), $this->case->request_tokens); @@ -94,7 +92,8 @@ public function update(ExecutionInstanceInterface $instance, TokenInterface $tok $this->case->saveOrFail(); } catch (\Exception $e) { - \Log::error($e->getMessage()); + Log::error('CaseException: ' . $e->getMessage()); + Log::error('CaseException: ' . $e->getTraceAsString()); } } @@ -124,7 +123,8 @@ public function updateStatus(ExecutionInstanceInterface $instance): void CaseStarted::where('case_number', $instance->case_number)->update($data); $this->caseParticipatedRepository->updateStatus($instance->case_number, $data); } catch (\Exception $e) { - \Log::error($e->getMessage()); + Log::error('CaseException: ' . $e->getMessage()); + Log::error('CaseException: ' . $e->getTraceAsString()); } } @@ -163,11 +163,15 @@ private function updateParticipants(TokenInterface $token): void /** * Check if the case started exist. * - * @param int $caseNumber + * @param int|null $caseNumber * @return bool */ - private function checkIfCaseStartedExist(int $caseNumber): bool + private function checkIfCaseStartedExist(int | null $caseNumber): bool { + if (is_null($caseNumber)) { + return false; + } + $this->case = CaseStarted::where('case_number', $caseNumber)->first(); return !is_null($this->case); @@ -191,8 +195,9 @@ private function updateSubProcesses(ExecutionInstanceInterface $instance): void $this->case->requests = CaseUtils::storeRequests($instance, $this->case->requests); $this->case->saveOrFail(); - } catch (\Exception $th) { - \Log::error($th->getMessage()); + } catch (\Exception $e) { + Log::error('CaseException: ' . $e->getMessage()); + Log::error('CaseException: ' . $e->getTraceAsString()); } } } diff --git a/ProcessMaker/Repositories/CaseSyncRepository.php b/ProcessMaker/Repositories/CaseSyncRepository.php new file mode 100644 index 0000000000..64ac329e20 --- /dev/null +++ b/ProcessMaker/Repositories/CaseSyncRepository.php @@ -0,0 +1,190 @@ +whereIn('id', $requestIds) + ->get(); + + $successes = []; + $errors = []; + + foreach ($requests as $instance) { + try { + if (!is_null($instance->parent_request_id)) { + continue; + } + + $csProcesses = CaseUtils::storeProcesses($instance, collect()); + $csRequests = CaseUtils::storeRequests($instance, collect()); + $csRequestTokens = collect(); + $csTasks = collect(); + $participants = $instance->participants->map->only('id', 'fullName', 'title', 'avatar'); + $status = $instance->status === CaseRepository::CASE_STATUS_ACTIVE ? 'IN_PROGRESS' : $instance->status; + + $cpData = self::prepareCaseStartedData($instance, $status, $participants); + + self::processTokens($instance, $cpData, $csRequestTokens, $csTasks); + + self::processChildRequests($instance, $cpData, $csProcesses, $csRequests, $participants, $csRequestTokens, $csTasks); + + $caseStarted = CaseStarted::updateOrCreate( + ['case_number' => $instance->case_number], + [ + 'user_id' => $instance->user_id, + 'case_title' => $instance->case_title, + 'case_title_formatted' => $instance->case_title_formatted, + 'case_status' => $status, + 'processes' => $csProcesses, + 'requests' => $csRequests, + 'request_tokens' => $csRequestTokens, + 'tasks' => $csTasks, + 'participants' => $participants, + 'initiated_at' => $instance->initiated_at, + 'completed_at' => $instance->completed_at, + ], + ); + + $successes[] = $caseStarted->case_number; + } catch (\Exception $e) { + $errors[] = $instance->case_number . ' ' . $e->getMessage(); + } + } + + return [ + 'successes' => $successes, + 'errors' => $errors, + ]; + } + + /** + * Prepare the case started data. + * + * @param ProcessRequest $instance + * @param string $status + * @param Collection $participants + * @return array + */ + private static function prepareCaseStartedData($instance, $status, $participants) + { + return [ + 'case_title' => $instance->case_title, + 'case_title_formatted' => $instance->case_title_formatted, + 'case_status' => $status, + 'processes' => CaseUtils::storeProcesses($instance, collect()), + 'requests' => CaseUtils::storeRequests($instance, collect()), + 'request_tokens' => collect(), + 'tasks' => collect(), + 'participants' => $participants, + 'initiated_at' => $instance->initiated_at, + 'completed_at' => $instance->completed_at, + ]; + } + + /** + * Process the tokens. + * + * @param ProcessRequest $instance + * @param array $cpData + * @param Collection $csRequestTokens + * @param Collection $csTasks + * @return void + */ + private static function processTokens($instance, &$cpData, &$csRequestTokens, &$csTasks) + { + foreach ($instance->tokens as $token) { + if (in_array($token->element_type, CaseUtils::ALLOWED_REQUEST_TOKENS)) { + $cpData['processes'] = CaseUtils::storeProcesses($instance, $cpData['processes']); + $cpData['requests'] = CaseUtils::storeRequests($instance, $cpData['requests']); + $cpData['request_tokens'] = CaseUtils::storeRequestTokens($token->getKey(), $cpData['request_tokens']); + $cpData['tasks'] = CaseUtils::storeTasks($token, $cpData['tasks']); + + $csRequestTokens = CaseUtils::storeRequestTokens($token->getKey(), $csRequestTokens); + $csTasks = CaseUtils::storeTasks($token, $csTasks); + + self::syncCasesParticipated($instance->case_number, $token->user_id, $cpData); + } + } + } + + /** + * Process the child requests. + * + * @param ProcessRequest $instance + * @param array $cpData + * @param Collection $csProcesses + * @param Collection $csRequests + * @param Collection $participants + * @param Collection $csRequestTokens + * @param Collection $csTasks + * @return void + */ + private static function processChildRequests( + $instance, &$cpData, &$csProcesses, &$csRequests, &$participants, &$csRequestTokens, &$csTasks + ) + { + foreach ($instance->childRequests as $subProcess) { + $cpData['processes'] = CaseUtils::storeProcesses($subProcess, collect()); + $cpData['requests'] = CaseUtils::storeRequests($subProcess, collect()); + $cpData['request_tokens'] = collect(); + $cpData['tasks'] = collect(); + + $csProcesses = CaseUtils::storeProcesses($subProcess, $csProcesses); + $csRequests = CaseUtils::storeRequests($subProcess, $csRequests); + + $participants = $participants + ->merge($subProcess->participants->map->only('id', 'fullName', 'title', 'avatar')) + ->unique('id') + ->values(); + + foreach ($subProcess->tokens as $spToken) { + if (in_array($spToken->element_type, CaseUtils::ALLOWED_REQUEST_TOKENS)) { + $cpData['processes'] = CaseUtils::storeProcesses($subProcess, $cpData['processes']); + $cpData['requests'] = CaseUtils::storeRequests($subProcess, $cpData['requests']); + $cpData['request_tokens'] = CaseUtils::storeRequestTokens($spToken->getKey(), $cpData['request_tokens']); + $cpData['tasks'] = CaseUtils::storeTasks($spToken, $cpData['tasks']); + + $csRequestTokens = CaseUtils::storeRequestTokens($spToken->getKey(), $csRequestTokens); + $csTasks = CaseUtils::storeTasks($spToken, $csTasks); + + self::syncCasesParticipated($instance->case_number, $spToken->user_id, $cpData); + } + } + } + } + + /** + * Sync the cases participated. + * + * @param CaseStarted $caseStarted + * @param TokenInterface $token + * @return void + */ + private static function syncCasesParticipated($caseNumber, $userId, $data) + { + CaseParticipated::updateOrCreate( + [ + 'case_number' => $caseNumber, + 'user_id' => $userId, + ], + $data, + ); + } +} diff --git a/ProcessMaker/Repositories/CaseUtils.php b/ProcessMaker/Repositories/CaseUtils.php index 2d93e1d098..527de49434 100644 --- a/ProcessMaker/Repositories/CaseUtils.php +++ b/ProcessMaker/Repositories/CaseUtils.php @@ -10,6 +10,8 @@ class CaseUtils { const ALLOWED_ELEMENT_TYPES = ['task']; + const ALLOWED_REQUEST_TOKENS = ['task', 'scriptTask', 'callActivity']; + /** * Store processes. * diff --git a/tests/Feature/Cases/CaseExceptionTest.php b/tests/Feature/Cases/CaseExceptionTest.php new file mode 100644 index 0000000000..5bf3317dd4 --- /dev/null +++ b/tests/Feature/Cases/CaseExceptionTest.php @@ -0,0 +1,134 @@ +user = User::factory()->create(); + $this->process = Process::factory()->create(); + + $this->instance = ProcessRequest::factory()->create([ + 'user_id' => $this->user->id, + 'process_id' => $this->process->id, + ]); + $this->token = ProcessRequestToken::factory()->create([ + 'user_id' => $this->user->id, + 'process_request_id' => $this->instance->id, + 'element_type' => 'task', + ]); + + $this->instance2 = ProcessRequest::factory()->create([ + 'user_id' => $this->user->id, + 'process_id' => $this->process->id, + ]); + $this->token2 = ProcessRequestToken::factory()->create([ + 'user_id' => $this->user->id, + 'process_request_id' => $this->instance2->id, + 'element_type' => 'task', + ]); + } + + public function test_create_case_missing_case_number(): void + { + $this->withoutExceptionHandling(); + + $this->instance->case_number = null; + $repo = new CaseRepository(); + $repo->create($this->instance); + + $this->assertDatabaseCount('cases_started', 0); + } + + public function test_create_case_missing_user_id(): void + { + $this->withoutExceptionHandling(); + + try { + $this->instance->user_id = null; + $repo = new CaseRepository(); + $repo->create($this->instance); + } catch (\Exception $e) { + $this->assertStringContainsString('Column \'user_id\' cannot be null', $e->getMessage()); + } + + $this->assertDatabaseCount('cases_started', 0); + } + + public function test_create_case_missing_case_title(): void + { + $this->withoutExceptionHandling(); + + try { + $this->instance->case_title = null; + $repo = new CaseRepository(); + $repo->create($this->instance); + } catch (\Exception $e) { + $this->assertStringContainsString('Column \'case_title\' cannot be null', $e->getMessage()); + } + + $this->assertDatabaseCount('cases_started', 0); + } + + public function test_update_case_missing_case_started(): void + { + $this->withoutExceptionHandling(); + + try { + $this->instance->case_title = null; + $repo = new CaseRepository(); + $repo->create($this->instance); + } catch (\Exception $e) { + $this->assertStringContainsString('Column \'case_title\' cannot be null', $e->getMessage()); + } + + $this->assertDatabaseCount('cases_started', 0); + + try { + $repo->update($this->instance, $this->token); + } catch (\Exception $e) { + $this->assertEquals( + 'case started not found, method=update, instance=' . $this->instance->getKey(), $e->getMessage() + ); + } + } + + public function test_artisan_sync_command_missing_ids(): void + { + $this->artisan('cases:sync') + ->expectsOutput('Please specify a list of request IDs.') + ->assertExitCode(0); + } + + public function test_artisan_sync_command_success(): void + { + $this->artisan('cases:sync --request_ids=' . $this->instance->id . ',' . $this->instance2->id) + ->expectsOutput('Case started synced ' . $this->instance->case_number) + ->expectsOutput('Case started synced ' . $this->instance2->case_number) + ->assertExitCode(0); + + $this->assertDatabaseCount('cases_started', 2); + } +} diff --git a/tests/Feature/Cases/CaseParticipatedTest.php b/tests/Feature/Cases/CaseParticipatedTest.php index a0b6795116..01c3d21c49 100644 --- a/tests/Feature/Cases/CaseParticipatedTest.php +++ b/tests/Feature/Cases/CaseParticipatedTest.php @@ -6,7 +6,6 @@ use ProcessMaker\Models\ProcessRequest; use ProcessMaker\Models\ProcessRequestToken; use ProcessMaker\Models\User; -use ProcessMaker\Repositories\CaseParticipatedRepository; use ProcessMaker\Repositories\CaseRepository; use Tests\TestCase; @@ -21,8 +20,7 @@ public function test_create_case_participated() 'process_id' => $process->id, ]); - $repoParticipant = new CaseParticipatedRepository(); - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($instance); $this->assertDatabaseHas('cases_started', [ @@ -72,8 +70,7 @@ public function test_create_multiple_case_participated() 'process_id' => $process->id, ]); - $repoParticipant = new CaseParticipatedRepository(); - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($instance); $this->assertDatabaseHas('cases_started', [ @@ -144,8 +141,7 @@ public function test_update_case_participated_users() 'process_id' => $process->id, ]); - $repoParticipant = new CaseParticipatedRepository(); - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($instance); $this->assertDatabaseHas('cases_started', [ @@ -211,8 +207,7 @@ public function test_update_case_participated_user_tasks() 'process_id' => $process->id, ]); - $repoParticipant = new CaseParticipatedRepository(); - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($instance); $this->assertDatabaseCount('cases_started', 1); @@ -290,8 +285,7 @@ public function test_update_case_participated_completed() 'process_id' => $process->id, ]); - $repoParticipant = new CaseParticipatedRepository(); - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($instance); $this->assertDatabaseCount('cases_started', 1); diff --git a/tests/Feature/Cases/CaseStartedSubProcessTest.php b/tests/Feature/Cases/CaseStartedSubProcessTest.php index db4204931c..619c0e77f2 100644 --- a/tests/Feature/Cases/CaseStartedSubProcessTest.php +++ b/tests/Feature/Cases/CaseStartedSubProcessTest.php @@ -9,7 +9,6 @@ use ProcessMaker\Models\ProcessRequest; use ProcessMaker\Models\ProcessRequestToken; use ProcessMaker\Models\User; -use ProcessMaker\Repositories\CaseParticipatedRepository; use ProcessMaker\Repositories\CaseRepository; class CaseStartedSubProcessTest extends TestCase @@ -73,12 +72,10 @@ protected function setUp(): void public function test_create_case_sub_process() { - $repoParticipant = Mockery::mock(CaseParticipatedRepository::class); - - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($this->parentRequest); - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($this->childRequest); $this->assertDatabaseCount('cases_started', 1); @@ -92,12 +89,10 @@ public function test_create_case_sub_process() public function test_create_case_processes() { - $repoParticipant = Mockery::mock(CaseParticipatedRepository::class); - - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($this->parentRequest); - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($this->childRequest); $this->assertDatabaseCount('cases_started', 1); @@ -115,12 +110,10 @@ public function test_create_case_processes() public function test_create_case_requests() { - $repoParticipant = Mockery::mock(CaseParticipatedRepository::class); - - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($this->parentRequest); - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($this->childRequest); $this->assertDatabaseCount('cases_started', 1); @@ -140,12 +133,10 @@ public function test_create_case_requests() public function test_create_case_request_tokens() { - $repoParticipant = new CaseParticipatedRepository(); - - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($this->parentRequest); - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($this->childRequest); $repo->update($this->parentRequest, $this->parentToken); $repo->update($this->childRequest, $this->childToken); @@ -163,12 +154,10 @@ public function test_create_case_request_tokens() public function test_create_case_tasks() { - $repoParticipant = new CaseParticipatedRepository(); - - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($this->parentRequest); - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($this->childRequest); $repo->update($this->parentRequest, $this->parentToken); $repo->update($this->childRequest, $this->childToken); @@ -192,9 +181,7 @@ public function test_create_case_tasks() public function test_create_case_participated_processes() { - $repoParticipant = new CaseParticipatedRepository(); - - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($this->parentRequest); $repo->create($this->childRequest); @@ -227,9 +214,7 @@ public function test_create_case_participated_processes() public function test_create_case_participated_requests() { - $repoParticipant = new CaseParticipatedRepository(); - - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($this->parentRequest); $repo->create($this->childRequest); @@ -265,9 +250,7 @@ public function test_create_case_participated_requests() public function test_create_case_participated_request_tokens() { - $repoParticipant = new CaseParticipatedRepository(); - - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($this->parentRequest); $repo->create($this->childRequest); @@ -297,9 +280,7 @@ public function test_create_case_participated_request_tokens() public function test_create_case_participated_tasks() { - $repoParticipant = new CaseParticipatedRepository(); - - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($this->parentRequest); $repo->create($this->childRequest); @@ -342,9 +323,7 @@ public function test_create_case_participated_tasks() public function test_update_case_participated_completed() { - $repoParticipant = new CaseParticipatedRepository(); - - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($this->parentRequest); $repo->create($this->childRequest); diff --git a/tests/Feature/Cases/CaseStartedTest.php b/tests/Feature/Cases/CaseStartedTest.php index 2b597a5bee..d63cea61ee 100644 --- a/tests/Feature/Cases/CaseStartedTest.php +++ b/tests/Feature/Cases/CaseStartedTest.php @@ -9,7 +9,6 @@ use ProcessMaker\Models\ProcessRequest; use ProcessMaker\Models\ProcessRequestToken; use ProcessMaker\Models\User; -use ProcessMaker\Repositories\CaseParticipatedRepository; use ProcessMaker\Repositories\CaseRepository; class CaseStartedTest extends TestCase @@ -19,12 +18,11 @@ class CaseStartedTest extends TestCase public function test_create_case() { $user = User::factory()->create(); - $repoParticipant = Mockery::mock(CaseParticipatedRepository::class); $instance = ProcessRequest::factory()->create([ 'user_id' => $user->id, ]); - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($instance); $this->assertDatabaseCount('cases_started', 1); @@ -39,7 +37,6 @@ public function test_create_case() public function test_create_multiple_cases() { $user = User::factory()->create(); - $repoParticipant = Mockery::mock(CaseParticipatedRepository::class); $instance1 = ProcessRequest::factory()->create([ 'user_id' => $user->id, ]); @@ -47,7 +44,7 @@ public function test_create_multiple_cases() 'user_id' => $user->id, ]); - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($instance1); $repo->create($instance2); @@ -71,14 +68,13 @@ public function test_create_case_started_processes() $process = Process::factory()->create(); $user = User::factory()->create(); - $repoParticipant = Mockery::mock(CaseParticipatedRepository::class); $instance = ProcessRequest::factory()->create([ 'user_id' => $user->id, 'process_id' => $process->id, ]); - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($instance); $this->assertDatabaseCount('cases_started', 1); @@ -97,14 +93,13 @@ public function test_create_case_started_requests() $process = Process::factory()->create(); $user = User::factory()->create(); - $repoParticipant = Mockery::mock(CaseParticipatedRepository::class); $instance = ProcessRequest::factory()->create([ 'user_id' => $user->id, 'process_id' => $process->id, ]); - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($instance); $this->assertDatabaseCount('cases_started', 1); @@ -130,9 +125,8 @@ public function test_update_case_started_request_tokens() 'process_id' => $process->id, ]); - $repoParticipant = new CaseParticipatedRepository(); - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($instance); $this->assertDatabaseCount('cases_started', 1); @@ -170,9 +164,8 @@ public function test_update_case_started_tasks() 'process_id' => $process->id, ]); - $repoParticipant = new CaseParticipatedRepository(); - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($instance); $this->assertDatabaseCount('cases_started', 1); @@ -232,9 +225,8 @@ public function test_update_case_started_script_tasks() 'process_id' => $process->id, ]); - $repoParticipant = new CaseParticipatedRepository(); - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($instance); $this->assertDatabaseCount('cases_started', 1); @@ -293,9 +285,8 @@ public function test_update_case_started_participants() 'process_id' => $process->id, ]); - $repoParticipant = new CaseParticipatedRepository(); - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($instance); $this->assertDatabaseCount('cases_started', 1); @@ -352,9 +343,8 @@ public function test_update_case_started_status() 'process_id' => $process->id, ]); - $repoParticipant = new CaseParticipatedRepository(); - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($instance); $this->assertDatabaseCount('cases_started', 1); @@ -399,12 +389,11 @@ public function test_update_case_started_status() public function test_try_update_if_case_has_not_been_created() { $user = User::factory()->create(); - $repoParticipant = Mockery::mock(CaseParticipatedRepository::class); $instance = ProcessRequest::factory()->create([ 'user_id' => null, ]); - $repo = new CaseRepository($repoParticipant); + $repo = new CaseRepository(); $repo->create($instance); $this->assertDatabaseCount('cases_started', 0);