Skip to content

Commit

Permalink
Add File::fromPath()
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Jan 2, 2025
1 parent 2a62d49 commit c7ec226
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Colors/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@

class Profile extends File implements ProfileInterface
{
//
}
12 changes: 12 additions & 0 deletions src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ public function __construct(mixed $data = null)
$this->pointer = $this->buildFilePointer($data);
}

/**
* Create file object from path in file system
*
* @param string $path
* @throws RuntimeException
* @return File
*/
public static function fromPath(string $path): self
{
return new self(fopen($path, 'r'));
}

/**
* {@inheritdoc}
*
Expand Down
7 changes: 7 additions & 0 deletions tests/Unit/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ public function testConstructorFromResource(): void
$this->assertInstanceOf(File::class, $file);
}

public function testFromPath(): void
{
$file = File::fromPath($this->getTestResourcePath());
$this->assertInstanceOf(File::class, $file);
$this->assertTrue($file->size() > 0);
}

public function testSave(): void
{
$filename = __DIR__ . '/file_' . strval(hrtime(true)) . '.test';
Expand Down

0 comments on commit c7ec226

Please sign in to comment.