Skip to content

Commit

Permalink
Added method FileInfoInterface::toArray()
Browse files Browse the repository at this point in the history
  • Loading branch information
tg666 committed Mar 12, 2024
1 parent e46f6ce commit 59b9832
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,17 @@ public function __toString(): string
return $this->link();
}

public function jsonSerialize(): array
public function toArray(): array
{
return [
'path' => $this->pathInfo->getPath(),
'storage' => $this->getStorageName(),
'version' => $this->pathInfo->getVersion(),
];
}

public function jsonSerialize(): array
{
return $this->toArray();
}
}
5 changes: 5 additions & 0 deletions src/FileInfoInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public function getStorageName(): string;

public function link(): string;

/**
* @return array{path: string, storage: string, version: ?string}
*/
public function toArray(): array;

/**
* @return array{path: string, storage: string, version: ?string}
*/
Expand Down
25 changes: 25 additions & 0 deletions tests/FileInfoTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,31 @@ final class FileInfoTest extends TestCase
Assert::same('https://www.example.com/files/file.json', $fileInfo->link());
}

public function testFileInfoShouldBeConvertedToArray(): void
{
$linkGenerator = Mockery::mock(LinkGeneratorInterface::class);
$pathInfo = Mockery::mock(PathInfoInterface::class);

$pathInfo->shouldReceive('getPath')
->once()
->andReturn('var/www/file.json');

$pathInfo->shouldReceive('getVersion')
->once()
->andReturn('123');

$fileInfo = new FileInfo($linkGenerator, $pathInfo, 'default');

Assert::same(
[
'path' => 'var/www/file.json',
'storage' => 'default',
'version' => '123',
],
$fileInfo->toArray(),
);
}

public function testFileInfoShouldBeSerializedIntoJson(): void
{
$linkGenerator = Mockery::mock(LinkGeneratorInterface::class);
Expand Down

0 comments on commit 59b9832

Please sign in to comment.