Skip to content

PSR-2 in tests #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
},
"autoload": {
"psr-4": {
"Laravel\\Lumen\\": "src/"
"Laravel\\Lumen\\": "src/",
"Laravel\\Lumen\\Tests\\": "tests/"
},
"classmap": [
"src/Foundation"
Expand Down
64 changes: 26 additions & 38 deletions tests/FullApplicationTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php
namespace Laravel\Lumen\Tests;

use Mockery as m;
use Illuminate\Http\Request;
use Laravel\Lumen\Application;
use PHPUnit_Framework_TestCase;

class ExampleTest extends PHPUnit_Framework_TestCase
class FullApplicationTest extends PHPUnit_Framework_TestCase
{
public function tearDown()
{
Expand All @@ -31,7 +33,7 @@ public function testGlobalMiddleware()
{
$app = new Application;

$app->middleware(['LumenTestMiddleware']);
$app->middleware(['Laravel\Lumen\Tests\LumenTestMiddleware']);

$app->get('/', function () {
return response('Hello World');
Expand All @@ -48,13 +50,13 @@ public function testRouteMiddleware()
{
$app = new Application;

$app->routeMiddleware(['foo' => 'LumenTestMiddleware']);
$app->routeMiddleware(['foo' => 'Laravel\Lumen\Tests\LumenTestMiddleware']);

$app->get('/', function () {
return response('Hello World');
});

$app->get('/foo', ['middleware' => 'foo', function() {
$app->get('/foo', ['middleware' => 'foo', function () {
return response('Hello World');
}]);

Expand All @@ -72,15 +74,15 @@ public function testGroupRouteMiddleware()
{
$app = new Application;

$app->routeMiddleware(['foo' => 'LumenTestMiddleware']);
$app->routeMiddleware(['foo' => 'Laravel\Lumen\Tests\LumenTestMiddleware']);

$app->group(['middleware' => 'foo'], function($app) {
$app->group(['middleware' => 'foo'], function ($app) {
$app->get('/', function () {
return response('Hello World');
});
});

$app->get('/foo', function() {
$app->get('/foo', function () {
return response('Hello World');
});

Expand All @@ -97,7 +99,10 @@ public function testGroupRouteMiddleware()
public function testNotFoundResponse()
{
$app = new Application;
$app->instance('Illuminate\Contracts\Debug\ExceptionHandler', $mock = m::mock('Laravel\Lumen\Exceptions\Handler[report]'));
$app->instance(
'Illuminate\Contracts\Debug\ExceptionHandler',
$mock = m::mock('Laravel\Lumen\Exceptions\Handler[report]')
);
$mock->shouldIgnoreMissing();

$app->get('/', function () {
Expand All @@ -113,7 +118,10 @@ public function testNotFoundResponse()
public function testMethodNotAllowedResponse()
{
$app = new Application;
$app->instance('Illuminate\Contracts\Debug\ExceptionHandler', $mock = m::mock('Laravel\Lumen\Exceptions\Handler[report]'));
$app->instance(
'Illuminate\Contracts\Debug\ExceptionHandler',
$mock = m::mock('Laravel\Lumen\Exceptions\Handler[report]')
);
$mock->shouldIgnoreMissing();

$app->post('/', function () {
Expand All @@ -130,29 +138,27 @@ public function testControllerResponse()
{
$app = new Application;

$app->get('/', 'LumenTestController@action');
$app->get('/', 'Laravel\Lumen\Tests\LumenTestController@action');

$response = $app->handle(Request::create('/', 'GET'));

$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('LumenTestController', $response->getContent());
$this->assertEquals('Laravel\Lumen\Tests\LumenTestController', $response->getContent());
}


public function testNamespacedControllerResponse()
{
$app = new Application;

require_once __DIR__.'/fixtures/TestController.php';

$app->group(['namespace' => 'Lumen\Tests'], function($app) {
$app->group(['namespace' => 'Laravel\Lumen\Tests'], function ($app) {
$app->get('/', 'TestController@action');
});

$response = $app->handle(Request::create('/', 'GET'));

$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('Lumen\Tests\TestController', $response->getContent());
$this->assertEquals('Laravel\Lumen\Tests\TestController', $response->getContent());
}


Expand All @@ -162,11 +168,11 @@ public function testGeneratingUrls()
$app->instance('request', Request::create('http://lumen.com', 'GET'));
unset($app->availableBindings['request']);

$app->get('/foo-bar', ['as' => 'foo', function() {
$app->get('/foo-bar', ['as' => 'foo', function () {
//
}]);

$app->get('/foo-bar/{baz}/{boom}', ['as' => 'bar', function() {
$app->get('/foo-bar/{baz}/{boom}', ['as' => 'bar', function () {
//
}]);

Expand All @@ -182,15 +188,15 @@ public function testGeneratingUrlsForRegexParameters()
$app->instance('request', Request::create('http://lumen.com', 'GET'));
unset($app->availableBindings['request']);

$app->get('/foo-bar', ['as' => 'foo', function() {
$app->get('/foo-bar', ['as' => 'foo', function () {
//
}]);

$app->get('/foo-bar/{baz:[0-9]+}/{boom}', ['as' => 'bar', function() {
$app->get('/foo-bar/{baz:[0-9]+}/{boom}', ['as' => 'bar', function () {
//
}]);

$app->get('/foo-bar/{baz:[0-9]+}/{boom:[0-9]+}', ['as' => 'baz', function() {
$app->get('/foo-bar/{baz:[0-9]+}/{boom:[0-9]+}', ['as' => 'baz', function () {
//
}]);

Expand All @@ -200,21 +206,3 @@ public function testGeneratingUrlsForRegexParameters()
$this->assertEquals('http://lumen.com/foo-bar/1/2', route('baz', ['baz' => 1, 'boom' => 2]));
}
}

class LumenTestService {}

class LumenTestMiddleware {
public function handle($request, $next) {
return response('Middleware');
}
}

class LumenTestController {
public $service;
public function __construct(LumenTestService $service) {
$this->service = $service;
}
public function action() {
return response(__CLASS__);
}
}
15 changes: 15 additions & 0 deletions tests/LumenTestController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
namespace Laravel\Lumen\Tests;

class LumenTestController
{
public $service;
public function __construct(LumenTestService $service)
{
$this->service = $service;
}
public function action()
{
return response(__CLASS__);
}
}
10 changes: 10 additions & 0 deletions tests/LumenTestMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace Laravel\Lumen\Tests;

class LumenTestMiddleware
{
public function handle($request, $next)
{
return response('Middleware');
}
}
6 changes: 6 additions & 0 deletions tests/LumenTestService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
namespace Laravel\Lumen\Tests;

class LumenTestService
{
}
9 changes: 9 additions & 0 deletions tests/TestController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php namespace Laravel\Lumen\Tests;

class TestController
{
public function action()
{
return __CLASS__;
}
}
7 changes: 0 additions & 7 deletions tests/fixtures/TestController.php

This file was deleted.