Skip to content

Commit 215c349

Browse files
committed
Removed compatibility with PHP5.6, fixed compatibility with PHP7.
1 parent 1b1324d commit 215c349

18 files changed

+34
-108
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: php
22

33
php:
4-
- 5.6
54
- 7.0
65
- 7.1
76
- 7.2
@@ -21,4 +20,4 @@ install:
2120
script:
2221
- |
2322
php -S localhost:8080 -t demo/web > /dev/null 2>&1 &
24-
vendor/bin/codecept run
23+
vendor/bin/codecept run

Action.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,13 @@ public function runWithParams($params)
134134

135135
$this->restoreYiiRequest();
136136
}
137-
} catch (JsonRpcException $e) {
137+
}
138+
catch (JsonRpcException $e) {
138139
return new ErrorResponse($e);
139140
}
141+
catch (\Throwable $e) {
142+
return new InternalErrorException('Error while processing request', [], $e);
143+
}
140144

141145
return !$isBatch ? array_shift($batchResponse) : $batchResponse;
142146
}

Controller.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,4 @@ public function behaviors()
5454
];
5555
}
5656

57-
/**
58-
* @throws \yii\base\InvalidConfigException
59-
*/
60-
public function init()
61-
{
62-
Yii::$app->set('errorHandler', ['class' => ErrorHandler::class]);
63-
Yii::$app->getErrorHandler()->register();
64-
parent::init();
65-
}
6657
}

ErrorHandler.php

Lines changed: 0 additions & 43 deletions
This file was deleted.

JsonRpcError.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class JsonRpcError implements \JsonSerializable
2323
* JsonRpcError constructor.
2424
* @param \Exception $exception
2525
*/
26-
public function __construct(\Exception $exception)
26+
public function __construct(\Throwable $exception)
2727
{
2828
$this->code = $exception->getCode();
2929
$this->message = $this->getExceptionMessage($exception);
@@ -59,7 +59,7 @@ public function jsonSerialize()
5959
* @param \Exception $exception
6060
* @return string
6161
*/
62-
protected function getExceptionMessage(\Exception $exception)
62+
protected function getExceptionMessage(\Throwable $exception)
6363
{
6464
$message = $exception->getMessage();
6565
return !empty($message) ?
@@ -71,7 +71,7 @@ protected function getExceptionMessage(\Exception $exception)
7171
* @param \Exception $exception
7272
* @return array
7373
*/
74-
protected function convertExceptionToArray(\Exception $exception)
74+
protected function convertExceptionToArray(\Throwable $exception)
7575
{
7676
$errorArray = [];
7777

JsonRpcRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function execute()
192192
throw new InvalidParamsException('Invalid params', [], $e);
193193
} catch (InvalidRouteException $e) {
194194
throw new MethodNotFoundException('Method not found: ' . $route . '.', [], $e);
195-
} catch (\Exception $e) {
195+
} catch (\Throwable $e) {
196196
throw new InternalErrorException('Internal error', [], $e);
197197
}
198198

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
}
2222
],
2323
"require": {
24-
"php": ">=5.6"
24+
"php": "~7.0",
25+
"yiisoft/yii2": "~2.0.15"
2526
},
2627
"require-dev": {
27-
"yiisoft/yii2": "~2.0.15",
2828
"codeception/codeception": "~2.4",
2929
"flow/jsonpath": "^0.4.0"
3030
}

demo/controllers/DemoController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function actionInternalError()
7373
* @param int $b
7474
* @return int
7575
*/
76-
public function actionSum($a, $b)
76+
public function actionSum(int $a, int $b)
7777
{
7878
return $a + $b;
7979
}

demo/tests/_support/Helper/JsonEqualsWrapper.php renamed to demo/tests/JsonEquals.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
<?php
2-
namespace tests\Helper;
2+
3+
namespace tests;
34

45
use Codeception\PHPUnit\Constraint\JsonContains;
56
use SebastianBergmann\Comparator\ComparisonFailure;
67
use SebastianBergmann\Comparator\ArrayComparator;
78
use SebastianBergmann\Comparator\Factory;
89
use Codeception\Util\JsonArray;
910

10-
class JsonEqualsWrapper extends JsonContains
11+
class JsonEquals extends JsonContains
1112
{
12-
protected function _matches($other)
13+
14+
/**
15+
* Evaluates the constraint for parameter $other. Returns true if the
16+
* constraint is met, false otherwise.
17+
*
18+
* @param mixed $other Value or object to evaluate.
19+
*
20+
* @return bool
21+
*/
22+
protected function matches($other) : bool
1323
{
1424
$jsonResponseArray = new JsonArray($other);
1525
if (!is_array($jsonResponseArray->toArray())) {

demo/tests/_support/Helper/Api.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// all public methods declared in helper class will be available in $I
66

77
use Codeception\Exception\ModuleException;
8+
use tests\JsonEquals;
89

910
class Api extends \Codeception\Module
1011
{
@@ -21,9 +22,7 @@ public function seeResponseEqualsJson($json = [])
2122

2223
\PHPUnit\Framework\Assert::assertThat(
2324
$response,
24-
version_compare(PHP_VERSION, '7.1', '>=')
25-
? new JsonEqualsTypeHint($json)
26-
: new JsonEquals($json)
25+
JsonEquals($json)
2726
);
2827
}
2928
}

0 commit comments

Comments
 (0)