Skip to content

Commit 240bada

Browse files
author
Andy Wermke
committed
Added separate StaticFileResponse text + testing the provides() method of the service provider.
1 parent b0b6e32 commit 240bada

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

tests/JsLocalization/JsLocalizationServiceProviderTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ protected function getPackageProviders()
1212
return array('JsLocalization\JsLocalizationServiceProvider');
1313
}
1414

15+
16+
public function testProvidesArray () {
17+
$service = new JsLocalization\JsLocalizationServiceProvider($this->app);
18+
19+
$this->assertEquals( $service->provides(), array('js-localization') );
20+
}
21+
1522
public function testRegisteredNamespaces ()
1623
{
1724
$this->assertArrayHasKey(
@@ -44,4 +51,4 @@ public function testBindings ()
4451
$this->assertInstanceOf('JsLocalization\CachingService', $cachingService);
4552
}
4653

47-
}
54+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\File;
4+
use JsLocalization\StaticFileResponse;
5+
6+
class StaticFileResponseTest extends TestCase
7+
{
8+
protected $testFilePath, $testFileContent;
9+
10+
public function setUp ()
11+
{
12+
parent::setUp();
13+
14+
$this->testFilePath = "/tmp/laravel-static";
15+
$this->testFileContent = "Test contents!";
16+
17+
File::put($this->testFilePath, $this->testFileContent);
18+
}
19+
20+
public function testServingFile ()
21+
{
22+
$response = new StaticFileResponse($this->testFilePath);
23+
24+
$lastModified = new DateTime();
25+
$lastModified->setTimestamp( File::lastModified($this->testFilePath) );
26+
27+
$this->assertEquals($response->getStatusCode(), 200);
28+
$this->assertEquals($response->getContent(), $this->testFileContent);
29+
$this->assertEquals($response->getLastModified()->getTimestamp(), $lastModified->getTimestamp());
30+
}
31+
32+
public function testExceptionHandling ()
33+
{
34+
$filePath = "/tmp/x/y/z/does-not-exist";
35+
$this->setExpectedException('Exception', "Cannot read file: $filePath");
36+
37+
$response = new StaticFileResponse($filePath);
38+
}
39+
}
40+
?>

0 commit comments

Comments
 (0)