Skip to content

Commit

Permalink
Merge pull request #559 from chikaldirick/feature/add-file-get-extens…
Browse files Browse the repository at this point in the history
…ion-method

Add 'getExtension' method to the File class hydephp/develop@8270e45
  • Loading branch information
github-actions committed Oct 8, 2022
1 parent d34fd8f commit 9bfed79
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Models/Support/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public function getMimeType(): string
return 'text/plain';
}

public function getExtension(): string
{
return pathinfo($this->path, PATHINFO_EXTENSION);
}

/** @inheritDoc */
public function toArray(): array
{
Expand Down
9 changes: 9 additions & 0 deletions tests/Feature/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ public function test_get_content_length_returns_length_of_file()
$this->assertSame(7, File::make('foo.txt')->getContentLength());
}

public function test_get_extension_returns_extension_of_file()
{
$this->file('foo.txt', 'foo');
$this->assertSame('txt', File::make('foo.txt')->getExtension());

$this->file('foo.png', 'foo');
$this->assertSame('png', File::make('foo.png')->getExtension());
}

public function test_get_mime_type_returns_mime_type_of_file_using_lookup_table()
{
$lookup = [
Expand Down

0 comments on commit 9bfed79

Please sign in to comment.