Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] Fix e-notice in APIv3 Profile Test on PHP8 #21143

Merged
merged 1 commit into from
Aug 16, 2021

Conversation

seamuslee001
Copy link
Contributor

Overview

This fixes an e-notice error on php 8 unit tests on 5.40, 5.41, master branches

Before

Test e-notice

api_v3_ProfileTest::testProfileSubmitInvalidProfileId
TypeError: uasort(): Argument #1 ($array) must be of type array, null given

/home/jenkins/bknix-edge/build/build-0/web/sites/all/modules/civicrm/api/v3/Profile.php:607

After

Test passes on php8

ping @eileenmcnaughton @totten

@civibot
Copy link

civibot bot commented Aug 14, 2021

(Standard links)

@civibot civibot bot added the 5.41 label Aug 14, 2021
@@ -604,6 +604,7 @@ function _civicrm_api3_buildprofile_submitfields($profileID, $optionsBehaviour,
*/
}
}
$profileFields[$profileID] = is_array($profileFields[$profileID]) ? $profileFields[$profileID] : [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point in the test, $profileFields is an empty array, so I would expect is_array($profileFields[$profileID]) to give an undefined index. In fact if you put an echo 'hi'; right after this line it doesn't output, so it's giving an E_NOTICE which is inadvertently fixing it by fullfilling the fail. If you put a var_dump($apiResult); in assertAPIFailure itself you can see this is what's happening.

Further, if there's no valid reason for this situation, would throwing an exception directly here be a better thing to do, because always converting to a valid thing might potentially hide other issues?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@demeritcowboy the problem is that it is not an empty array on php8 it is NULL for $profileFields[$profileID]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$profileFields is an empty array, so $profileFields[$profileID] gives an ENOTICE when you use is_array on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right sorry got confused, does my update work for you @demeritcowboy

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'm going to put merge-ready because I'm confused about a couple things, but if someone wants to merge I won't object.

  1. It seems like a (unintended?) change from dev/core#2743 fix api v3 to not unnecessarily load options #21099. Before it used to say "'1000' is not a valid option for field uf_group_id", and now, with this patch, it says "Invalid value for profile_id", which in this case yes is more accurate.
  2. I'm still wondering about my comment from before: If there's never a valid reason for $profileFields[$profileID] to be null here, then converting it to a valid value instead of throwing an exception might end up hiding something else. In either case it's a change from before, because what it used to do before, funnily enough, was to actually create an entry for 1000 inside the array, i.e. after the uasort $profileFields = [1000 => NULL], and now after the uasort $profileFields = [1000 => []].

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm - I think - yeah good points - but I guess if we are going to do a better fix it would be fine to do it in master & if no-one actually cares enough to do it then I guess that's fine if there is no reproduceable regression.

So I'm happy to merge this & maybe someone will fix more better in master

Remove e-notice issue found by dave d
@demeritcowboy demeritcowboy added the merge ready PR will be merged after a few days if there are no objections label Aug 15, 2021
@eileenmcnaughton eileenmcnaughton merged commit c2f9f4e into civicrm:5.41 Aug 16, 2021
@eileenmcnaughton eileenmcnaughton deleted the fix_enotice_php8 branch August 16, 2021 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.41 merge ready PR will be merged after a few days if there are no objections
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants