Skip to content

Commit

Permalink
Merge branch 'PR2191' into 4.x
Browse files Browse the repository at this point in the history
Closes #2191
  • Loading branch information
akrabat committed Apr 17, 2017
2 parents 63de022 + 4062311 commit 54401a4
Show file tree
Hide file tree
Showing 25 changed files with 145 additions and 81 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"require-dev": {
"squizlabs/php_codesniffer": "^2.5",
"phpunit/phpunit": "^5.0"
"phpunit/phpunit": "^5.7|^6.0"
},
"provide": {
"psr/http-message-implementation": "1.0"
Expand Down
8 changes: 5 additions & 3 deletions tests/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Slim\Tests;

use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
use Slim\App;
use Slim\Exception\MethodNotAllowedException;
Expand All @@ -24,7 +25,7 @@
use Slim\Router;
use Slim\Tests\Mocks\MockAction;

class AppTest extends \PHPUnit_Framework_TestCase
class AppTest extends TestCase
{
public static function setupBeforeClass()
{
Expand Down Expand Up @@ -1275,6 +1276,9 @@ public function testInvokeWithPimpleCallable()
$this->assertEquals('Hello', (string)$res->getBody());
}

/**
* @expectedException \RuntimeException
*/
public function testInvokeWithPimpleUndefinedCallable()
{
// Prepare request and response objects
Expand All @@ -1301,8 +1305,6 @@ public function testInvokeWithPimpleUndefinedCallable()

$app->get('/foo', 'foo:bar');

$this->setExpectedException('\RuntimeException');

// Invoke app
$app($req, $res);
}
Expand Down
21 changes: 16 additions & 5 deletions tests/CallableResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
*/
namespace Slim\Tests;

use PHPUnit\Framework\TestCase;
use Slim\CallableResolver;
use Slim\Container;
use Slim\Tests\Mocks\CallableTest;
use Slim\Tests\Mocks\InvokableTest;

class CallableResolverTest extends \PHPUnit_Framework_TestCase
class CallableResolverTest extends TestCase
{
/**
* @var Container
Expand Down Expand Up @@ -107,32 +108,42 @@ public function testResolutionToAnInvokableClass()
$this->assertEquals(1, InvokableTest::$CalledCount);
}

/**
* @expectedException \RuntimeException
*/
public function testMethodNotFoundThrowException()
{
$this->container['callable_service'] = new CallableTest();
$resolver = new CallableResolver($this->container);
$this->setExpectedException('\RuntimeException');
$resolver->resolve('callable_service:noFound');
}

/**
* @expectedException \RuntimeException
*/
public function testFunctionNotFoundThrowException()
{
$resolver = new CallableResolver($this->container);
$this->setExpectedException('\RuntimeException');
$resolver->resolve('noFound');
}

/**
* @expectedException \RuntimeException
* @expectedExceptionMessage Callable Unknown does not exist
*/
public function testClassNotFoundThrowException()
{
$resolver = new CallableResolver($this->container);
$this->setExpectedException('\RuntimeException', 'Callable Unknown does not exist');
$resolver->resolve('Unknown:notFound');
}

/**
* @expectedException \RuntimeException
* @expectedExceptionMessage is not resolvable
*/
public function testCallableClassNotFoundThrowException()
{
$resolver = new CallableResolver($this->container);
$this->setExpectedException('\RuntimeException', 'is not resolvable');
$resolver->resolve(['Unknown', 'notFound']);
}
}
3 changes: 2 additions & 1 deletion tests/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
*/
namespace Slim\Tests;

use PHPUnit\Framework\TestCase;
use ReflectionProperty;
use Slim\Collection;

class CollectionTest extends \PHPUnit_Framework_TestCase
class CollectionTest extends TestCase
{
/**
* @var Collection
Expand Down
3 changes: 2 additions & 1 deletion tests/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
*/
namespace Slim\Tests;

use PHPUnit\Framework\TestCase;
use Slim\Container;
use Interop\Container\ContainerInterface;

class ContainerTest extends \PHPUnit_Framework_TestCase
class ContainerTest extends TestCase
{
/**
* @var Container
Expand Down
3 changes: 2 additions & 1 deletion tests/DeferredCallableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

namespace Slim\Tests;

use PHPUnit\Framework\TestCase;
use Slim\CallableResolver;
use Slim\Container;
use Slim\DeferredCallable;
use Slim\Tests\Mocks\CallableTest;

class DeferredCallableTest extends \PHPUnit_Framework_TestCase
class DeferredCallableTest extends TestCase
{
public function testItResolvesCallable()
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Handlers/AbstractHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
*/
namespace Slim\Tests\Handlers;

use PHPUnit\Framework\TestCase;
use Slim\Handlers\AbstractHandler;

class AbstractHandlerTest extends \PHPUnit_Framework_TestCase
class AbstractHandlerTest extends TestCase
{
public function testHalfValidContentType()
{
Expand Down
11 changes: 7 additions & 4 deletions tests/Handlers/ErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
*/
namespace Slim\Tests\Handlers;

use PHPUnit\Framework\TestCase;
use Slim\Handlers\Error;
use Slim\Http\Response;

class ErrorTest extends \PHPUnit_Framework_TestCase
class ErrorTest extends TestCase
{
public function errorProvider()
{
Expand Down Expand Up @@ -61,6 +62,9 @@ public function testErrorDisplayDetails($acceptHeader, $contentType, $startOfBod
$this->assertEquals(0, strpos((string)$res->getBody(), $startOfBody));
}

/**
* @expectedException \UnexpectedValueException
*/
public function testNotFoundContentType()
{
$errorMock = $this->getMockBuilder(Error::class)->setMethods(['determineContentType'])->getMock();
Expand All @@ -71,7 +75,6 @@ public function testNotFoundContentType()

$req = $this->getMockBuilder('Slim\Http\Request')->disableOriginalConstructor()->getMock();

$this->setExpectedException('\UnexpectedValueException');
$errorMock->__invoke($req, new Response(), $e);
}

Expand All @@ -98,15 +101,15 @@ public function testPreviousException()
/**
* If someone extends the Error handler and calls renderHtmlExceptionOrError with
* a parameter that isn't an Exception or Error, then we thrown an Exception.
*
* @expectedException \RuntimeException
*/
public function testRenderHtmlExceptionorErrorTypeChecksParameter()
{
$class = new \ReflectionClass(Error::class);
$renderHtmlExceptionorError = $class->getMethod('renderHtmlExceptionOrError');
$renderHtmlExceptionorError->setAccessible(true);

$this->setExpectedException(\RuntimeException::class);

$error = new Error();
$renderHtmlExceptionorError->invokeArgs($error, ['foo']);
}
Expand Down
7 changes: 5 additions & 2 deletions tests/Handlers/NotAllowedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
*/
namespace Slim\Tests\Handlers;

use PHPUnit\Framework\TestCase;
use Slim\Handlers\NotAllowed;
use Slim\Http\Response;

class NotAllowedTest extends \PHPUnit_Framework_TestCase
class NotAllowedTest extends TestCase
{
public function invalidMethodProvider()
{
Expand Down Expand Up @@ -56,13 +57,15 @@ public function testOptions()
$this->assertEquals('POST, PUT', $res->getHeaderLine('Allow'));
}

/**
* @expectedException \UnexpectedValueException
*/
public function testNotFoundContentType()
{
$errorMock = $this->getMockBuilder(NotAllowed::class)->setMethods(['determineContentType'])->getMock();
$errorMock->method('determineContentType')
->will($this->returnValue('unknown/type'));

$this->setExpectedException('\UnexpectedValueException');
$errorMock->__invoke($this->getRequest('GET', 'unknown/type'), new Response(), ['POST']);
}

Expand Down
7 changes: 5 additions & 2 deletions tests/Handlers/NotFoundTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
*/
namespace Slim\Tests\Handlers;

use PHPUnit\Framework\TestCase;
use Slim\Handlers\NotFound;
use Slim\Http\Response;
use Slim\Http\Uri;

class NotFoundTest extends \PHPUnit_Framework_TestCase
class NotFoundTest extends TestCase
{
public function notFoundProvider()
{
Expand Down Expand Up @@ -43,6 +44,9 @@ public function testNotFound($acceptHeader, $contentType, $startOfBody)
$this->assertEquals(0, strpos((string)$res->getBody(), $startOfBody));
}

/**
* @expectedException \UnexpectedValueException
*/
public function testNotFoundContentType()
{
$errorMock = $this->getMockBuilder(NotFound::class)->setMethods(['determineContentType'])->getMock();
Expand All @@ -51,7 +55,6 @@ public function testNotFoundContentType()

$req = $this->getMockBuilder('Slim\Http\Request')->disableOriginalConstructor()->getMock();

$this->setExpectedException('\UnexpectedValueException');
$errorMock->__invoke($req, new Response(), ['POST']);
}

Expand Down
8 changes: 5 additions & 3 deletions tests/Handlers/PhpErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

namespace Slim\Tests\Handlers;

use Doctrine\Instantiator\Exception\UnexpectedValueException;
use PHPUnit\Framework\TestCase;
use Slim\Handlers\PhpError;
use Slim\Http\Response;

class PhpErrorTest extends \PHPUnit_Framework_TestCase
class PhpErrorTest extends TestCase
{
public function phpErrorProvider()
{
Expand Down Expand Up @@ -66,6 +68,7 @@ public function testPhpErrorDisplayDetails($acceptHeader, $contentType, $startOf

/**
* @requires PHP 7.0
* @expectedException \UnexpectedValueException
*/
public function testNotFoundContentType()
{
Expand All @@ -75,7 +78,6 @@ public function testNotFoundContentType()

$req = $this->getMockBuilder('Slim\Http\Request')->disableOriginalConstructor()->getMock();

$this->setExpectedException('\UnexpectedValueException');
$errorMock->__invoke($req, new Response(), new \Exception());
}

Expand Down Expand Up @@ -140,6 +142,7 @@ public function testPhpErrorDisplayDetails5($acceptHeader, $contentType, $startO

/**
* @requires PHP 5.0
* @expectedException \UnexpectedValueException
*/
public function testNotFoundContentType5()
{
Expand All @@ -152,7 +155,6 @@ public function testNotFoundContentType5()
$throwable = $this->getMockBuilder('\Throwable')->getMock();
$req = $this->getMockBuilder('Slim\Http\Request')->disableOriginalConstructor()->getMock();

$this->setExpectedException('\UnexpectedValueException');
$errorMock->__invoke($req, new Response(), $throwable);
}

Expand Down
Loading

0 comments on commit 54401a4

Please sign in to comment.