Merged in bugfix/PMCORE-3985 (pull request #8571)

PMCORE-3985 PHP Unit, solve the issue in the Circle CI

Approved-by: Paula Quispe
This commit is contained in:
Roly Gutierrez
2022-09-14 16:24:28 +00:00
committed by Paula Quispe
12 changed files with 39 additions and 41 deletions

View File

@@ -40,6 +40,7 @@ return [
'prefix' => '', 'prefix' => '',
'strict' => env('DB_STRICT', false), 'strict' => env('DB_STRICT', false),
'engine' => null, 'engine' => null,
'options' => [PDO::ATTR_EMULATE_PREPARES => true,]
] ]
], ],
/* /*

View File

@@ -12,6 +12,7 @@ class ProcessFactory extends Factory
public function definition(): array public function definition(): array
{ {
$category = \ProcessMaker\Model\ProcessCategory::factory()->create();
return [ return [
'PRO_UID' => G::generateUniqueID(), 'PRO_UID' => G::generateUniqueID(),
'PRO_ID' => $this->faker->unique()->numberBetween(2000), 'PRO_ID' => $this->faker->unique()->numberBetween(2000),
@@ -31,10 +32,8 @@ class ProcessFactory extends Factory
'PRO_ITEE' => 1, 'PRO_ITEE' => 1,
'PRO_ACTION_DONE' => serialize([]), 'PRO_ACTION_DONE' => serialize([]),
'PRO_SUBPROCESS' => 0, 'PRO_SUBPROCESS' => 0,
'PRO_CATEGORY' => function () { 'PRO_CATEGORY' => $category->CATEGORY_UID,
return \ProcessMaker\Model\ProcessCategory::factory()->create()->CATEGORY_UID; 'CATEGORY_ID' => $category->CATEGORY_ID
},
'CATEGORY_ID' => 0
]; ];
} }

View File

@@ -39,11 +39,11 @@ class WorkflowToolsTest extends TestCase
ob_start(); ob_start();
$this->workspaceTools->addAsyncOptionToSchedulerCommands(false); $this->workspaceTools->addAsyncOptionToSchedulerCommands(false);
$string = ob_get_clean(); $string = ob_get_clean();
$this->assertRegExp("/This was previously updated/", $string); $this->assertMatchesRegularExpression("/This was previously updated/", $string);
ob_start(); ob_start();
$this->workspaceTools->addAsyncOptionToSchedulerCommands(true); $this->workspaceTools->addAsyncOptionToSchedulerCommands(true);
$string = ob_get_clean(); $string = ob_get_clean();
$this->assertRegExp("/Adding \+async option/", $string); $this->assertMatchesRegularExpression("/Adding \+async option/", $string);
} }
} }

View File

@@ -11,11 +11,13 @@ class WorkspaceToolsTest extends TestCase
public $workspace; public $workspace;
/** /**
* Call the setUp parent method * Set up method.
* @return void
*/ */
public function setUp() public function setUp(): void
{ {
parent::setUp(); // TODO: Change the autogenerated stub parent::setUp();
$this->truncateNonInitialModels();
config(["system.workspace" => "new_site"]); config(["system.workspace" => "new_site"]);
$this->workspace = config("system.workspace"); $this->workspace = config("system.workspace");
@@ -31,26 +33,16 @@ class WorkspaceToolsTest extends TestCase
public function it_should_test_upgrade_Iso_Country_method() public function it_should_test_upgrade_Iso_Country_method()
{ {
$workspaceTools = new WorkspaceTools($this->workspace); $workspaceTools = new WorkspaceTools($this->workspace);
$workspaceTools->updateIsoCountry(); $workspaceTools->updateIsoCountry();
$result = ob_get_contents(); $result = ob_get_contents();
$this->assertRegExp("/-> Update table ISO_COUNTRY Done/", $result); $this->assertMatchesRegularExpression("/-> Update table ISO_COUNTRY Done/", $result);
$res = IsoCountry::findById('CI'); $res = IsoCountry::findById('CI');
// Assert the result is the expected // Assert the result is the expected
$this->assertEquals('Côte d\'Ivoire', $res['IC_NAME']); $this->assertEquals('Côte d\'Ivoire', $res['IC_NAME']);
} }
/**
* Set up method.
* @return void
*/
public function setUp(): void
{
parent::setUp();
$this->truncateNonInitialModels();
}
/** /**
* Tests the migrateCaseTitleToThreads method * Tests the migrateCaseTitleToThreads method
* *
@@ -149,7 +141,7 @@ class WorkspaceToolsTest extends TestCase
$result = ob_get_contents(); $result = ob_get_contents();
ob_end_clean(); ob_end_clean();
$this->assertMatchesRegularExpression("/The Case Title has been updated successfully in APP_DELEGATION table./", $result); $this->assertMatchesRegularExpression("/The Case Title has been updated successfully in APP_DELEGATION table./", $result);
$r = Delegation::select('DEL_TITLE')->where('DELEGATION_ID', $delegation1->DELEGATION_ID)->get()->values()->toArray(); $r = Delegation::select('DEL_TITLE')->where('DELEGATION_ID', $delegation1->DELEGATION_ID)->get()->values()->toArray();
$this->assertEquals($r[0]['DEL_TITLE'], $application1->APP_TITLE); $this->assertEquals($r[0]['DEL_TITLE'], $application1->APP_TITLE);

View File

@@ -15,7 +15,7 @@ class ProxyNewCasesListTest extends TestCase
/** /**
* This sets the initial parameters for each test. * This sets the initial parameters for each test.
*/ */
public function setUp() public function setUp(): void
{ {
parent::setUp(); // TODO: Change the autogenerated stub parent::setUp(); // TODO: Change the autogenerated stub
$this->settingUserLogged(); $this->settingUserLogged();

View File

@@ -368,7 +368,7 @@ class EmailServerTest extends TestCase
$emailServer = new EmailServer(); $emailServer = new EmailServer();
// This expects an exception message // This expects an exception message
$this->expectExceptionMessage('Undefined array key "MESS_ENGINE"'); $this->expectException('ErrorException');
// Call the sendTestMail method // Call the sendTestMail method
$emailServer->sendTestMail($data); $emailServer->sendTestMail($data);

View File

@@ -114,9 +114,10 @@ class WebEntryTest extends TestCase
$webEntryFilename = 'My_Custom_Form'; $webEntryFilename = 'My_Custom_Form';
//assert true result //assert true result
$webEntry = factory(WebEntry::class)->create([ $webEntry = WebEntry::factory()->create([
'WE_DATA' => $webEntryFilename . $phpExtension, 'WE_DATA' => $webEntryFilename . $phpExtension,
'WE_HIDE_ACTIVE_SESSION_WARNING' => '0' 'WE_HIDE_ACTIVE_SESSION_WARNING' => '0',
'WE_AUTHENTICATION' => 'LOGIN_REQUIRED'
]); ]);
$weUid = $webEntry->WE_UID; $weUid = $webEntry->WE_UID;
@@ -126,9 +127,10 @@ class WebEntryTest extends TestCase
$this->assertEquals($result, true); $this->assertEquals($result, true);
//assert false result //assert false result
$webEntry = factory(WebEntry::class)->create([ $webEntry = WebEntry::factory()->create([
'WE_DATA' => $webEntryFilename . $phpExtension, 'WE_DATA' => $webEntryFilename . $phpExtension,
'WE_HIDE_ACTIVE_SESSION_WARNING' => '1' 'WE_HIDE_ACTIVE_SESSION_WARNING' => '1',
'WE_AUTHENTICATION' => 'LOGIN_REQUIRED'
]); ]);
$weUid = $webEntry->WE_UID; $weUid = $webEntry->WE_UID;

View File

@@ -368,6 +368,6 @@ class GmailOAuthTest extends TestCase
$res = $gmailOauth->getMessageBody(); $res = $gmailOauth->getMessageBody();
// Assert the result contains the server protocol and host // Assert the result contains the server protocol and host
$this->assertRegExp("#" . System::getServerProtocol() . System::getServerHost() . "#", $res); $this->assertMatchesRegularExpression("#" . System::getServerProtocol() . System::getServerHost() . "#", $res);
} }
} }

