Skip to content

Commit 0e1c850

Browse files
authored
Feature/patch issue 34 (#41)
Fix issue #34
1 parent 7292012 commit 0e1c850

4 files changed

Lines changed: 57 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Hawkbit Changelog
22

3+
## 2.3.2
4+
5+
### Fixed
6+
7+
- Fix issue #34. Bind closure always to application instance.
8+
39
## 2.3.1
410

511
### Fixed

src/Application/AbstractApplication.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<?php
22
/**
3-
* Created by PhpStorm.
4-
* User: marco.bunge
5-
* Date: 03.11.2016
6-
* Time: 08:54
3+
* The Hawkbit Micro Framework. An advanced derivate of Proton Micro Framework
4+
*
5+
* @author Marco Bunge <marco_bunge@web.de>
6+
* @author Daniyal Hamid (@Designcise) <hello@designcise.com>
7+
* @copyright Marco Bunge <marco_bunge@web.de>
8+
*
9+
* @license MIT
710
*/
811

912
namespace Hawkbit\Application;
@@ -374,7 +377,7 @@ public function validateContract($class, $contract)
374377
protected function bindClosureToInstance($closure, $instance)
375378
{
376379
if ($closure instanceof \Closure) {
377-
\Closure::bind($closure, $instance, get_class($instance));
380+
$closure = $closure->bind($closure, $instance, get_class($instance));
378381
}
379382

380383
return $closure;
@@ -436,4 +439,4 @@ abstract public function shutdown();
436439
* @return void
437440
*/
438441
abstract public function init();
439-
}
442+
}

tests/ApplicationTest.php

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,29 @@
2929

3030
class ApplicationTest extends \PHPUnit_Framework_TestCase
3131
{
32-
/**
33-
*
34-
*/
35-
protected function tearDown()
32+
public function testAppInstanceAccessInClosure()
3633
{
37-
restore_error_handler();
38-
restore_exception_handler();
34+
35+
$app = new Application(true);
36+
37+
$appInstanceInClosure = false;
38+
39+
$app->get(
40+
'/',
41+
function (ServerRequestInterface $request, ResponseInterface $response, array $args = [])
42+
use(&$appInstanceInClosure){
43+
$that = $this;
44+
$appInstanceInClosure = $this instanceof Application\ApplicationInterface;
45+
return $response;
46+
}
47+
);
48+
49+
$request = ServerRequestFactory::fromGlobals();
50+
$response = $app->handle($request);
51+
52+
$this->assertTrue($appInstanceInClosure);
53+
$this->assertEquals(200, $response->getStatusCode());
54+
3955
}
4056

4157

@@ -508,7 +524,8 @@ public function testAjaxRequestRecogniseHTML()
508524
$this->assertEquals('application/json', $app->getContentType());
509525
}
510526

511-
public function testRootRequestWithoutPublicAsDocumentRoot(){
527+
public function testRootRequestWithoutPublicAsDocumentRoot()
528+
{
512529
$app = new Application();
513530
$app->get('/', function (ServerRequestInterface $request, ResponseInterface $response) {
514531
$response->getBody()->write('<h1>HELLO</h1>');
@@ -525,7 +542,9 @@ public function testRootRequestWithoutPublicAsDocumentRoot(){
525542
$this->assertEquals('text/html', $app->getContentType());
526543
$_SERVER = $tmpServer;
527544
}
528-
public function testExampleRequestWithoutPublicAsDocumentRoot(){
545+
546+
public function testExampleRequestWithoutPublicAsDocumentRoot()
547+
{
529548
$app = new Application();
530549

531550
$app->get('/', function (ServerRequestInterface $request, ResponseInterface $response) {
@@ -549,4 +568,15 @@ public function testExampleRequestWithoutPublicAsDocumentRoot(){
549568
$this->assertEquals('text/html', $app->getContentType());
550569
$_SERVER = $tmpServer;
551570
}
571+
572+
/**
573+
*
574+
*/
575+
protected function tearDown()
576+
{
577+
restore_error_handler();
578+
restore_exception_handler();
579+
}
580+
581+
552582
}

tests/Stratigility/MiddlewarePipeAdapterTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ public function testFunctionalPiping()
2626
$handleRoute = false;
2727
$handleMiddleware = false;
2828
$application = new Application();
29-
$application->get('/', function ($request, ResponseInterface $response) use(&$handleRoute) {
30-
$this->assertInstanceOf(ServerRequestInterface::class, $request);
31-
$this->assertInstanceOf(ResponseInterface::class, $response);
29+
$testCase = $this;
30+
$application->get('/', function ($request, ResponseInterface $response) use(&$handleRoute, $testCase) {
31+
$testCase->assertInstanceOf(ServerRequestInterface::class, $request);
32+
$testCase->assertInstanceOf(ResponseInterface::class, $response);
3233
$response->getBody()->write('Hello World');
3334
$handleRoute = true;
3435
return $response;

0 commit comments

Comments
 (0)