Skip to content

Commit

Permalink
MNT Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Dec 11, 2023
1 parent 8eeb8a6 commit 09e13ad
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 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/SilverStripe-DockblockWriter-Tasks-DocblockTagWriterTask <path>`
`vendor/bin/sake dev/tasks/SilverStripe-DocblockWriter-Tasks-DocblockTagWriterTask <path>`
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true">
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
<testsuites>
<testsuite name="Default">
<directory>tests</directory>
Expand Down
26 changes: 4 additions & 22 deletions src/Tasks/DocblockTagWriterTask.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SilverStripe\DockblockWriter\Tasks;
namespace emteknetnz\DocblockWriter\Tasks;

use Exception;
use ReflectionClass;
Expand All @@ -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/dev/tasks/SilverStripe-DockblockWriter-Tasks-DocblockTagWriterTask <path>
* Usage: vendor/bin/sake dev/tasks/dev/tasks/SilverStripe-DocblockWriter-Tasks-DocblockTagWriterTask <path>
*/
class DocblockTagWriterTask extends BuildTask
{
Expand Down Expand Up @@ -76,12 +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)) {
if (strpos($path, $pathFilter) !== 0) {
continue;
}
$files[] = [
Expand Down Expand Up @@ -306,7 +303,7 @@ private function getPathFilter(HTTPRequest $request): string
{
$args = $request->getVars()['args'] ?? [];
if (empty($args)) {
$task = 'dev/tasks/SilverStripe-DockblockWriter-Tasks-DocblockTagWriterTask';
$task = 'dev/tasks/SilverStripe-DocblockWriter-Tasks-DocblockTagWriterTask';
echo "Usage: vendor/bin/sake $task <path>\n";
die;
}
Expand Down Expand Up @@ -334,19 +331,4 @@ private function getProperty(string $dataClass, string $property): array
// Use new rather than ::create() because Extension subclasses are not injectable
return $prop->getValue(new $dataClass());
}

private function shouldProcessFile(string $path, string $pathFilter): bool
{
/// Skip if the file is not in the path filter
if (strpos($path, $pathFilter) !== 0) {
return false;
}
// Exclude vendor and thirdpaty folders
$vendorFolder = Controller::join_links(BASE_PATH, 'vendor');
$thirdPartyFolder = Controller::join_links(BASE_PATH, 'thirdparty');
if (strpos($path, $vendorFolder) !== false || strpos($path, $thirdPartyFolder) !== false) {
return false;
}
return true;
}
}
30 changes: 24 additions & 6 deletions tests/Tasks/DocblockTagWriterTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace emteknetnz\DocblockWriter\Tests\Tasks;

use SilverStripe\Dev\SapphireTest;
use SilverStripe\DocblockWriter\Tests\Tasks\DocblockTagWriterTaskTest\TestObjectA;
use SilverStripe\DocblockWriter\Tests\Tasks\DocblockTagWriterTaskTest\TestObjectB;
use SilverStripe\DocblockWriter\Tests\Tasks\DocblockTagWriterTaskTest\TestObjectThrough;
use SilverStripe\DockblockWriter\Tasks\DocblockTagWriterTask;
use emteknetnz\DocblockWriter\Tests\Tasks\DocblockTagWriterTaskTest\TestObjectA;
use emteknetnz\DocblockWriter\Tests\Tasks\DocblockTagWriterTaskTest\TestObjectB;
use emteknetnz\DocblockWriter\Tests\Tasks\DocblockTagWriterTaskTest\TestObjectThrough;
use emteknetnz\DocblockWriter\Tests\Tasks\DocblockTagWriterTaskTest\TestExtension;
use emteknetnz\DocblockWriter\Tasks\DocblockTagWriterTask;

class DocblockTagWriterTaskTest extends SapphireTest
{
Expand All @@ -19,8 +20,25 @@ class DocblockTagWriterTaskTest extends SapphireTest
public function testGetProcessableFiles()
{
$task = new DocblockTagWriterTask();
$pathFilter = __DIR__ . str_replace('.php', '', __FILE__);
$expected = [];
$pathFilter = str_replace('.php', '', __FILE__);
$expected = [
[
'path' => $pathFilter . '/TestObjectA.php',
'dataClass' => TestObjectA::class,
],
[
'path' => $pathFilter . '/TestObjectB.php',
'dataClass' => TestObjectB::class,
],
[
'path' => $pathFilter . '/TestObjectThrough.php',
'dataClass' => TestObjectThrough::class,
],
[
'path' => $pathFilter . '/TestExtension.php',
'dataClass' => TestExtension::class,
],
];
$actual = $task->getProcessableFiles($pathFilter);
$this->assertSame($expected, $actual);
}
Expand Down

0 comments on commit 09e13ad

Please sign in to comment.