Skip to content

Commit

Permalink
Fixes testcase.
Browse files Browse the repository at this point in the history
Signed-off-by: crynobone <crynobone@gmail.com>
  • Loading branch information
crynobone committed Oct 8, 2015
1 parent ab2c3a1 commit e1f27e0
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 67 deletions.
2 changes: 1 addition & 1 deletion src/Template/Simple.php
Expand Up @@ -75,7 +75,7 @@ public function composeCsv($view = null, array $data = [], $status = 200, array
public function composeHtml($view = null, array $data = [], $status = 200, array $config = [])
{
if (! isset($view)) {
throw new InvalidArgumentException("Missing [\$view].");
throw new InvalidArgumentException('Missing [$view].');
}

if (! $view instanceof View) {
Expand Down
2 changes: 2 additions & 0 deletions src/Template/Template.php
Expand Up @@ -33,6 +33,7 @@ abstract class Template
* Default format.
*
* @var string
*
* @deprecated 3.1
*/
protected $defaultFormat = 'html';
Expand All @@ -53,6 +54,7 @@ public function __construct(Factory $view, Transformable $transformable = null)
* Get default format.
*
* @return string
*
* @deprecated 3.1
*/
public function getDefaultFormat()
Expand Down
59 changes: 31 additions & 28 deletions tests/FacileTest.php
Expand Up @@ -23,7 +23,7 @@ public function tearDown()
public function testConstructMethod()
{
$request = m::mock('\Illuminate\Http\Request');
$view = m::mock('\Illuminate\Contracts\View\Factory');
$view = m::mock('\Illuminate\Contracts\View\Factory');

$stub = new Facile(new Factory($request), new Simple($view), [], 'json');

Expand All @@ -32,13 +32,14 @@ public function testConstructMethod()
$data->setAccessible(true);

$expected = [
'view' => null,
'data' => [],
'view' => null,
'data' => [],
'status' => 200,
'on' => [
'on' => [
'csv' => ['only' => null, 'except' => null, 'uses' => 'data'],
'html' => ['only' => null, 'except' => null],
'json' => ['only' => null, 'except' => null],
'csv' => ['uses' => 'data'],
'xml' => ['only' => null, 'except' => null, 'root' => null],
],
];

Expand All @@ -53,7 +54,7 @@ public function testConstructMethod()
public function testViewMethod()
{
$request = m::mock('\Illuminate\Http\Request');
$view = m::mock('\Illuminate\Contracts\View\Factory');
$view = m::mock('\Illuminate\Contracts\View\Factory');

$stub = new Facile(new Factory($request), new Simple($view), [], 'json');

Expand All @@ -77,7 +78,7 @@ public function testViewMethod()
public function testWhenMethod($before, $after)
{
$request = m::mock('\Illuminate\Http\Request');
$view = m::mock('\Illuminate\Contracts\View\Factory');
$view = m::mock('\Illuminate\Contracts\View\Factory');

$stub = new Facile(new Factory($request), new Simple($view), [], 'json');

Expand All @@ -101,7 +102,7 @@ public function testWhenMethod($before, $after)
public function testOnMethod($before, $after)
{
$request = m::mock('\Illuminate\Http\Request');
$view = m::mock('\Illuminate\Contracts\View\Factory');
$view = m::mock('\Illuminate\Contracts\View\Factory');

$stub = new Facile(new Factory($request), new Simple($view), [], 'json');

Expand All @@ -124,7 +125,7 @@ public function testOnMethod($before, $after)
public function testWithMethod()
{
$request = m::mock('\Illuminate\Http\Request');
$view = m::mock('\Illuminate\Contracts\View\Factory');
$view = m::mock('\Illuminate\Contracts\View\Factory');

$stub = new Facile(new Factory($request), new Simple($view), [], 'json');

Expand All @@ -148,7 +149,7 @@ public function testWithMethod()
public function testStatusMethod()
{
$request = m::mock('\Illuminate\Http\Request');
$view = m::mock('\Illuminate\Contracts\View\Factory');
$view = m::mock('\Illuminate\Contracts\View\Factory');

$stub = new Facile(new Factory($request), new Simple($view), [], 'json');

Expand All @@ -170,10 +171,10 @@ public function testStatusMethod()
*/
public function testTemplateMethod()
{
$request = m::mock('\Illuminate\Http\Request');
$view = m::mock('\Illuminate\Contracts\View\Factory');
$request = m::mock('\Illuminate\Http\Request');
$view = m::mock('\Illuminate\Contracts\View\Factory');

$env = new Factory($request);
$env = new Factory($request);
$template = new Simple($view);

$env->template('foo', $template);
Expand All @@ -182,15 +183,15 @@ public function testTemplateMethod()

$stub->template('foo');

$refl = new \ReflectionObject($stub);
$refl = new \ReflectionObject($stub);
$template = $refl->getProperty('template');
$template->setAccessible(true);

$this->assertEquals('foo', $template->getValue($stub));

$stub->template(new Simple($view));

$refl = new \ReflectionObject($stub);
$refl = new \ReflectionObject($stub);
$template = $refl->getProperty('template');
$template->setAccessible(true);

Expand All @@ -204,7 +205,7 @@ public function testTemplateMethod()
*/
public function testFormatMethod()
{
$request = m::mock('\Illuminate\Http\Request');
$request = m::mock('\Illuminate\Http\Request');
$template = m::mock('\Orchestra\Facile\Template\Simple');

$request->shouldReceive('prefers')->once()->with('jsonp')->andReturn('jsonp');
Expand All @@ -216,7 +217,7 @@ public function testFormatMethod()

$stub->format('md');

$refl = new \ReflectionObject($stub);
$refl = new \ReflectionObject($stub);
$format = $refl->getProperty('format');
$format->setAccessible(true);

Expand All @@ -230,7 +231,7 @@ public function testFormatMethod()
*/
public function testRenderMethod()
{
$request = m::mock('\Illuminate\Http\Request');
$request = m::mock('\Illuminate\Http\Request');
$template = m::mock('\Orchestra\Facile\Template\Simple');

$request->shouldReceive('prefers')->once()->with('jsonp')->andReturn('jsonp');
Expand All @@ -249,7 +250,7 @@ public function testRenderMethod()
*/
public function testToStringMethod()
{
$request = m::mock('\Illuminate\Http\Request');
$request = m::mock('\Illuminate\Http\Request');
$template1 = m::mock('\Orchestra\Facile\Template\Simple');

$template1->shouldReceive('compose')->once()
Expand Down Expand Up @@ -288,24 +289,26 @@ public function dataProviderForWhenTest()
return [
[
[
'view' => null,
'data' => [],
'view' => null,
'data' => [],
'status' => 200,
'on' => [
'on' => [
'csv' => ['only' => null, 'except' => null, 'uses' => 'data'],
'html' => ['only' => null, 'except' => null],
'json' => ['only' => null, 'except' => null],
'csv' => ['uses' => 'data'],
'xml' => ['only' => null, 'except' => null, 'root' => null],
],
],
[
'view' => null,
'data' => [],
'view' => null,
'data' => [],
'status' => 200,
'on' => [
'on' => [
'csv' => ['only' => null, 'except' => null, 'uses' => 'data'],
'html' => ['only' => null, 'except' => null],
'json' => ['only' => null, 'except' => null],
'csv' => ['uses' => 'data'],
'foo' => ['uses' => 'foobar'],
'xml' => ['only' => null, 'except' => null, 'root' => null],
'foo' => ['uses' => 'foobar'],
],
],
],
Expand Down
39 changes: 21 additions & 18 deletions tests/FactoryTest.php
Expand Up @@ -24,7 +24,7 @@ public function testConstructMethod()

$stub = new Factory($request);

$refl = new \ReflectionObject($stub);
$refl = new \ReflectionObject($stub);
$templates = $refl->getProperty('templates');
$templates->setAccessible(true);

Expand All @@ -38,7 +38,7 @@ public function testConstructMethod()
*/
public function testMakeMethod()
{
$request = m::mock('\Illuminate\Http\Request');
$request = m::mock('\Illuminate\Http\Request');
$template = m::mock('\Orchestra\Facile\Template\Template');

$template->shouldReceive('compose')->once()->with('json', m::any())->andReturn('foo');
Expand All @@ -56,13 +56,14 @@ public function testMakeMethod()
$data->setAccessible(true);

$expected = [
'view' => null,
'data' => ['foo' => 'foo is awesome'],
'view' => null,
'data' => ['foo' => 'foo is awesome'],
'status' => 200,
'on' => [
'on' => [
'csv' => ['only' => null, 'except' => null, 'uses' => 'data'],
'html' => ['only' => null, 'except' => null],
'json' => ['only' => null, 'except' => null],
'csv' => ['uses' => 'data'],
'xml' => ['only' => null, 'except' => null, 'root' => null],
],
];

Expand All @@ -78,7 +79,7 @@ public function testMakeMethod()
*/
public function testViewMethod()
{
$request = m::mock('\Illuminate\Http\Request');
$request = m::mock('\Illuminate\Http\Request');
$template = m::mock('\Orchestra\Facile\Template\Template');

$request->shouldReceive('prefers')->once()->with('html')->andReturn('html');
Expand All @@ -97,13 +98,14 @@ public function testViewMethod()
$data->setAccessible(true);

$expected = [
'view' => 'foo.bar',
'data' => ['foo' => 'foo is awesome'],
'view' => 'foo.bar',
'data' => ['foo' => 'foo is awesome'],
'status' => 200,
'on' => [
'on' => [
'csv' => ['only' => null, 'except' => null, 'uses' => 'data'],
'html' => ['only' => null, 'except' => null],
'json' => ['only' => null, 'except' => null],
'csv' => ['uses' => 'data'],
'xml' => ['only' => null, 'except' => null, 'root' => null],
],
];

Expand All @@ -119,7 +121,7 @@ public function testViewMethod()
*/
public function testWithMethod()
{
$request = m::mock('\Illuminate\Http\Request');
$request = m::mock('\Illuminate\Http\Request');
$template = m::mock('TemplateDriver', '\Orchestra\Facile\Template\Template');

$request->shouldReceive('prefers')->once()->with('html')->andReturn('html');
Expand All @@ -139,13 +141,14 @@ public function testWithMethod()
$data->setAccessible(true);

$expected = [
'view' => null,
'data' => ['foo' => 'foo is awesome'],
'view' => null,
'data' => ['foo' => 'foo is awesome'],
'status' => 200,
'on' => [
'on' => [
'csv' => ['only' => null, 'except' => null, 'uses' => 'data'],
'html' => ['only' => null, 'except' => null],
'json' => ['only' => null, 'except' => null],
'csv' => ['uses' => 'data'],
'xml' => ['only' => null, 'except' => null, 'root' => null],
],
];

Expand All @@ -165,7 +168,7 @@ public function testTemplateMethod()

$stub = new Factory($request);

$refl = new \ReflectionObject($stub);
$refl = new \ReflectionObject($stub);
$templates = $refl->getProperty('templates');
$templates->setAccessible(true);

Expand All @@ -183,7 +186,7 @@ public function testTemplateMethod()
*/
public function testTemplateMethodThrowsException()
{
$request = m::mock('\Illuminate\Http\Request');
$request = m::mock('\Illuminate\Http\Request');
$template = m::mock('BadFooTemplateStub');

$stub = new Factory($request);
Expand Down
2 changes: 1 addition & 1 deletion tests/Template/SimpleTest.php
Expand Up @@ -26,7 +26,7 @@ public function testConstructMethod()
$stub = new Simple($view);
$refl = new \ReflectionObject($stub);

$formats = $refl->getProperty('formats');
$formats = $refl->getProperty('formats');
$defaultFormat = $refl->getProperty('defaultFormat');

$formats->setAccessible(true);
Expand Down

0 comments on commit e1f27e0

Please sign in to comment.