From 41ffbd3a6c47afef190f95528cd813e50f8f7b55 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Mon, 11 Dec 2023 19:01:59 +1300 Subject: [PATCH] MNT Unit tests --- README.md | 2 +- composer.json | 2 +- src/Tasks/DocblockTagWriterTask.php | 18 ++++++++++++++---- tests/Tasks/DocblockTagWriterTaskTest.php | 10 +++++----- .../DocblockTagWriterTaskTest/TestObjectA.php | 2 ++ .../DocblockTagWriterTaskTest/TestObjectB.php | 2 ++ .../TestObjectThrough.php | 2 ++ 7 files changed, 27 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 9004d92..a9d644a 100644 --- a/README.md +++ b/README.md @@ -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 ` +`vendor/bin/sake dev/tasks/SilverStripe-DockblockWriter-Tasks-DocblockTagWriterTask ` diff --git a/composer.json b/composer.json index a29fbbb..d80980b 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "silverstripe/docblock-writer", + "name": "emteknetnz/docblock-writer", "type": "silverstripe-vendormodule", "license": "BSD-3-Clause", "require": { diff --git a/src/Tasks/DocblockTagWriterTask.php b/src/Tasks/DocblockTagWriterTask.php index fb8d77a..1115769 100644 --- a/src/Tasks/DocblockTagWriterTask.php +++ b/src/Tasks/DocblockTagWriterTask.php @@ -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 + * Usage: vendor/bin/sake dev/tasks/dev/tasks/SilverStripe-DockblockWriter-Tasks-DocblockTagWriterTask */ class DocblockTagWriterTask extends BuildTask { @@ -76,6 +76,9 @@ 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)) { @@ -83,7 +86,7 @@ public function getProcessableFiles(string $pathFilter): array } $files[] = [ 'path' => $path, - 'dataClass' => $dataClass, + 'dataClass' => $dataClass, // TODO: rename dataClass, doesn't make sense for Extensions ]; } return $files; @@ -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 \n"; + $task = 'dev/tasks/SilverStripe-DockblockWriter-Tasks-DocblockTagWriterTask'; + echo "Usage: vendor/bin/sake $task \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 diff --git a/tests/Tasks/DocblockTagWriterTaskTest.php b/tests/Tasks/DocblockTagWriterTaskTest.php index 324e944..ba30632 100644 --- a/tests/Tasks/DocblockTagWriterTaskTest.php +++ b/tests/Tasks/DocblockTagWriterTaskTest.php @@ -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); } } diff --git a/tests/Tasks/DocblockTagWriterTaskTest/TestObjectA.php b/tests/Tasks/DocblockTagWriterTaskTest/TestObjectA.php index 78ea488..d2e0c78 100644 --- a/tests/Tasks/DocblockTagWriterTaskTest/TestObjectA.php +++ b/tests/Tasks/DocblockTagWriterTaskTest/TestObjectA.php @@ -8,6 +8,8 @@ class TestObjectA extends DataObject implements TestOnly { + private static $table_name = 'DocblockTagWriterTaskTest_TestObjectA'; + private static $has_one = [ 'MyHasOne' => TestObjectB::class, ]; diff --git a/tests/Tasks/DocblockTagWriterTaskTest/TestObjectB.php b/tests/Tasks/DocblockTagWriterTaskTest/TestObjectB.php index 660d8bb..3306c98 100644 --- a/tests/Tasks/DocblockTagWriterTaskTest/TestObjectB.php +++ b/tests/Tasks/DocblockTagWriterTaskTest/TestObjectB.php @@ -8,6 +8,8 @@ class TestObjectB extends DataObject implements TestOnly { + private static $table_name = 'DocblockTagWriterTaskTest_TestObjectB'; + private static $belongs_many_many = [ 'SomeManyManys' => TestObjectA::class, ]; diff --git a/tests/Tasks/DocblockTagWriterTaskTest/TestObjectThrough.php b/tests/Tasks/DocblockTagWriterTaskTest/TestObjectThrough.php index b345642..180bc89 100644 --- a/tests/Tasks/DocblockTagWriterTaskTest/TestObjectThrough.php +++ b/tests/Tasks/DocblockTagWriterTaskTest/TestObjectThrough.php @@ -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,