View File

@@ -155,7 +155,7 @@ class DelegationTest extends TestCase
*/ */
public function it_return_scope_thread_id_open() public function it_return_scope_thread_id_open()
{ {
$table = factory(Delegation::class)->states('foreign_keys')->create(); $table = Delegation::factory()->foreign_keys()->create();
$this->assertCount(1, $table->threadIdOpen()->get()); $this->assertCount(1, $table->threadIdOpen()->get());
} }

View File

@@ -678,7 +678,7 @@ class MetricsTest extends TestCase
'DEL_INDEX' => 2, 'DEL_INDEX' => 2,
]); ]);
$metrics = new Metrics(); $metrics = new Metrics();
$this->expectExceptionMessage('Undefined variable $list'); $this->expectException('Luracast\Restler\RestException');
$metrics->getProcessTotalCases(12, 123, "asda"); $metrics->getProcessTotalCases(12, 123, "asda");
} }
@@ -695,7 +695,7 @@ class MetricsTest extends TestCase
'DEL_INDEX' => 2, 'DEL_INDEX' => 2,
]); ]);
$metrics = new Metrics(); $metrics = new Metrics();
$this->expectExceptionMessage('Undefined variable $list'); $this->expectException('Luracast\Restler\RestException');
$metrics->getTotalCasesByRange(12, 123, "asda"); $metrics->getTotalCasesByRange(12, 123, "asda");
} }
@@ -712,7 +712,7 @@ class MetricsTest extends TestCase
'DEL_INDEX' => 2, 'DEL_INDEX' => 2,
]); ]);
$metrics = new Metrics(); $metrics = new Metrics();
$this->expectExceptionMessage('Undefined variable $list'); $this->expectException('Luracast\Restler\RestException');
$metrics->getCasesRiskByProcess(12, 123, "asda"); $metrics->getCasesRiskByProcess(12, 123, "asda");
} }
} }

