Skip to content

Commit

Permalink
Fix a bug of hasTimestamps() method in ModelGenerator class
Browse files Browse the repository at this point in the history
  • Loading branch information
cable8mm committed Jan 6, 2025
1 parent d4ad05f commit ceb012f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ public function migration(): string
*/
public function hasTimestamps(): bool
{
return in_array('created_at', array_column($this->columns, 'field')) && in_array('updated_at', array_column($this->columns, 'field'));
return ! (
in_array('created_at', array_column($this->columns, 'field')) &&
in_array('updated_at', array_column($this->columns, 'field'))
);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Generators/ModelGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function test_it_can_generate_timestamps(): void
{
$file = File::system()->read(Path::testgen().DIRECTORY_SEPARATOR.'Sample.php');

$this->assertStringContainsString('timestamps', $file);
$this->assertStringNotContainsString('timestamps', $file);
}

public function test_it_can_generate_without_timestamps(): void
Expand All @@ -53,6 +53,6 @@ public function test_it_can_generate_without_timestamps(): void

$file = File::system()->read(Path::testgen().DIRECTORY_SEPARATOR.'Sample.php');

$this->assertStringNotContainsString('timestamps', $file);
$this->assertStringContainsString('timestamps', $file);
}
}
4 changes: 4 additions & 0 deletions tests/Unit/Generators/RelationGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ protected function setUp(): void
$this->table = new Table('samples', [
Column::make('id', 'bigInteger'),
Column::make('related_id', 'bigInteger'),
Column::make('created_at', 'timestamp'),
Column::make('updated_at', 'timestamp'),
], [
ForeignKey::make('samples_related_fk', 'Sample', 'related_id', 'Related', 'id'),
]);

$this->related = new Table('related', [
Column::make('id', 'bigInteger'),
Column::make('created_at', 'timestamp'),
Column::make('updated_at', 'timestamp'),
]);

ModelGenerator::make(
Expand Down

0 comments on commit ceb012f

Please sign in to comment.