Skip to content

Commit

Permalink
👷 Migrate to GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
B-Galati committed Jul 17, 2022
1 parent f2a708f commit fe18073
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 38 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: CI

on: [ pull_request ]

env:
COMPOSER_UPDATE_FLAGS: "--no-interaction --no-progress --prefer-dist "

jobs:
tests:
runs-on: ubuntu-latest
name: Test
strategy:
fail-fast: false
matrix:
include:
- php: 7.4 # should use monolog v1
composer_update_flags: --prefer-lowest
- php: 7.4 # should use monolog v2
- php: 8.0 # should use monolog v2
- php: 8.1 # should use monolog v3
steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
coverage: none

- name: Composer dependencies
run: COMPOSER_UPDATE_FLAGS+="${{matrix.composer_update_flags}}" make vendor

- name: PHPUnit
run: make phpunit

static-analysis:
runs-on: ubuntu-latest
name: Static analysis
steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.1"

- name: Composer dependencies
run: make vendor

- name: Composer validate
run: make composer-validate

- name: PHPStan
run: make phpstan

- name: PHP CS Fixer
run: make php-cs-fixer-check
15 changes: 7 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ composer.lock: composer.json
composer update $(COMPOSER_UPDATE_FLAGS)
@touch $@

.PHONY: tests tests-without-cs
tests-without-cs: composer-validate phpstan phpunit ## Run all tests but code style check
tests: tests-without-cs cs-check ## Run all tests
.PHONY: tests
tests: composer-validate phpstan phpunit php-cs-fixer-check ## Run all tests

.PHONY: composer-validate
composer-validate: vendor ## Validate composer.json file
composer validate
composer validate --strict

.PHONY: phpstan
phpstan: vendor ## Check PHP code style
Expand All @@ -31,10 +30,10 @@ phpstan: vendor ## Check PHP code style
phpunit: vendor ## Run PhpUnit tests
vendor/bin/phpunit -v

.PHONY: cs-check
cs-check: vendor ## Check php code style
.PHONY: php-cs-fixer-check
php-cs-fixer-check: vendor ## Check php code style
vendor/bin/php-cs-fixer fix --diff --dry-run --no-interaction -v --cache-file=.php_cs.cache --stop-on-violation

.PHONY: cs-fix
cs-fix: vendor ## Automatically fix php code style
.PHONY: php-cs-fixer-fix
php-cs-fixer-fix: vendor ## Automatically fix php code style
vendor/bin/php-cs-fixer fix -v --cache-file=.php_cs.cache
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Monolog Sentry Handler

[![Build Status](https://img.shields.io/travis/B-Galati/monolog-sentry-handler/master.svg?style=flat-square)](https://travis-ci.org/B-Galati/monolog-sentry-handler)
[![Build Status](https://github.com/B-Galati/monolog-sentry-handler/workflows/CI/badge.svg?branch=main)](https://github.com/B-Galati/monolog-sentry-handler/actions?query=workflow%3ACI+branch%3Amain)
[![Latest Version](https://img.shields.io/github/release/B-Galati/monolog-sentry-handler.svg?style=flat-square)](https://packagist.org/packages/bgalati/monolog-sentry-handler)
[![MIT License](https://img.shields.io/github/license/B-Galati/monolog-sentry-handler?style=flat-square)](LICENCE)

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
}
},
"require": {
"php": "^7.2 || ^8.0",
"php": "^7.4 || ^8.0",
"monolog/monolog": "^1.6 || ^2.0 || ^3.0",
"sentry/sentry": "^3.1"
},
"require-dev": {
"coduo/php-matcher": "^3.2.2",
"coduo/php-matcher": "^6.0.8",
"friendsofphp/php-cs-fixer": "^2.15",
"jangregor/phpstan-prophecy": "^1.0.0",
"phpstan/phpstan": "^1.8.0",
Expand Down
15 changes: 4 additions & 11 deletions src/SentryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @see \Sentry\Monolog\CompatibilityProcessingHandlerTrait
*/
if (Logger::API >= 3) {
if (Logger::API >= 3) { // @phpstan-ignore-line - Comparison operation ">=" between 3 and 3 is always true.
/**
* Logic which is used if monolog >= 3 is installed.
* @internal
Expand Down Expand Up @@ -90,7 +90,7 @@ private function getBreadcrumbLevelFromLevel(int $level): string
}
}
}
} else {
} else { // @phpstan-ignore-line - Else branch is unreachable because previous condition is always true.
/**
* Logic which is used if monolog < 3 is installed.
* @internal
Expand Down Expand Up @@ -163,15 +163,8 @@ class SentryHandler extends AbstractProcessingHandler
{
use CompatibilityProcessingHandlerTrait;

/**
* @var HubInterface
*/
protected $hub;

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

/**
* @param HubInterface $hub The sentry hub used to send event to Sentry
Expand Down
27 changes: 11 additions & 16 deletions tests/SentryHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,8 @@ final class SentryHandlerTest extends TestCase
{
use PHPMatcherAssertions;

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

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

protected function setUp(): void
{
Expand Down Expand Up @@ -89,7 +82,7 @@ private function record(array $record)
/**
* @return array<array<string, mixed>|LogRecord>
*/
private function records(array $records)
private function records(array $records): array
{
return array_map(function($record) {
return $this->record($record);
Expand Down Expand Up @@ -239,7 +232,6 @@ public function testHandleBatch(): void
'message' => 'Info message',
'timestamp' => '@double@',
'data' => [
'exception' => '@*@',
'extra-info',
],
],
Expand Down Expand Up @@ -298,7 +290,6 @@ public function testHandleBatch(): void
'message' => 'Critical message',
'timestamp' => '@double@',
'data' => [
'exception' => '@*@',
'extra-critical',
],
],
Expand Down Expand Up @@ -392,9 +383,7 @@ public function testHandleBatchFiltersRecordsByLevel(): void
'level' => 'fatal',
'message' => 'Critical message',
'timestamp' => '@double@',
'data' => [
'exception' => '@*@',
],
'data' => [],
],
]
);
Expand Down Expand Up @@ -493,7 +482,13 @@ private function assertCapturedEvent(Severity $severity, string $message, array
$this->assertMatchesPattern('@string@', (string) $event->getId());
$this->assertMatchesPattern('@string@', (string) $event->getTimestamp());
$this->assertMatchesPattern('@string@', $event->getServerName());
$this->assertMatchesPattern(['processScope' => 'called'] + $extra, $event->getExtra());
$this->assertMatchesPattern([
'processScope' => 'called',
'monolog.channel' => '@string@',
'monolog.level' => '@string@',
] + $extra,
$event->getExtra(),
);

if ($breadcrumbs) {
$this->assertMatchesPattern(
Expand Down

0 comments on commit fe18073

Please sign in to comment.