Skip to content

Commit

Permalink
Merge 5896e81 into f73e513
Browse files Browse the repository at this point in the history
  • Loading branch information
micheh committed Jul 29, 2015
2 parents f73e513 + 5896e81 commit 7542838
Show file tree
Hide file tree
Showing 26 changed files with 436 additions and 534 deletions.
10 changes: 7 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.7/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
<testsuites>
Expand All @@ -18,7 +22,7 @@
</testsuites>

<filter>
<whitelist>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory>./Slim/</directory>
</whitelist>
</filter>
Expand Down
76 changes: 28 additions & 48 deletions tests/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,29 @@
/**
* Slim Framework (http://slimframework.com)
*
* @link https://github.com/codeguy/Slim
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2015 Josh Lockhart
* @license https://github.com/codeguy/Slim/blob/master/LICENSE (MIT License)
* @license https://github.com/slimphp/Slim/blob/master/LICENSE.md (MIT License)
*/

use \Slim\App;
use \Slim\Http\Environment;
use \Slim\Http\Uri;
use \Slim\Http\Body;
use \Slim\Http\Headers;
use \Slim\Http\Request;
use \Slim\Http\Response;

class MockAction
{
public function __call($name, array $arguments)
{
if (count($arguments) !== 3) {
throw new InvalidArgumentException("Not a Slim call");
}

$arguments[1]->write(json_encode(compact('name') + ['arguments' => $arguments[2]]));

return $arguments[1];
}
}

class AppTest extends PHPUnit_Framework_TestCase
namespace Slim\Tests;

use Slim\App;
use Slim\Container;
use Slim\Handlers\Strategies\RequestResponseArgs;
use Slim\Http\Body;
use Slim\Http\Environment;
use Slim\Http\Headers;
use Slim\Http\Request;
use Slim\Http\Response;
use Slim\Http\Uri;
use Slim\Tests\Mocks\MockAction;

class AppTest extends \PHPUnit_Framework_TestCase
{
public function testContainerInterfaceException()
{
$this->setExpectedException('Exception');
try {
$container = '';
$app = new App($container);
} catch (Exception $e) {
$this->assertEquals('Expected a ContainerInterface', $e->getMessage());
throw $e;
}
$this->setExpectedException('InvalidArgumentException', 'Expected a ContainerInterface');
$app = new App('');
}

public function testIssetInContainer()
Expand Down Expand Up @@ -129,7 +113,7 @@ public function testOptionsRoute()
$this->assertInstanceOf('\Slim\Route', $route);
$this->assertAttributeContains('OPTIONS', 'methods', $route);
}

public function testAnyRoute()
{
$path = '/foo';
Expand All @@ -138,7 +122,7 @@ public function testAnyRoute()
};
$app = new App();
$route = $app->any($path, $callable);

$this->assertInstanceOf('\Slim\Route', $route);
$this->assertAttributeContains('GET', 'methods', $route);
$this->assertAttributeContains('POST', 'methods', $route);
Expand All @@ -164,10 +148,6 @@ public function testMapRoute()

public function testGroup()
{
$path = '/foo';
$callable = function ($req, $res) {
// Do something
};
$app = new App();
$app->group('/foo', function () use ($app) {
$route = $app->get('/bar', function ($req, $res) {
Expand Down Expand Up @@ -367,9 +347,9 @@ public function testInvokeWithMatchingRouteWithNamedParameter()

public function testInvokeWithMatchingRouteWithNamedParameterRequestResponseArgStrategy()
{
$c = new \Slim\Container();
$c = new Container();
$c['foundHandler'] = function($c) {
return new \Slim\Handlers\Strategies\RequestResponseArgs();
return new RequestResponseArgs();
};

$app = new App($c);
Expand Down Expand Up @@ -566,7 +546,7 @@ function handle($req, $res) {

return $res;
}
$app->get('/foo', 'handle');
$app->get('/foo', __NAMESPACE__ . '\handle');

// Prepare request and response objects
$env = Environment::mock([
Expand All @@ -583,7 +563,7 @@ function handle($req, $res) {
$res = new Response();

// Invoke app
$resOut = $app($req, $res);
$app($req, $res);

$this->assertEquals('foo', (string)$res->getBody());
}
Expand Down Expand Up @@ -615,12 +595,12 @@ public function testCurrentRequestAttributesAreNotLostWhenAddingRouteArguments()
$resOut = $app($req, $res);
$this->assertEquals('1rob', (string)$resOut->getBody());
}

public function testCurrentRequestAttributesAreNotLostWhenAddingRouteArgumentsRequestResponseArg()
{
$c = new \Slim\Container();
$c = new Container();
$c['foundHandler'] = function() {
return new \Slim\Handlers\Strategies\RequestResponseArgs();
return new RequestResponseArgs();
};

$app = new App($c);
Expand Down Expand Up @@ -663,7 +643,7 @@ public function testInvokeSubRequest()
$this->assertEquals('foo', (string)$subReq->getBody());
$this->assertEquals(200, $newResponse->getStatusCode());
}

public function testInvokeSubRequestWithQuery()
{
$app = new App();
Expand Down
52 changes: 14 additions & 38 deletions tests/CallableResolverTest.php
Original file line number Diff line number Diff line change
@@ -1,49 +1,25 @@
<?php
/**
* Slim - a micro PHP 5 framework
* Slim Framework (http://slimframework.com)
*
* @author Josh Lockhart <info@slimframework.com>
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 2.3.5
*
* MIT LICENSE
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2015 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/master/LICENSE.md (MIT License)
*/
namespace Slim\Tests;

use Slim\CallableResolver;
use Slim\Container;
use Slim\Tests\Mocks\CallableTest;

class CallableTest
class CallableResolverTest extends \PHPUnit_Framework_TestCase
{
public static $CalledCount = 0;
public function toCall()
{
return static::$CalledCount++;
}
}

class CallableResolverTest extends PHPUnit_Framework_TestCase
{
/**
* @var Container
*/
private $container;


public function setUp()
{
Expand All @@ -69,7 +45,7 @@ function test_callable()
static $called_count = 0;
return $called_count++;
};
$resolver = new CallableResolver($this->container, 'test_callable');
$resolver = new CallableResolver($this->container, __NAMESPACE__ . '\test_callable');
$resolver();
$this->assertEquals(1, test_callable());
}
Expand All @@ -84,7 +60,7 @@ public function testObjMethodArray()

public function testSlimCallable()
{
$resolver = new CallableResolver($this->container, 'CallableTest:toCall');
$resolver = new CallableResolver($this->container, 'Slim\Tests\Mocks\CallableTest:toCall');
$resolver();
$this->assertEquals(1, CallableTest::$CalledCount);
}
Expand Down
34 changes: 4 additions & 30 deletions tests/ContainerTest.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,13 @@
<?php
/**
* Slim - a micro PHP 5 framework
* Slim Framework (http://slimframework.com)
*
* @author Josh Lockhart <info@slimframework.com>
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 2.3.5
*
* MIT LICENSE
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* @link https://github.com/slimphp/Slim
* @copyright Copyright (c) 2011-2015 Josh Lockhart
* @license https://github.com/slimphp/Slim/blob/master/LICENSE.md (MIT License)
*/

namespace Slim\Tests;

use Slim\Route;
use Slim\Http\Collection;
use Slim\Container;

class ContainerTest extends \PHPUnit_Framework_TestCase
Expand Down
7 changes: 0 additions & 7 deletions tests/Foo.php

This file was deleted.

0 comments on commit 7542838

Please sign in to comment.