19 declare(strict_types=1);
21 require_once(
"vendor/composer/vendor/autoload.php");
53 'description' =>
true,
54 'background' =>
false,
56 'featurewiki' =>
false,
57 'javascript' =>
false,
93 return in_array(
"ILIAS\\UI\\Component\\Component", $reflection->getInterfaceNames());
98 return preg_match(
"#^(\\\\)?ILIAS\\\\UI\\\\Component\\\\([a-zA-Z]+\\\\)*Factory$#", $name) === 1;
109 $reflection = self::buildFactoryReflection();
112 if (!in_array($element->getName(), self::$omit_factory_methods)) {
113 return array($element, $element->getName());
116 }, $reflection->getMethods())
124 $this->yaml_parser =
new Crawler\EntriesYamlParser();
130 $message =
"TODO: Put your factory into the proper namespace.";
131 $this->assertMatchesRegularExpression(
132 "#^ILIAS\\\\UI\\\\Component.#",
133 self::$reflection->getNamespaceName(),
140 $name = self::$reflection->getName();
141 $message =
"TODO: Give your factory a proper name.";
148 #[\PHPUnit\Framework\Attributes\DataProvider('getMethodsProvider')] 153 $function_name_string =
"\n public function " . $method_reflection->getName() .
"()";
154 $docstring_data = $this->yaml_parser->parseArrayFromString(
155 $method_reflection->getDocComment() . $function_name_string
157 $this->assertTrue(
true);
159 $message =
"TODO ($name): fix parse error in kitchen sink yaml: " . $e->getMessage();
162 $this->assertCount(1, $docstring_data);
163 return $docstring_data[0];
169 #[\PHPUnit\Framework\Attributes\DataProvider('getMethodsProvider')] 172 $message =
"TODO ($name): fix return type, it must be a factory or a component.";
175 $this->assertTrue(
true);
177 $this->assertTrue(
true);
186 #[\PHPUnit\Framework\Attributes\DataProvider('getMethodsProvider')] 194 $return_doc = $docstring_data[
"namespace"];
195 $name_uppercase = ucwords($name);
197 $regex_head =
"#^(\\\\?)$regex_factory_namespace";
199 $message =
"TODO ($name): fix @return, it does not match the method name.";
201 $this->assertMatchesRegularExpression(
202 "$regex_head\\\\$name_uppercase\\\\Factory$#",
209 $standard_pattern =
"$regex_head\\\\$name_uppercase#";
210 $standard_case = preg_match($standard_pattern, $return_doc);
213 $namespace_parts = explode(
"\\", self::$reflection->getNamespaceName());
214 $typediff_only_pattern =
"$regex_head\\\\" . array_pop($namespace_parts) .
"#";
215 $typediff_only_case = preg_match($typediff_only_pattern, $return_doc);
217 $this->assertTrue($standard_case || $typediff_only_case,
$message);
223 return str_replace(
"\\",
"\\\\", self::$reflection->getNamespaceName());
229 #[\PHPUnit\Framework\Attributes\DataProvider('getMethodsProvider')] 234 $message =
"TODO ($name): remove params from method that returns Factory.";
235 $this->assertEquals(0, $method_reflection->getNumberOfParameters(),
$message);
241 #[\PHPUnit\Framework\Attributes\DataProvider('getMethodsProvider')] 247 if ($kitchensink_info_settings[
'description']) {
248 $message =
"TODO ($name): add a description.";
249 $this->assertArrayHasKey(
'description', $docstring_data,
$message);
251 $desc_fields = implode(
", ", static::$description_categories);
252 $message =
"TODO ($name): the description field should at least contain one of these: $desc_fields.";
253 $existing_keys = array_keys($docstring_data[
"description"]);
254 $existing_expected_keys = array_intersect(static::$description_categories, $existing_keys);
255 $this->assertGreaterThanOrEqual(
257 $existing_expected_keys,
263 #[\PHPUnit\Framework\Attributes\DataProvider('getMethodsProvider')] 267 if (isset($docstring_data[
"description"]) && isset($docstring_data[
"description"][
"rivals"])) {
268 $rules = $docstring_data[
"description"][
"rivals"];
269 $message =
"TODO ($name): The Rivals field has a non-string index. Format like 'rival_name': 'description'";
270 $this->assertTrue(array_unique(
array_map(
"is_string", array_keys($rules))) === array(
true),
$message);
272 $this->assertTrue(
true);
275 #[\PHPUnit\Framework\Attributes\DataProvider('getMethodsProvider')] 281 if ($kitchensink_info_settings[
'background']) {
282 $message =
"TODO ($name): add a background field.";
283 $this->assertArrayHasKey(
'background', $docstring_data,
$message);
287 #[\PHPUnit\Framework\Attributes\DataProvider('getMethodsProvider')] 293 if ($kitchensink_info_settings[
'featurewiki']) {
294 $message =
"TODO ($name): add a featurewiki field.";
295 $this->assertArrayHasKey(
'featurewiki', $docstring_data,
$message);
299 #[\PHPUnit\Framework\Attributes\DataProvider('getMethodsProvider')] 305 if ($kitchensink_info_settings[
'javascript']) {
306 $message =
"TODO ($name): add a javascript field.";
307 $this->assertArrayHasKey(
'javascript', $docstring_data,
$message);
311 #[\PHPUnit\Framework\Attributes\DataProvider('getMethodsProvider')] 317 if ($kitchensink_info_settings[
'rules']) {
318 $message =
"TODO ($name): add a rules field.";
319 $this->assertArrayHasKey(
'rules', $docstring_data,
$message);
321 $rules_fields = implode(
", ", static::$rules_categories);
322 $message =
"TODO ($name): the rules field should at least contain one of these: $rules_fields.";
323 $existing_keys = array_keys($docstring_data[
"rules"]);
324 $existing_expected_keys = array_intersect(static::$rules_categories, $existing_keys);
325 $this->assertGreaterThanOrEqual(
327 $existing_expected_keys,
333 #[\PHPUnit\Framework\Attributes\DataProvider('getMethodsProvider')] 338 if (!$this->
returnsFactory($docstring_data) && $kitchensink_info_settings[
"context"]) {
339 $message =
"TODO ($name): factory method returning component should have context field. Add it.";
340 $this->assertArrayHasKey(
"context", $docstring_data,
$message);
346 if (array_key_exists($name, static::$kitchensink_info_settings)) {
348 static::$kitchensink_info_settings_default,
349 static::$kitchensink_info_settings[$name]
352 return static::$kitchensink_info_settings_default;
returnsFactory(array $docstring_data)
isFactoryName(string $name)
testKitchensinkInfoDescription(ReflectionMethod $method_reflection, string $name)
testReturnType(ReflectionMethod $method_reflection, string $name)
Tests whether the method either returns a factory or a component.
static string $factory_title
testKitchensinkInfoFeatureWiki(ReflectionMethod $method_reflection, string $name)
testKitchensinkInfoBackground(ReflectionMethod $method_reflection, string $name)
static array $omit_factory_methods
testKitchensinkInfoContext(ReflectionMethod $method_reflection, string $name)
returnsComponent(array $docstring_data)
static getMethodsProvider()
static array static array $description_categories
testKitchensinkInfoRules(ReflectionMethod $method_reflection, string $name)
testFactoryMethodNameCompatibleDocstring(ReflectionMethod $method_reflection, string $name)
Tests whether the method name matches the return doctring?
testMethodParams(ReflectionMethod $method_reflection, string $name)
Tests whether methods returning factories have no parameters.
static buildFactoryReflection()
static ReflectionClass $reflection
testKitchensinkInfoRivals(ReflectionMethod $method_reflection, string $name)
static array $kitchensink_info_settings_default
getRegexFactoryNamespace()
Crawler EntriesYamlParser $yaml_parser
kitchensinkInfoSettingsMergedWithDefaults(string $name)
static array $rules_categories
testKitchensinkInfoJavaScript(ReflectionMethod $method_reflection, string $name)
Defines tests every SHOULD pass UI-factory.
testCheckYamlExtraction(ReflectionMethod $method_reflection, string $name)
Tests whether the YAML Kitchen Sink info can be parsed.