From e7ea1b831cc619760bd4a00f862f87b4e8be0fca Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Wed, 26 Apr 2023 16:14:29 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B06254=20ItopDataTestCase::CreateUserReque?= =?UTF-8?q?st=20:=20now=20pass=20fields=20values=20as=20array=20More=20ver?= =?UTF-8?q?satile=20way=20of=20doing=20things=20!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/php-unit-tests/ItopDataTestCase.php | 30 +++++++++++-------- .../unitary-tests/core/DBSearchTest.php | 6 +++- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/tests/php-unit-tests/ItopDataTestCase.php b/tests/php-unit-tests/ItopDataTestCase.php index 7bc24f57b..4dfd2a5ae 100644 --- a/tests/php-unit-tests/ItopDataTestCase.php +++ b/tests/php-unit-tests/ItopDataTestCase.php @@ -293,25 +293,31 @@ class ItopDataTestCase extends ItopTestCase * Create a UserRequest in database * * @param int $iNum - * @param int $iTimeSpent - * @param int $iOrgId - * @param int $iCallerId + * @param array $aUserRequestCustomParams set fields values for the UserRequest : attcode as key, att value as value. + * If the attcode is already present in the default values, custom value will be kept (see array_merge documentation) * * @return \UserRequest - * @throws Exception + * @throws \ArchivedObjectException + * @throws \CoreException + * + * @link https://www.php.net/manual/en/function.array-merge.php array_merge PHP function documentation + * + * @uses \array_merge() + * @uses createObject */ - protected function CreateUserRequest($iNum, $iTimeSpent = 0, $iOrgId = 0, $iCallerId = 0) - { - /** @var \UserRequest $oTicket */ - $oTicket = $this->createObject('UserRequest', array( + protected function CreateUserRequest($iNum, $aUserRequestCustomParams) { + $aUserRequestDefaultParams = [ 'ref' => 'Ticket_'.$iNum, 'title' => 'BUG 1161_'.$iNum, //'request_type' => 'incident', 'description' => 'Add aggregate functions', - 'time_spent' => $iTimeSpent, - 'caller_id' => $iCallerId, - 'org_id' => ($iOrgId == 0 ? $this->getTestOrgId() : $iOrgId), - )); + 'org_id' => $this->getTestOrgId(), + ]; + + $aUserRequestParams = array_merge($aUserRequestDefaultParams, $aUserRequestCustomParams); + + /** @var \UserRequest $oTicket */ + $oTicket = $this->createObject('UserRequest', $aUserRequestParams); $this->debug("Created {$oTicket->Get('title')} ({$oTicket->Get('ref')})"); return $oTicket; diff --git a/tests/php-unit-tests/unitary-tests/core/DBSearchTest.php b/tests/php-unit-tests/unitary-tests/core/DBSearchTest.php index 19c53b186..5d00b6aa5 100644 --- a/tests/php-unit-tests/unitary-tests/core/DBSearchTest.php +++ b/tests/php-unit-tests/unitary-tests/core/DBSearchTest.php @@ -161,7 +161,11 @@ class DBSearchTest extends ItopDataTestCase $i = 0; foreach($aReq as $aParams) { - $oObj = $this->CreateUserRequest($i, $aParams[0], $aOrgIds[$aParams[1]], $aPersonIds[$aParams[2]]); + $oObj = $this->CreateUserRequest($i, [ + 'time_spent' => $aParams[0], + 'org_id' => $aOrgIds[$aParams[1]], + 'caller_id' => $aPersonIds[$aParams[2]], + ]); self::assertNotNull($oObj); $i++; }