Skip to content

Commit

Permalink
🔧 Update PHPStan
Browse files Browse the repository at this point in the history
  • Loading branch information
B-Galati committed May 19, 2020
1 parent 5a45512 commit 183b840
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ composer-validate: vendor ## Validate composer.json file

.PHONY: phpstan
phpstan: vendor ## Check PHP code style
vendor/bin/phpstan analyse -l7 -- src tests
vendor/bin/phpstan analyse

.PHONY: phpunit
phpunit: vendor ## Run PhpUnit tests
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
"require-dev": {
"coduo/php-matcher": "^3.2.2",
"friendsofphp/php-cs-fixer": "^2.15",
"jangregor/phpstan-prophecy": "0.4.2",
"phpstan/phpstan": "0.11.19",
"phpstan/phpstan-phpunit": "0.11.2",
"jangregor/phpstan-prophecy": "0.8.0",
"phpstan/phpstan": "0.12.25",
"phpstan/phpstan-phpunit": "0.12.8",
"phpunit/phpunit": "^7.5||^8.3",
"sentry/sdk": "^2.0",
"symfony/phpunit-bridge": "^4.3",
Expand Down
11 changes: 10 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- vendor/jangregor/phpstan-prophecy/src/extension.neon
- vendor/jangregor/phpstan-prophecy/extension.neon
parameters:
inferPrivatePropertyTypeFromConstructor: true
tipsOfTheDay: false
checkMissingIterableValueType: false

level: 8
paths: [src, tests]

ignoreErrors:
- message: "#^Method .*\\\\SpyTransport\\:\\:getSpiedEventsAsArray\\(\\) should return array\\(.*\\) but returns array\\(.*\\)\\.$#"
count: 1
path: tests/SentryHandlerTest.php
7 changes: 7 additions & 0 deletions src/SentryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@

class SentryHandler extends AbstractProcessingHandler
{
/**
* @var HubInterface
*/
protected $hub;

/**
* @var array
*/
private $breadcrumbsBuffer = [];

/**
Expand Down
43 changes: 29 additions & 14 deletions tests/SentryHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ class SentryHandlerTest extends TestCase
{
use PHPMatcherAssertions;

/**
* @var Hub
*/
private $hub;

/**
* @var SpyTransport
*/
private $transport;

protected function setUp(): void
Expand All @@ -41,8 +48,7 @@ protected function setUp(): void

protected function tearDown(): void
{
$this->hub = null;
$this->transport = null;
unset($this->hub, $this->transport);
}

public function testHandle(): void
Expand Down Expand Up @@ -386,7 +392,7 @@ public function testHandleBatchCanBeCalledTwiceWithoutSideEffects(): void

private function assertCapturedEvent(Severity $severity, string $message, array $extra, \Exception $exception = null, array $breadcrumbs = []): void
{
$event = $this->transport->spiedEvent->toArray();
$event = $this->transport->getSpiedEventsAsArray();

if (null !== $exception) {
$this->assertCount(1, $event['exception']['values']);
Expand Down Expand Up @@ -457,6 +463,9 @@ private function createSentryHandler(int $level = null): SpySentryHandler

class SpySentryHandler extends SentryHandler
{
/**
* @var bool
*/
public $afterWriteCalled = false;

/** {@inheritdoc} */
Expand Down Expand Up @@ -504,22 +513,28 @@ public function resetSpy(): void
$this->isFlushed = false;
}

public function getBreadcrumbsAsArray(): array
/**
* @return array{
* "exception": array,
* "breadcrumbs": array,
* "message": string,
* "level": string,
* "event_id": string,
* "timestamp": int,
* "platform": string,
* "server_name": string,
* "extra": array,
* "sdk": string,
* "contexts": array
* }
*/
public function getSpiedEventsAsArray(): array
{
if (null === $this->spiedEvent) {
throw new \RuntimeException('No spied scope');
}

return array_map(
function (Breadcrumb $breadcrumb) {
$array = $breadcrumb->toArray();

unset($array['timestamp']);

return $array;
},
$this->spiedEvent->getBreadcrumbs()
);
return $this->spiedEvent->toArray();
}

public function close(?int $timeout = null): PromiseInterface
Expand Down

0 comments on commit 183b840

Please sign in to comment.