Tests @api annotated code integrity
Definition at line 13 of file PublicCodeTest.php.
◆ layoutFilesDataProvider()
layoutFilesDataProvider |
( |
| ) |
|
Find all layout update files in magento modules and themes.
- Returns
- array
- Exceptions
-
Definition at line 92 of file PublicCodeTest.php.
◆ publicPHPTypesDataProvider()
publicPHPTypesDataProvider |
( |
| ) |
|
Retrieve list of all interfaces and classes in Magento codebase that are marked with @api annotation.
- Returns
- array
- Exceptions
-
Definition at line 147 of file PublicCodeTest.php.
151 foreach (
$files as $file) {
153 if (strpos($fileContents,
'@api') !==
false) {
154 foreach ($this->getDeclaredClassesAndInterfaces($file) as
$class) {
155 if (!in_array(
$class->getName(), $this->getWhitelist())
$_option $_optionId $class
foreach($appDirs as $dir) $files
◆ testAllPHPClassesReferencedFromPublicClassesArePublic()
testAllPHPClassesReferencedFromPublicClassesArePublic |
( |
|
$class | ) |
|
We want to avoid situation when a type is marked public (@api annotated) but one of its methods returns or accepts the value of non-public type. This test walks through all public PHP types and makes sure that all their method arguments and return values are public types.
- Parameters
-
- Exceptions
-
Definition at line 107 of file PublicCodeTest.php.
109 $nonPublishedClasses = [];
110 $reflection = new \ReflectionClass(
$class);
111 $filter = \ReflectionMethod::IS_PUBLIC;
112 if ($reflection->isAbstract()) {
113 $filter = $filter | \ReflectionMethod::IS_PROTECTED;
115 $methods = $reflection->getMethods($filter);
117 if (
$method->isConstructor()) {
120 $nonPublishedClasses = $this->checkParameters(
$class,
$method, $nonPublishedClasses);
124 if (
$method->hasReturnType()) {
125 if (!
$method->getReturnType()->isBuiltin()) {
126 $returnTypes = [trim(
$method->getReturnType()->__toString(),
'?[]')];
129 $returnTypes = $this->getReturnTypesFromDocComment(
$method->getDocComment());
131 $nonPublishedClasses = $this->checkReturnValues(
$class, $returnTypes, $nonPublishedClasses);
134 if (count($nonPublishedClasses)) {
136 "Public type '" .
$class .
"' references following non-public types:\n" 137 . implode(
"\n", array_unique($nonPublishedClasses))
$_option $_optionId $class
The documentation for this class was generated from the following file:
- vendor/magento/magento2-base/dev/tests/static/testsuite/Magento/Test/Integrity/PublicCodeTest.php