Skip to content

Commit

Permalink
Fix remove useless fields from nova resources (#96)
Browse files Browse the repository at this point in the history
* Fix remove useless fields from nova resources

* Refactoring a delete method
  • Loading branch information
cable8mm authored Jan 6, 2025
1 parent cc9d49d commit 7a2a5ea
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Generators/NovaResourceGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public function run(bool $force = false): void
{
$novaFieldsString = '';
foreach ($this->table->getColumns() as $column) {
$novaFieldsString .= self::INTENT.$column->novaField().PHP_EOL;
if (! in_array($column->field, ['created_at', 'updated_at'])) {
$novaFieldsString .= self::INTENT.$column->novaField().PHP_EOL;
}
}
$novaFieldsString = rtrim($novaFieldsString, PHP_EOL.PHP_EOL);

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Generators/ModelGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function test_it_can_generate_timestamps(): void

public function test_it_can_generate_without_timestamps(): void
{
unlink(Path::testgen().DIRECTORY_SEPARATOR.'Sample.php');
File::system()->delete(Path::testgen().DIRECTORY_SEPARATOR.'Sample.php');

ModelGenerator::make(
new Table('samples', [
Expand Down
43 changes: 43 additions & 0 deletions tests/Unit/Generators/NovaResourceGeneratorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Cable8mm\Xeed\Tests\Unit\Generators;

use Cable8mm\Xeed\Column;
use Cable8mm\Xeed\Generators\NovaResourceGenerator;
use Cable8mm\Xeed\Support\File;
use Cable8mm\Xeed\Support\Path;
use Cable8mm\Xeed\Table;
use PHPUnit\Framework\TestCase;

final class NovaResourceGeneratorTest extends TestCase
{
protected function setUp(): void
{
NovaResourceGenerator::make(
new Table('samples', [
Column::make('id', 'bigint'),
Column::make('created_at', 'timestamp'),
Column::make('updated_at', 'timestamp'),
]),
destination: Path::testgen()
)->run();
}

protected function tearDown(): void
{
File::system()->delete(Path::testgen().DIRECTORY_SEPARATOR.'Sample.php');
}

public function test_it_can_be_existed(): void
{
$this->assertFileExists(Path::testgen().DIRECTORY_SEPARATOR.'Sample.php');
}

public function test_it_can_be_without_timestamps(): void
{
$file = File::system()->read(Path::testgen().DIRECTORY_SEPARATOR.'Sample.php');

$this->assertStringNotContainsString('Created At', $file);
$this->assertStringNotContainsString('Updated At', $file);
}
}

0 comments on commit 7a2a5ea

Please sign in to comment.