View File

@@ -3,7 +3,6 @@
namespace Tests\unit\workflow\engine\src\ProcessMaker\Services\Api; namespace Tests\unit\workflow\engine\src\ProcessMaker\Services\Api;
use Faker\Factory; use Faker\Factory;
use Luracast\Restler\RestException;
use ProcessMaker\Model\Process; use ProcessMaker\Model\Process;
use ProcessMaker\Model\User; use ProcessMaker\Model\User;
use ProcessMaker\Model\RbacUsers; use ProcessMaker\Model\RbacUsers;
@@ -29,6 +28,11 @@ class ProjectTest extends TestCase
*/ */
public function it_should_set_the_process_owner_with_invalid_value() public function it_should_set_the_process_owner_with_invalid_value()
{ {
$workspace = config("system.workspace");
$cacheFolder = PATH_DATA . "sites" . PATH_SEP . $workspace . PATH_SEP . "cachefiles" . PATH_SEP;
if (!file_exists($cacheFolder)) {
mkdir($cacheFolder, 0777, true);
}
$filename = PATH_TRUNK . "tests/resources/p1normal-2.pmx"; $filename = PATH_TRUNK . "tests/resources/p1normal-2.pmx";
$importer = new XmlImporter(); $importer = new XmlImporter();
$importer->setData("usr_uid", $this->user->USR_UID); $importer->setData("usr_uid", $this->user->USR_UID);
@@ -51,18 +55,18 @@ class ProjectTest extends TestCase
*/ */
public function it_should_test_the_do_get_process_method() public function it_should_test_the_do_get_process_method()
{ {
$this->markTestSkipped("Propel doesn't have connection to database php8");
//Create user //Create user
$user = User::factory()->create();
RbacUsers::factory()->create([ RbacUsers::factory()->create([
'USR_UID' => $user->USR_UID, 'USR_UID' => $this->user->USR_UID,
'USR_USERNAME' => $user->USR_USERNAME, 'USR_USERNAME' => $this->user->USR_USERNAME,
'USR_FIRSTNAME' => $user->USR_FIRSTNAME, 'USR_FIRSTNAME' => $this->user->USR_FIRSTNAME,
'USR_LASTNAME' => $user->USR_LASTNAME 'USR_LASTNAME' => $this->user->USR_LASTNAME
]); ]);
//Create process //Create process
$process = Process::factory()->create([ $process = Process::factory()->create([
'PRO_CREATE_USER' => $user->USR_UID, 'PRO_CREATE_USER' => $this->user->USR_UID,
'PRO_STATUS' => 'ACTIVE', 'PRO_STATUS' => 'ACTIVE',
'PRO_TYPE_PROCESS' => 'PRIVATE', 'PRO_TYPE_PROCESS' => 'PRIVATE',
]); ]);

View File

@@ -37,7 +37,7 @@ class UpdateUserLastLoginTest extends TestCase
$userLog = ['USR_UID' => $user['USR_UID']]; $userLog = ['USR_UID' => $user['USR_UID']];
// Assert the expected exception // Assert the expected exception
$this->expectExceptionMessage('Undefined array key "LOG_INIT_DATE"'); $this->expectException('Exception');
// Call the updateUserLastLogin function // Call the updateUserLastLogin function
updateUserLastLogin($userLog); updateUserLastLogin($userLog);