Skip to content

Commit

Permalink
Fixes type-hinting to Orchestra\Support\Contracts\CsvableInterface.
Browse files Browse the repository at this point in the history
Signed-off-by: crynobone <crynobone@gmail.com>
  • Loading branch information
crynobone committed May 20, 2014
1 parent 373ca6a commit 8e21b1e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/changes.md
Expand Up @@ -5,6 +5,10 @@ title: Facile Change Log

## Version 2.1 {#v2-1}

### v2.1.4 {#v2-1-4}

* Fixes type-hinting to `Orchestra\Support\Contracts\CsvableInterface`.

### v2.1.3 {#v2-1-3}

* Replace `Orchestra\Facile\Container::on()` with `Orchestra\Facile\Container::when()`.
Expand Down
2 changes: 2 additions & 0 deletions src/Facile/Template/Base.php
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\Contracts\ArrayableInterface;
use Illuminate\View\View;
use Orchestra\Support\Collection;
use Orchestra\Support\Contracts\CsvableInterface;

class Base extends Driver
{
Expand Down Expand Up @@ -57,6 +58,7 @@ public function composeHtml($view = null, array $data = array(), $status = 200,
public function composeJson($view, array $data = array(), $status = 200, array $config = array())
{
unset($view);
unset($config);

$data = array_map(array($this, 'transformToArray'), $data);

Expand Down
37 changes: 34 additions & 3 deletions tests/Template/BaseTest.php
Expand Up @@ -86,15 +86,16 @@ public function testComposeJsonMethod()
}

/**
* Test Orchestra\Facile\Template::composeCsv() method.
* Test Orchestra\Facile\Template::composeCsv() method
* given as Illuminate\Support\Contracts\ArrayableInterface.
*
* @test
*/
public function testComposeCsvMethod()
public function testComposeCsvMethodAsArrayableInterface()
{
$view = m::mock('\Illuminate\View\Environment');
$data = array(
'data' => new Collection(array(
'data' => new \Illuminate\Support\Collection(array(
array('id' => 1, 'name' => 'Mior Muhammad Zaki'),
array('id' => 2, 'name' => 'Taylor Otwell'),
)),
Expand All @@ -105,6 +106,36 @@ public function testComposeCsvMethod()
1,"Mior Muhammad Zaki"
2,"Taylor Otwell"
EXPECTED;

$stub = with(new Base($view))->composeCsv(null, $data);

$this->assertInstanceOf('\Illuminate\Http\Response', $stub);
$this->assertEquals($expected, $stub->getContent());
$this->assertEquals('text/csv', $stub->headers->get('content-type'));
}

/**
* Test Orchestra\Facile\Template::composeCsv() method
* given as Orchestra\Support\Contracts\CsvableInterface.
*
* @test
*/
public function testComposeCsvMethodAsCsvableInterface()
{
$view = m::mock('\Illuminate\View\Environment');
$data = array(
'data' => new Collection(array(
array('id' => 1, 'name' => 'Mior Muhammad Zaki'),
array('id' => 2, 'name' => 'Taylor Otwell'),
)),
);

$expected = <<<EXPECTED
id,name
1,"Mior Muhammad Zaki"
2,"Taylor Otwell"
EXPECTED;

$stub = with(new Base($view))->composeCsv(null, $data);
Expand Down

0 comments on commit 8e21b1e

Please sign in to comment.