Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that we have covered with tests some constants phpdoc checks #110

Merged
merged 1 commit into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/fixtures/phpdoc_properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ class dummy_with_properties {
var ?string $undocumented2;
private $undocumented3;
private ?string $undocumented4;
const UNDOCUMENTED_CONSTANT1 = 0;
public const UNDOCUMENTED_CONSTANT2 = 0;

/**
* @const A wrongly documented constant.
*/
const WRONGLY_DOCUMENTED_CONSTANT = 0;

/**
* @var mixed $documented1 I'm just a dummy!
Expand All @@ -41,4 +48,9 @@ class dummy_with_properties {
* @var ?string $documented4 I'm just a dummy!
*/
private ?string $documented4;

/**
* @var A correctly documented constant.
*/
const CORRECTLY_DOCUMENTED_CONSTANT = 0;
}
22 changes: 21 additions & 1 deletion tests/moodlecheck_rules_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ public function test_functionsdocumented_method_overrides() {
* @covers ::local_moodlecheck_variablesdocumented
* @covers \local_moodlecheck_file::get_variables
*/
public function test_variablesdocumented() {
public function test_variables_and_constants_documented() {
$file = __DIR__ . "/fixtures/phpdoc_properties.php";

global $PAGE;
Expand All @@ -515,6 +515,8 @@ public function test_variablesdocumented() {

$xpath = new \DOMXpath($xmlresult);

// Verify that the undocumented variables are reported.

$found = $xpath->query('//file/error[@source="variablesdocumented"]');
// TODO: Change to DOMNodeList::count() when php71 support is gone.
$this->assertSame(4, $found->length);
Expand All @@ -524,6 +526,24 @@ public function test_variablesdocumented() {
$this->assertStringContainsString('$undocumented2', $found->item(1)->getAttribute("message"));
$this->assertStringContainsString('$undocumented3', $found->item(2)->getAttribute("message"));
$this->assertStringContainsString('$undocumented4', $found->item(3)->getAttribute("message"));

// Verify that the undocumented constants are reported.

$found = $xpath->query('//file/error[@source="constsdocumented"]');
// TODO: Change to DOMNodeList::count() when php71 support is gone.
$this->assertSame(2, $found->length);

// The PHPdocs of the other properties should be detected correctly.
$this->assertStringContainsString('UNDOCUMENTED_CONSTANT1', $found->item(0)->getAttribute("message"));
$this->assertStringContainsString('UNDOCUMENTED_CONSTANT2', $found->item(1)->getAttribute("message"));

// Verify that the @const tag is reported as invalid.

$found = $xpath->query('//file/error[@source="phpdocsinvalidtag"]');
// TODO: Change to DOMNodeList::count() when php71 support is gone.
$this->assertSame(1, $found->length);

$this->assertStringContainsString('Invalid phpdocs tag @const used', $found->item(0)->getAttribute("message"));
}

/**
Expand Down