Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
examples
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
examples
Merge requests
!59
Issue
#3458387
: Avoid YamlValidationTest::provideYamls() returns .yml files that are not part of the Examples project
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#3458387
: Avoid YamlValidationTest::provideYamls() returns .yml files that are not part of the Examples project
issue/examples-3458387:3458387-fix-YamlValidationTest-failures
into
4.0.x
Overview
0
Commits
3
Pipelines
4
Changes
1
Merged
Alberto Paderno
requested to merge
issue/examples-3458387:3458387-fix-YamlValidationTest-failures
into
4.0.x
10 months ago
Overview
0
Commits
3
Pipelines
4
Changes
1
Expand
Closes
#3458387
0
0
Merge request reports
Compare
4.0.x
version 2
d94ec6e8
10 months ago
version 1
5beca885
10 months ago
4.0.x (base)
and
latest version
latest version
366ed375
3 commits,
10 months ago
version 2
d94ec6e8
2 commits,
10 months ago
version 1
5beca885
1 commit,
10 months ago
1 file
+
39
−
19
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
tests/src/Unit/YamlValidationTest.php
+
39
−
19
Options
@@ -6,45 +6,65 @@ use PHPUnit\Framework\TestCase;
use
Symfony\Component\Yaml\Yaml
;
/**
* V
alidate requirements for config YAML
.
* V
erifies the configuration files are valid
.
*
* YAML in modules' config/ directory should not have a uuid: key. We'll use
* this test to check whether that's the case.
* Configuration files are considered valid if they do not contain a uuid key.
*
* @group examples
*/
class
YamlValidationTest
extends
TestCase
{
/**
*
Find all the config YAML files and p
rovide t
hem to the test
.
*
P
rovide
s
t
est data for testNoUuidsInConfig()
.
*
* @return array[]
* An array of arrays of strings, suitable as a data provider. Strings are
* paths to YAML files in config directories.
* @return array
* The test data.
*/
public
function
provideYamls
()
{
$yaml_paths
=
[];
// We cannot check all the files in all the directories contained in the
// project directory because GitLab CI could add its own directories,
// including the server document root directory.
// That is why $paths contains a list of directories to check.
// @todo Checks this needs to be changed once
// https://www.drupal.org/project/gitlab_templates/issues/3425971
// introduces changes in the setup process.
$paths
=
[
realpath
(
__DIR__
.
'/../../..'
)
.
'/modules'
];
$yaml_files
=
[];
$examples_project_path
=
realpath
(
__DIR__
.
'/../../..'
);
$paths
=
new
\RecursiveIteratorIterator
(
new
\RecursiveDirectoryIterator
(
$examples_project_path
,
\RecursiveDirectoryIterator
::
FOLLOW_SYMLINKS
));
foreach
(
$paths
as
$path
)
{
$pathname
=
$path
->
getPathname
();
if
(
strpos
(
$pathname
,
'.yml'
)
!==
FALSE
)
{
if
(
strpos
(
$pathname
,
'/config/'
)
!==
FALSE
)
{
$yaml_paths
[]
=
[
$pathname
];
$directory
=
new
\RecursiveDirectoryIterator
(
$path
,
\RecursiveDirectoryIterator
::
SKIP_DOTS
);
$filter
=
new
\RecursiveCallbackFilterIterator
(
$directory
,
function
(
$current
,
$key
,
$iterator
)
{
if
(
$current
->
isFile
())
{
// Only accept files whose extension is .yml which are contained in a
// config directory.
if
(
$current
->
getExtension
()
===
'yml'
&&
strpos
(
$current
->
getPathName
(),
'/config/'
)
!==
FALSE
)
{
return
TRUE
;
}
return
FALSE
;
}
// Always accept a directory.
return
TRUE
;
});
$iterator
=
new
\RecursiveIteratorIterator
(
$filter
);
foreach
(
$iterator
as
$info
)
{
$yaml_files
[]
=
[
$info
->
getPathname
()];
}
}
return
$yaml_paths
;
return
$yaml_files
;
}
/**
* Tests that the configuration files do not contain a uuid key.
*
* @dataProvider provideYamls
*/
public
function
testNoUuidsInConfig
(
$yaml_
path
)
{
$yaml
=
Yaml
::
parse
(
file_get_contents
(
$yaml_
path
));
$this
->
assertArrayNotHasKey
(
'uuid'
,
$yaml
,
"
YAML in this
file contains a uuid key
:
$yaml_path
"
);
public
function
testNoUuidsInConfig
(
$yaml_
file
)
{
$yaml
=
Yaml
::
parse
(
file_get_contents
(
$yaml_
file
));
$this
->
assertArrayNotHasKey
(
'uuid'
,
$yaml
,
"
$yaml_
file
contains a uuid key
.
"
);
}
}
Loading