diff --git a/src/Dto/BackupObj.php b/src/Dto/BackupObj.php index d08c13e..f587391 100644 --- a/src/Dto/BackupObj.php +++ b/src/Dto/BackupObj.php @@ -32,8 +32,8 @@ public function toArray(): array return [ 'real_name' => $this->name, 'name' => $this->name, - 'created_at' => Carbon::createFromTimestamp($this->createdAt)->format(config('env-editor.timeFormat')), - 'modified_at' => Carbon::createFromTimestamp($this->modifiedAt)->format(config('env-editor.timeFormat')), + 'created_at' => $this->createdAt->format(config('env-editor.timeFormat')), + 'modified_at' => $this->modifiedAt->format(config('env-editor.timeFormat')), 'raw_content' => $this->rawContent, 'path' => $this->path, 'entries' => $this->entries->toArray(), diff --git a/tests/Unit/Dto/BackupObjTest.php b/tests/Unit/Dto/BackupObjTest.php new file mode 100644 index 0000000..0ff6a0c --- /dev/null +++ b/tests/Unit/Dto/BackupObjTest.php @@ -0,0 +1,45 @@ +app['config']->set('env-editor.timeFormat', 'd/m H:i'); + $this->freezeTime(); + $now = now(); + + $data = [ + 'name' => 'foo-file', + 'createdAt' => $now->clone()->subHour(), + 'modifiedAt' => $now->clone(), + 'rawContent' => 'dummy-content', + 'path' => 'foo-path', + 'entries' => new Collection([ + new EntryObj('key', + 'value', 1, 1), + ]), + ]; + + $dto = new BackupObj(...$data); + + $expected = [ + 'name' => 'foo-file', + 'real_name' => 'foo-file', + 'created_at' => $now->clone()->subHour()->format('d/m H:i'), + 'modified_at' => $now->clone()->format('d/m H:i'), + 'raw_content' => 'dummy-content', + 'path' => 'foo-path', + 'entries' => $data['entries']->toArray(), + ]; + $this->assertEquals($expected, $dto->jsonSerialize()); + } +} diff --git a/tests/Unit/Helpers/EntryObjTest.php b/tests/Unit/Dto/EntryObjTest.php similarity index 97% rename from tests/Unit/Helpers/EntryObjTest.php rename to tests/Unit/Dto/EntryObjTest.php index fb0e2f5..a95ef82 100644 --- a/tests/Unit/Helpers/EntryObjTest.php +++ b/tests/Unit/Dto/EntryObjTest.php @@ -1,6 +1,6 @@ getAllBackUps(); $this->assertEquals(1, $backUps->count()); - $this->assertEquals($backUps->first()->rawContent, $content); + $backup = $backUps->first(); + $this->assertInstanceOf(Collection::class, $backup->entries); + $this->assertInstanceOf(EntryObj::class, $backup->entries->first()); + $this->assertEquals($backup->rawContent, $content); unlink($file); }