Skip to content

Commit

Permalink
Merge pull request #1676 from hydephp/add-unit-test
Browse files Browse the repository at this point in the history
Add unit test for naming conventions
  • Loading branch information
caendesilva authored Apr 25, 2024
2 parents 6cfcd5b + 559967b commit 2a56552
Showing 1 changed file with 53 additions and 0 deletions.
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

0 comments on commit 2a56552

Please sign in to comment.