Skip to content

Improve isFieldInResponse to handle more combinations - #35618

Merged
patrickjahns merged 2 commits into
masterfrom
improve-isFieldInResponse
Jun 21, 2019
Merged

Improve isFieldInResponse to handle more combinations#35618
patrickjahns merged 2 commits into
masterfrom
improve-isFieldInResponse

Conversation

@phil-davis

@phil-davis phil-davis commented Jun 21, 2019

Copy link
Copy Markdown
Contributor

Description

Enhance isFieldInResponse() acceptance test method so that it:

  • knows if the caller is expecting success, and if the field does not exist or has an unexpected value, or... then emit some debug information to help the developer know what the actual value was etc.
  • add the special value ANY_VALUE so we can test for a field existing (or not existing) and we do not care what the value is.

Motivation and Context

If I write:

    And the fields of the last response should not include
      | share_with | anne |

Then if the share_with field exists, but has some other value like bob, then the test passes.
I want to be able to to test that a field does not exist at all.

If the field is not as expected, then as well as a fail message, I would like to know what value it was set to, or if the field did not exist. That can really help when trying to work out why a test is failing.

How Has This Been Tested?

Local runs of createShare.feature scenarios with different combinations of fields and values in steps for:

And the fields of the last response should include
And the fields of the last response should not include

to verify that when something is different from expected, that the test does fail, and emits a somewhat-useful message.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Database schema changes (next release will require increase of minor version instead of patch)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:

Open tasks:

  • Backport (if applicable set "backport-request" label and remove when the backport was done)

@codecov

codecov Bot commented Jun 21, 2019

Copy link
Copy Markdown

Codecov Report

Merging #35618 into master will decrease coverage by 16.78%.
The diff coverage is n/a.

Impacted file tree graph

@@              Coverage Diff              @@
##             master   #35618       +/-   ##
=============================================
- Coverage     65.68%    48.9%   -16.79%     
=============================================
  Files          1222      109     -1113     
  Lines         70932    10569    -60363     
  Branches       1289     1289               
=============================================
- Hits          46594     5169    -41425     
+ Misses        23960     5022    -18938     
  Partials        378      378
Flag Coverage Δ Complexity Δ
#javascript 53.7% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 38.29% <ø> (-28.77%) 0 <ø> (-18775)
Impacted Files Coverage Δ Complexity Δ
lib/private/Files/Storage/DAV.php 59.45% <0%> (-21.64%) 0% <0%> (ø)
apps/updatenotification/templates/admin.php
lib/private/Encryption/Keys/Storage.php
lib/private/App/CodeChecker/NodeVisitor.php
lib/private/RedisFactory.php
apps/dav/lib/Avatars/AvatarNode.php
...s/dav/appinfo/Migrations/Version20170202213905.php
apps/dav/lib/Upload/ChunkLocationProvider.php
apps/files/lib/AppInfo/Application.php
apps/systemtags/list.php
... and 1104 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ee2a647...76b2a71. Read the comment docs.

@codecov

codecov Bot commented Jun 21, 2019

Copy link
Copy Markdown

Codecov Report

Merging #35618 into master will decrease coverage by 16.78%.
The diff coverage is n/a.

Impacted file tree graph

@@              Coverage Diff              @@
##             master   #35618       +/-   ##
=============================================
- Coverage     65.68%    48.9%   -16.79%     
=============================================
  Files          1222      109     -1113     
  Lines         70932    10569    -60363     
  Branches       1289     1289               
=============================================
- Hits          46594     5169    -41425     
+ Misses        23960     5022    -18938     
  Partials        378      378
Flag Coverage Δ Complexity Δ
#javascript 53.7% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 38.29% <ø> (-28.77%) 0 <ø> (-18775)
Impacted Files Coverage Δ Complexity Δ
lib/private/Files/Storage/DAV.php 59.45% <0%> (-21.64%) 0% <0%> (ø)
apps/updatenotification/templates/admin.php
lib/private/Encryption/Keys/Storage.php
lib/private/App/CodeChecker/NodeVisitor.php
lib/private/RedisFactory.php
apps/dav/lib/Avatars/AvatarNode.php
...s/dav/appinfo/Migrations/Version20170202213905.php
apps/dav/lib/Upload/ChunkLocationProvider.php
apps/files/lib/AppInfo/Application.php
apps/systemtags/list.php
... and 1104 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ee2a647...76b2a71. Read the comment docs.

@phil-davis
phil-davis marked this pull request as ready for review June 21, 2019 08:20
* @return bool
*/
public function isFieldInResponse($field, $contentExpected, $data = null) {
public function isFieldInResponse($field, $contentExpected, $expectSuccess = true, $data = null) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note: nothing currently calls this passing $data parameter. So we can push it out to parameter 4 without breaking anything.

@skshetry skshetry Jun 21, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's really not the $expectSuccess, but provides debug information (so, something like $debug = true?). And, as it's purpose is to provide debug info, it would be good to push it to the edge, I think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It does actually tell the function if the caller is expecting a true or false return.
If the caller is expecting true but the function is about to return false then emit some debug info to give clues about why the expected content was not found.
If the caller is expecting false but the function is about to return true then emit some debug info to give clues about what (unexpected) content was found.

return (\strlen((string)$element->$field) == 15);
$fieldIsSet = true;
$fieldValue = (string)$element->$field;
if ($contentExpected == "ANY_VALUE") {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if ($contentExpected == "ANY_VALUE") {
if ($contentExpected === "ANY_VALUE") {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@individual-it I did another refactoring, also putting in plenty of ===
Please review the whole thing again.

@phil-davis
phil-davis force-pushed the improve-isFieldInResponse branch from 76b2a71 to 6f71e04 Compare June 21, 2019 09:17
public function doesFieldValueMatchExpectedContent(
$field, $value, $contentExpected, $expectSuccess = true
) {
if (($contentExpected === "ANY_VALUE")

@skshetry skshetry Jun 21, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It was quite difficult to understand previously. It's readable now. Next thing to do would be to not pass $contentExpected as string (except, for if we are checking for value). We could encapsulate these on something like Token class as static variables.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

or using our %something% inline substitutions

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, someday this will need the next refactoring.
e.g. if/when somebody writes a test with usernames A_TOKEN and A_NUMBER and they want to test that share_with field has the actual value A_NUMBER :)

@phil-davis
phil-davis force-pushed the improve-isFieldInResponse branch from 6f71e04 to 0496af1 Compare June 21, 2019 13:22
) . " 00:00:00";
}

$contentExpected = (string) $contentExpected;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We let the caller pass "mixed" in $contentExpected (just because they can anyway).
The responses really only have string values (even if they happen to look like numbers...). So we cast to string here, then can do === comparisons in comfort.

@phil-davis
phil-davis force-pushed the improve-isFieldInResponse branch from 0496af1 to afb7d3a Compare June 21, 2019 13:41
@patrickjahns
patrickjahns merged commit 2397193 into master Jun 21, 2019
@delete-merged-branch
delete-merged-branch Bot deleted the improve-isFieldInResponse branch June 21, 2019 14:58
@phil-davis

Copy link
Copy Markdown
Contributor Author

Backport stable10 #35622

@lock lock Bot locked as resolved and limited conversation to collaborators Jun 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants