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
64f1ecee
Commit
64f1ecee
authored
2 years ago
by
Kunal Sachdev
Committed by
Ted Bowman
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3318065
by kunal.sachdev, Wim Leers, tedbow: SymlinkValidatorTest doesn't test PreApplyEvent
parent
c1c9d462
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!646
Issue #3318065: SymlinkValidatorTest doesn't test PreApplyEvent
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
package_manager/tests/src/Kernel/SymlinkValidatorTest.php
+48
-24
48 additions, 24 deletions
package_manager/tests/src/Kernel/SymlinkValidatorTest.php
with
48 additions
and
24 deletions
package_manager/tests/src/Kernel/SymlinkValidatorTest.php
+
48
−
24
View file @
64f1ecee
...
...
@@ -7,7 +7,9 @@ namespace Drupal\Tests\package_manager\Kernel;
use
Drupal\Core\DependencyInjection\ContainerBuilder
;
use
Drupal\Core\Url
;
use
Drupal\package_manager
\Event\CollectIgnoredPathsEvent
;
use
Drupal\package_manager
\Event\PreApplyEvent
;
use
Drupal\package_manager
\Event\PreCreateEvent
;
use
Drupal\package_manager
\Event\StatusCheckEvent
;
use
Drupal\package_manager
\ValidationResult
;
use
PhpTuf\ComposerStager\Domain\Exception\PreconditionException
;
use
PhpTuf\ComposerStager\Domain\Service\Precondition\CodebaseContainsNoSymlinksInterface
;
...
...
@@ -55,18 +57,22 @@ class SymlinkValidatorTest extends PackageManagerKernelTestBase {
* The test cases.
*/
public
function
providerSymlink
():
array
{
return
[
'no symlinks'
=>
[
$test_cases
=
[];
foreach
([
PreApplyEvent
::
class
,
PreCreateEvent
::
class
,
StatusCheckEvent
::
class
]
as
$event
)
{
$test_cases
[
"
$event
event with no symlinks"
]
=
[
FALSE
,
[],
],
'symlinks'
=>
[
$event
,
];
$test_cases
[
"
$event
event with symlinks"
]
=
[
TRUE
,
[
ValidationResult
::
createError
([
'Symlinks were found.'
]),
],
],
];
$event
,
];
}
return
$test_cases
;
}
/**
...
...
@@ -76,10 +82,12 @@ class SymlinkValidatorTest extends PackageManagerKernelTestBase {
* Whether or not the precondition will detect symlinks.
* @param \Drupal\package_manager\ValidationResult[] $expected_results
* The expected validation results.
* @param string $event
* The event to test.
*
* @dataProvider providerSymlink
*/
public
function
testSymlink
(
bool
$symlinks_exist
,
array
$expected_results
):
void
{
public
function
testSymlink
(
bool
$symlinks_exist
,
array
$expected_results
,
string
$event
):
void
{
$add_ignored_path
=
function
(
CollectIgnoredPathsEvent
$event
):
void
{
$event
->
add
([
'ignore/me'
]);
};
...
...
@@ -90,23 +98,40 @@ class SymlinkValidatorTest extends PackageManagerKernelTestBase {
Argument
::
type
(
PathInterface
::
class
),
Argument
::
type
(
PathListInterface
::
class
),
];
$this
->
precondition
->
assertIsFulfilled
(
...
$arguments
)
->
will
(
function
(
array
$arguments
)
use
(
$symlinks_exist
):
void
{
Assert
::
assertContains
(
'ignore/me'
,
$arguments
[
2
]
->
getAll
());
if
(
$symlinks_exist
)
{
throw
new
PreconditionException
(
$this
->
reveal
(),
'Symlinks were found.'
);
}
})
->
shouldBeCalled
();
$this
->
assertStatusCheckResults
(
$expected_results
);
$this
->
assertResults
(
$expected_results
,
PreCreateEvent
::
class
);
$listener
=
function
()
use
(
$arguments
,
$symlinks_exist
):
void
{
$this
->
precondition
->
assertIsFulfilled
(
...
$arguments
)
->
will
(
function
(
array
$arguments
)
use
(
$symlinks_exist
):
void
{
Assert
::
assertContains
(
'ignore/me'
,
$arguments
[
2
]
->
getAll
());
if
(
$symlinks_exist
)
{
throw
new
PreconditionException
(
$this
->
reveal
(),
'Symlinks were found.'
);
}
})
->
shouldBeCalled
();
};
$this
->
addEventTestListener
(
$listener
,
$event
);
if
(
$event
===
StatusCheckEvent
::
class
)
{
$this
->
assertStatusCheckResults
(
$expected_results
);
}
else
{
$this
->
assertResults
(
$expected_results
,
$event
);
}
}
/**
* Tests the Composer Stager's symlink precondition with richer help.
*
* @param bool $symlinks_exist
* Whether or not the precondition will detect symlinks.
* @param array $expected_results
* The expected validation results.
* @param string $event
* The event to test.
*
* @dataProvider providerSymlink
*/
public
function
testHelpLink
(
bool
$symlinks_exist
,
array
$expected_results
,
string
$event
):
void
{
$this
->
enableModules
([
'help'
]);
// Enabling Help rebuilt the container, so we need to re-add our event
// listener.
$this
->
addEventTestListener
(
$add_ignored_path
,
CollectIgnoredPathsEvent
::
class
);
$url
=
Url
::
fromRoute
(
'help.page'
,
[
'name'
=>
'package_manager'
])
->
setOption
(
'fragment'
,
'package-manager-faq-symlinks-found'
)
...
...
@@ -121,8 +146,7 @@ class SymlinkValidatorTest extends PackageManagerKernelTestBase {
$messages
=
array_map
(
$map
,
$result
->
getMessages
());
$expected_results
[
$index
]
=
ValidationResult
::
createError
(
$messages
);
}
$this
->
assertStatusCheckResults
(
$expected_results
);
$this
->
assertResults
(
$expected_results
,
PreCreateEvent
::
class
);
$this
->
testSymlink
(
$symlinks_exist
,
$expected_results
,
$event
);
}
}
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