From 8a902c61493b1be59d7daba9d694905ed4cb6475 Mon Sep 17 00:00:00 2001 From: David Callizaya Date: Fri, 22 Nov 2024 17:09:51 -0400 Subject: [PATCH 1/2] Add method to create Process instance from JSON file --- tests/TestCase.php | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 1ffdfd9633..7532d59031 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,18 +3,15 @@ namespace Tests; use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts; -use Illuminate\Database\DatabaseManager; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Bus; use PDOException; +use ProcessMaker\ImportExport\Importer; +use ProcessMaker\ImportExport\Options; use ProcessMaker\Jobs\RefreshArtisanCaches; use ProcessMaker\Models\Process; -use ProcessMaker\Models\ProcessRequest; -use ProcessMaker\Models\ProcessRequestLock; -use ProcessMaker\Models\SecurityLog; -use ProcessMaker\Models\Setting; abstract class TestCase extends BaseTestCase { @@ -127,6 +124,30 @@ protected function createProcessFromBPMN(string $bpmnFile, array $attributes = [ return Process::factory()->create(array_merge($data, $attributes)); } + /** + * Creates a Process instance from a JSON file. + * + * This method reads the specified JSON file, merges the provided attributes, + * and creates a new Process instance. + * + * @param string $jsonFile The path to the JSON file containing the process definition. + * @param array $attributes Additional attributes to merge into the process definition. + * @return Process The created Process instance. + */ + protected function createProcessFromJSON(string $jsonFile, array $attributes = []): Process + { + $payload = json_decode(file_get_contents($jsonFile), true); + $options = new Options([]); + $importer = new Importer($payload, $options); + $importer->previewImport(); + $manifest = $importer->doImport(); + $processId = $manifest[$payload['root']]->log['newId']; + $process = Process::find($processId); + $process->update($attributes); + + return $process; + } + /** * Connections transacts * From 389b1c34b384d45459e1dc164cc9b533f00e0462 Mon Sep 17 00:00:00 2001 From: David Callizaya Date: Fri, 22 Nov 2024 17:10:45 -0400 Subject: [PATCH 2/2] Improve modifying exception messages in RunServiceTask --- ProcessMaker/Jobs/RunServiceTask.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ProcessMaker/Jobs/RunServiceTask.php b/ProcessMaker/Jobs/RunServiceTask.php index e9a6fcad57..76ce0c9746 100644 --- a/ProcessMaker/Jobs/RunServiceTask.php +++ b/ProcessMaker/Jobs/RunServiceTask.php @@ -2,6 +2,7 @@ namespace ProcessMaker\Jobs; +use Exception; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Support\Facades\Log; use ProcessMaker\Exception\ConfigurationException; @@ -127,8 +128,11 @@ public function action(ProcessRequestToken $token = null, ServiceTaskInterface $ $error->setName($message); $token->setProperty('error', $error); - $exceptionClass = get_class($exception); - $modifiedException = new $exceptionClass($message); + if ($message !== $exception->getMessage()) { + $modifiedException = new Exception($message, $exception->getCode(), $exception); + } else { + $modifiedException = $exception; + } $token->logError($modifiedException, $element); Log::error('Service task failed: ' . $implementation . ' - ' . $message);