Skip to content

Commit

Permalink
MNT Unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Dec 11, 2023
1 parent 2cce15e commit 41ffbd3
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Silverstripe CMS squad either in a dev or a CI environment. It is not intended t

`composer install --dev silverstripe/docblock-writer`

`vendor/bin/sake dev/tasks/TODO_NAMESPACE/DocBlockTagWriterTask <path>`
`vendor/bin/sake dev/tasks/SilverStripe-DockblockWriter-Tasks-DocblockTagWriterTask <path>`
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "silverstripe/docblock-writer",
"name": "emteknetnz/docblock-writer",
"type": "silverstripe-vendormodule",
"license": "BSD-3-Clause",
"require": {
Expand Down
18 changes: 14 additions & 4 deletions src/Tasks/DocblockTagWriterTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* Adds class level docblock @method tags to DataObjects and Extensions for ORM private static proerties
* `has_one`, `one_many` and `many_many`.
*
* Usage: vendor/bin/sake dev/tasks/TODO_NAMESPACE/DocBlockTagWriterTask <path>
* Usage: vendor/bin/sake dev/tasks/dev/tasks/SilverStripe-DockblockWriter-Tasks-DocblockTagWriterTask <path>
*/
class DocblockTagWriterTask extends BuildTask
{
Expand Down Expand Up @@ -76,14 +76,17 @@ public function getProcessableFiles(string $pathFilter): array
$classInfo->getValidSubClasses(DataObject::class),
$classInfo->getValidSubClasses(Extension::class),
);
// $c = array_values($dataClasses);
// sort($c);
// print_r($c);
foreach ($dataClasses as $dataClass) {
$path = (new ReflectionClass($dataClass))->getFileName();
if (!$this->shouldProcessFile($path, $pathFilter)) {
continue;
}
$files[] = [
'path' => $path,
'dataClass' => $dataClass,
'dataClass' => $dataClass, // TODO: rename dataClass, doesn't make sense for Extensions
];
}
return $files;
Expand Down Expand Up @@ -303,10 +306,17 @@ private function getPathFilter(HTTPRequest $request): string
{
$args = $request->getVars()['args'] ?? [];
if (empty($args)) {
echo "Usage: vendor/bin/sake dev/tasks/AnnotatorTask <path>\n";
$task = 'dev/tasks/SilverStripe-DockblockWriter-Tasks-DocblockTagWriterTask';
echo "Usage: vendor/bin/sake $task <path>\n";
die;
}
return Controller::join_links(BASE_PATH, $args[0]);
$path = $args[0];
// Absolute path
if (strpos($path, BASE_PATH) === 0) {
return $path;
}
// Relative path
return Controller::join_links(BASE_PATH, $path);
}

private function getProperty(string $dataClass, string $property): array
Expand Down
10 changes: 5 additions & 5 deletions tests/Tasks/DocblockTagWriterTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class DocblockTagWriterTaskTest extends SapphireTest
TestObjectThrough::class,
];

public function testSomething()
public function testGetProcessableFiles()
{
$task = new DocblockTagWriterTask();
$pathFilter = basename(__FILE__);
var_dump($pathFilter);
// TODO write some tests
$this->assertTrue(true);
$pathFilter = __DIR__ . str_replace('.php', '', __FILE__);
$expected = [];
$actual = $task->getProcessableFiles($pathFilter);
$this->assertSame($expected, $actual);
}
}
2 changes: 2 additions & 0 deletions tests/Tasks/DocblockTagWriterTaskTest/TestObjectA.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

class TestObjectA extends DataObject implements TestOnly
{
private static $table_name = 'DocblockTagWriterTaskTest_TestObjectA';

private static $has_one = [
'MyHasOne' => TestObjectB::class,
];
Expand Down
2 changes: 2 additions & 0 deletions tests/Tasks/DocblockTagWriterTaskTest/TestObjectB.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

class TestObjectB extends DataObject implements TestOnly
{
private static $table_name = 'DocblockTagWriterTaskTest_TestObjectB';

private static $belongs_many_many = [
'SomeManyManys' => TestObjectA::class,
];
Expand Down
2 changes: 2 additions & 0 deletions tests/Tasks/DocblockTagWriterTaskTest/TestObjectThrough.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

class TestObjectThrough extends DataObject implements TestOnly
{
private static $table_name = 'DocblockTagWriterTaskTest_TestObjectThrough';

private static array $has_one = [
'TestObjectA' => TestObjectA::class,
'TestObjectB' => TestObjectB::class,
Expand Down

0 comments on commit 41ffbd3

Please sign in to comment.