Skip to content
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

Add rector [batch] #20

Merged
merged 6 commits into from
Sep 28, 2022
Merged
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
21 changes: 21 additions & 0 deletions .github/workflows/rector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
on:
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

name: rector

jobs:
rector:
uses: yiisoft/actions/.github/workflows/rector.yml@master
with:
os: >-
['ubuntu-latest']
php: >-
['8.0']
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@
"httpsoft/http-message": "^1.0.9",
"php-http/guzzle7-adapter": "^1.0",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.14.3",
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.18",
"yiisoft/error-handler": "^2.1",
"yiisoft/yii-event": "^1.0",
"yiisoft/yii-console": "^1.0"
"yiisoft/yii-console": "^1.0",
"yiisoft/yii-event": "^1.0"
},
"suggest": {
"yiisoft/yii-console": "Add error catching to console application",
Expand Down
22 changes: 22 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_80,
]);
};
6 changes: 4 additions & 2 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
use Sentry\SentrySdk;
use Sentry\Transport\HttpTransport;
use Sentry\Transport\NullTransport;
use Symfony\Component\Console\Event\ConsoleErrorEvent;
use Yiisoft\Definitions\Reference;
use Yiisoft\Di\Container;
use Yiisoft\Di\ContainerConfig;
use Yiisoft\Yii\Sentry\SentryConsoleHandler;

final class ConfigTest extends TestCase
{
Expand Down Expand Up @@ -137,8 +139,8 @@ public function eventsConsoleDataProvider(): array
],
],
[
'Symfony\Component\Console\Event\ConsoleErrorEvent' => [
['Yiisoft\Yii\Sentry\SentryConsoleHandler', 'handle'],
ConsoleErrorEvent::class => [
[SentryConsoleHandler::class, 'handle'],
],
],
],
Expand Down
6 changes: 4 additions & 2 deletions tests/SentryConsoleHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Yiisoft\Yii\Sentry\Tests;

use PHPUnit\Framework\Error\Error as PHPUnitError;
use RuntimeException;
use Symfony\Component\Console\Event\ConsoleErrorEvent;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\NullOutput;
Expand All @@ -30,7 +32,7 @@ public function testHandleWithException(): void


$this->createAndRunAppWithEventHandler($eventKey, ExceptionCommand::class);
$this->assertTransportHasException('RuntimeException', 'Console exception test.', $eventKey);
$this->assertTransportHasException(RuntimeException::class, 'Console exception test.', $eventKey);
}

public function testHandleWithFatalError(): void
Expand All @@ -39,7 +41,7 @@ public function testHandleWithFatalError(): void
$eventKey = self::class . "::$methodName()";

$this->createAndRunAppWithEventHandler($eventKey, FatalErrorCommand::class);
$this->assertTransportHasException('PHPUnit\Framework\Error\Error', 'Console fatal error test.', $eventKey);
$this->assertTransportHasException(PHPUnitError::class, 'Console fatal error test.', $eventKey);
}

public function testHandleWithErrorHandlerException(): void
Expand Down
5 changes: 3 additions & 2 deletions tests/SentryMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Error;
use HttpSoft\Message\Response;
use HttpSoft\Message\ServerRequest;
use PHPUnit\Framework\Error\Error as PHPUnitError;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
Expand All @@ -32,7 +33,7 @@ public function testProcessWithException(): void
$this->createRequestHandlerWithException(),
);
} catch (RuntimeException $e) {
$this->assertTransportHasException('RuntimeException', 'Exception test.', $eventKey);
$this->assertTransportHasException(RuntimeException::class, 'Exception test.', $eventKey);

throw $e;
}
Expand All @@ -53,7 +54,7 @@ public function testProcessWithFatalError(): void
$this->createRequestHandlerWithFatalError(),
);
} catch (Error $e) {
$this->assertTransportHasException('PHPUnit\Framework\Error\Error', 'Fatal error test.', $eventKey);
$this->assertTransportHasException(PHPUnitError::class, 'Fatal error test.', $eventKey);

throw $e;
}
Expand Down