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

Add unit test for naming conventions #1676

Merged
merged 5 commits into from
Apr 25, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Hyde\Framework\Testing\Unit;

use Illuminate\Filesystem\Filesystem;
use Hyde\Framework\Actions\BladeMatterParser;
use Hyde\Console\Commands\VendorPublishCommand;
use Hyde\Framework\Actions\CreatesNewMarkdownPostFile;
use Hyde\Framework\Actions\CreatesNewPageSourceFile;
use Hyde\Framework\Actions\MarkdownFileParser;
Expand All @@ -28,6 +30,57 @@ public function testCommandsClassesFollowNamingConventions()
}
}

public function testCommandsDescriptionsFollowNamingConventions()
{
self::mockConfig();

$files = glob('vendor/hyde/framework/src/Console/Commands/*.php');

$this->assertNotEmpty($files, 'No commands found.');

// Commands must have a string $description property
foreach ($files as $filepath) {
$class = 'Hyde\\Console\\Commands\\'.basename($filepath, '.php');
$reflection = new ReflectionClass($class);

$this->assertTrue($reflection->hasProperty('description') && $reflection->getProperty('description')->isProtected(),
"Command class $class does not have a protected \$description property.\n ".realpath($filepath)
);

if ($class === VendorPublishCommand::class) {
$params = [new Filesystem()];
} else {
$params = [];
}

$instance = new $class(...$params);
$description = $instance->getDescription();

$this->assertIsString($description);
$this->assertNotEmpty($description);

$this->assertTrue($description[0] === strtoupper($description[0]),
"Command class $class description does not start with an uppercase letter.\n ".realpath($filepath)
);

$this->assertTrue($description[strlen($description) - 1] !== '.' && $description[strlen($description) - 1] !== '!' && $description[strlen($description) - 1] !== '?',
"Command class $class description ends with a period or another punctuation mark.\n ".realpath($filepath)
);

$this->assertSame($description, trim($description),
'Command class '.$class.' description has leading or trailing whitespace.'
);

$this->assertStringNotContainsString(' ', $description,
'Command class '.$class.' description has multiple consecutive spaces.'
);

$this->assertStringNotContainsString("\n", $description,
'Command class '.$class.' description has a newline character.'
);
}
}

public function testActionEntryPointsFollowNamingConventions()
{
$files = glob('vendor/hyde/framework/src/Framework/Actions/*.php');
Expand Down
Loading