Skip to content

Commit

Permalink
Create Action class to find Image content lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed May 20, 2022
1 parent 3b8cf08 commit 911a0da
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Actions/FindsContentLengthForImageObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Hyde\Framework\Actions;

use Hyde\Framework\Contracts\ActionContract;
use Hyde\Framework\Models\Image;

/**
* @see \Tests\Feature\FindsContentLengthForImageObjectTest
*/
class FindsContentLengthForImageObject implements ActionContract
{
protected Image $image;

public function __construct(Image $image)
{
$this->image = $image;
}

public function execute(): int
{
return 0;
}
}
7 changes: 7 additions & 0 deletions src/Models/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Hyde\Framework\Models;

use Hyde\Framework\Actions\FindsContentLengthForImageObject;

/**
* Holds the information for an image.
*/
Expand Down Expand Up @@ -98,6 +100,11 @@ public function getSource(): ?string
return $this->uri ?? $this->path ?? null;
}

public function getContentLength(): int
{
return (new FindsContentLengthForImageObject($this))->execute();
}

public function getImageAuthorAttributionString(): ?string
{
if (isset($this->author)) {
Expand Down
25 changes: 25 additions & 0 deletions tests/Feature/FindsContentLengthForImageObjectTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Tests\Feature;

use Hyde\Framework\Actions\FindsContentLengthForImageObject;
use Hyde\Framework\Models\Image;
use Tests\TestCase;

/**
* @covers \Hyde\Framework\Actions\FindsContentLengthForImageObject
*/
class FindsContentLengthForImageObjectTest extends TestCase
{
// Test Image helper shorthand returns content length
/**
* Unit test for the shorthand. Logic is tested in the rest of the case.
* @covers \Hyde\Framework\Models\Image::getContentLength
*/
public function test_image_helper_shorthand_returns_content_length()
{
$this->assertIsInt(
(new Image())->getContentLength()
);
}
}

0 comments on commit 911a0da

Please sign in to comment.