Skip to content

Commit 5371e70

Browse files
committed
resource::fromFilePath
1 parent e7d2964 commit 5371e70

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

src/Resources/AbstractResource.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,12 @@ public function getHash()
121121
return $this->_hash ?: md5($this->getContent());
122122
}
123123

124+
public static function fromFilePath($filePath)
125+
{
126+
$resource = new static();
127+
$resource->setFilePath($filePath);
128+
$resource->setContent(file_get_contents($filePath));
129+
return $resource;
130+
}
131+
124132
}

tests/DispatchTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function testHandle()
5050
$request = Request::create('/r/f643eb32/css/test.css');
5151
$response = $dispatch->handle($request);
5252
$this->assertEquals(200, $response->getStatusCode());
53-
$this->assertContains('url(r/d41d8cd9/img/x.jpg)', $response->getContent());
53+
$this->assertContains('url(r/d68e763c/img/x.jpg)', $response->getContent());
5454

5555
$request = Request::create('/p/d5dd9dc7/css/placeholder.css');
5656
$response = $dispatch->handle($request);
@@ -74,7 +74,7 @@ public function testBaseUri()
7474
Dispatch::bind($dispatch);
7575
$request = Request::create('/r/f643eb32/css/test.css');
7676
$response = $dispatch->handle($request);
77-
$this->assertContains('url(http://assets.packaged.in/r/d41d8cd9/img/x.jpg)', $response->getContent());
77+
$this->assertContains('url(http://assets.packaged.in/r/d68e763c/img/x.jpg)', $response->getContent());
7878
Dispatch::destroy();
7979
}
8080

tests/Resources/AbstractDispatchableResourceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testProcessesContent()
2222
$resource->setProcessingPath('css/test.css');
2323
$resource->setContent(file_get_contents(Path::system($root, Dispatch::RESOURCES_DIR, 'css', 'test.css')));
2424
$content = $resource->getContent();
25-
$this->assertContains('url(r/d41d8cd9/img/x.jpg)', $content);
25+
$this->assertContains('url(r/d68e763c/img/x.jpg)', $content);
2626
$this->assertContains('url(\'r/d41d8cd9/css/css.jpg\')', $content);
2727
$this->assertContains('url("r/d41d8cd9/css/sub/subimg.jpg")', $content);
2828
$this->assertContains('url(\'http://www.example.com/background.jpg\')', $content);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Packaged\Dispatch\Tests\Resources;
4+
5+
use Packaged\Dispatch\Resources\Image\JpgResource;
6+
use Packaged\Helpers\Path;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class AbstractResourceTest extends TestCase
10+
{
11+
12+
public function testFromFilePath()
13+
{
14+
$jpg = JpgResource::fromFilePath(Path::system(dirname(__DIR__), '_root', 'resources', 'img', 'x.jpg'));
15+
$this->assertEquals('d68e763c825dc0e388929ae1b375ce18', $jpg->getHash());
16+
}
17+
}

tests/_root/resources/img/x.jpg

Whitespace-only changes.

0 commit comments

Comments
 (0)