Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
automatic_updates
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
automatic_updates
Commits
e1a0bf4e
Commit
e1a0bf4e
authored
2 years ago
by
Travis Carden
Committed by
Ted Bowman
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3320815
by TravisCarden: Make validation result comparison test messages more helpful
parent
18d1ca72
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!588
Issue #3320815: Make validation result comparison test messages more helpful
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
package_manager/tests/src/Traits/ValidationTestTrait.php
+37
-5
37 additions, 5 deletions
package_manager/tests/src/Traits/ValidationTestTrait.php
with
37 additions
and
5 deletions
package_manager/tests/src/Traits/ValidationTestTrait.php
+
37
−
5
View file @
e1a0bf4e
...
...
@@ -12,18 +12,50 @@ trait ValidationTestTrait {
/**
* Asserts two validation result sets are equal.
*
* This assertion is sensitive to the order of results. For example,
* ['a', 'b'] is not equal to ['b', 'a'].
*
* @param \Drupal\package_manager\ValidationResult[] $expected_results
* The expected validation results.
* @param \Drupal\package_manager\ValidationResult[] $actual_results
* The actual validation results.
*/
protected
function
assertValidationResultsEqual
(
array
$expected_results
,
array
$actual_results
):
void
{
$this
->
assertCount
(
count
(
$expected_results
),
$actual_results
);
$expected_results
=
$this
->
getValidationResultsAsArray
(
$expected_results
);
$actual_results
=
$this
->
getValidationResultsAsArray
(
$actual_results
);
self
::
assertSame
(
$expected_results
,
$actual_results
);
}
/**
* Gets an array representation of validation results for easy comparison.
*
* @param \Drupal\package_manager\ValidationResult[] $results
* An array of validation results.
*
* @return array
* An array of validation results details:
* - severity: (int) The severity code.
* - messages: (array) An array of strings.
* - summary: (string|null) A summary string if there is one or NULL if not.
*/
protected
function
getValidationResultsAsArray
(
array
$results
):
array
{
return
array_values
(
array_map
(
static
function
(
ValidationResult
$result
)
{
$messages
=
array_map
(
static
function
(
$message
):
string
{
return
(
string
)
$message
;
},
$result
->
getMessages
());
$summary
=
$result
->
getSummary
();
if
(
$summary
!==
NULL
)
{
$summary
=
(
string
)
$result
->
getSummary
();
}
foreach
(
$expected_results
as
$expected_result
)
{
$actual_result
=
array_shift
(
$actual_results
);
$this
->
assertTrue
(
ValidationResult
::
isEqual
(
$expected_result
,
$actual_result
));
}
return
[
'severity'
=>
$result
->
getSeverity
(),
'messages'
=>
$messages
,
'summary'
=>
$summary
,
];
},
$results
));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment