Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Commit

Permalink
Add support for Symfony 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Michał Mleczko committed Apr 18, 2020
1 parent 340ff23 commit 2137a53
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 28 deletions.
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM php:cli-alpine

WORKDIR /app

CMD tail -f /dev/null

COPY --from=composer:1.10.5 /usr/bin/composer /usr/bin/composer

ENV BROWSCAP_DIR /usr/local/etc/php/browsecap

ADD http://browscap.org/stream?q=Lite_PHP_BrowsCapINI $BROWSCAP_DIR/browscap.ini
RUN echo "browscap='$BROWSCAP_DIR/browscap.ini'" >> /usr/local/etc/php/conf.d/browsecap.ini && \
chmod 755 -R $BROWSCAP_DIR
6 changes: 3 additions & 3 deletions SubscribedProcessor/BrowserDataAppending.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Dziki\MonologSentryBundle\UserAgent\ParserInterface;
use Dziki\MonologSentryBundle\UserAgent\UserAgent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class BrowserDataAppending implements EventSubscriberInterface
Expand Down Expand Up @@ -44,10 +44,10 @@ public function __invoke(array $record): array
return $record;
}

public function onKernelRequest(GetResponseEvent $event): void
public function onKernelRequest(RequestEvent $event): void
{
/** @var string $userAgent */
$userAgent = $event->getRequest()->headers->get('User-Agent', '', true);
$userAgent = $event->getRequest()->headers->get('User-Agent', '');

$this->userAgent = $this->parser->parse($userAgent);
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/Functional/MonologSentryExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Dziki\MonologSentryBundle\UserAgent\NativeParser;
use Dziki\MonologSentryBundle\UserAgent\PhpUserAgentParser;
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
use Symfony\Component\Cache\Simple\ArrayCache;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
Expand Down Expand Up @@ -60,7 +60,7 @@ public function checkIfServicesDefinedAndPrivate(): void
],
];

$this->registerService(TokenStorageInterface::class, new TokenStorage());
$this->registerService(TokenStorageInterface::class, TokenStorage::class);
$this->compile();

$this->assertServicesDefinedAndPrivate($defaultServices);
Expand All @@ -77,7 +77,7 @@ private function assertServicesDefinedAndPrivate($defaultServices): void
$this->fail(sprintf('Service "%s" (%s) should be private', \get_class($service), $defaultService));
}
} catch (ServiceNotFoundException $exception) {
$this->assertContains($defaultService, $exception->getMessage());
$this->assertStringContainsString($defaultService, $exception->getMessage());
}
}
}
Expand Down Expand Up @@ -138,7 +138,7 @@ public function checkIfCachedParserServiceDefinedAndPrivate(): void
],
];

$this->registerService('app.cache.simple', new ArrayCache());
$this->registerService('app.cache.simple', ArrayAdapter::class);
$this->compile();

$this->assertServicesDefinedAndPrivate($defaultServices);
Expand Down
1 change: 0 additions & 1 deletion Tests/Functional/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ monolog:
handler: sentry
sentry:
type: raven
class: Dziki\MonologSentryBundle\Handler\Raven
dsn: http://test-hash@some-sentry.com/some-id
level: notice
release: 0.0.0.1-dev
6 changes: 5 additions & 1 deletion Tests/Functional/config_with_cache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ monolog_sentry:

services:
simple_array_cache:
class: 'Symfony\Component\Cache\Simple\ArrayCache'
class: 'Symfony\Component\Cache\Psr16Cache'
arguments:
- '@simple_array_symfony_cache'
simple_array_symfony_cache:
class: 'Symfony\Component\Cache\Adapter\ArrayAdapter'
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ public function changeClassDefinitionForAllAndOnlyRavenHandlerServices()
$this->assertSame(
Raven::class,
$containerBuilder
->getDefinition($id)
->getDefinition((string) $id)
->getClass()
);
} else {
$this->assertSame(
$class,
$containerBuilder
->getDefinition($id)
->getDefinition((string) $id)
->getClass()
);
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/Unit/Handler/RavenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testDebug()
$handler->handle($record);

$this->assertEquals($ravenClient::DEBUG, $ravenClient->lastData['level']);
$this->assertContains($record['message'], $ravenClient->lastData['message']);
$this->assertStringContainsString($record['message'], $ravenClient->lastData['message']);
}

protected function getHandler($ravenClient)
Expand Down Expand Up @@ -88,7 +88,7 @@ public function testWarning()
$handler->handle($record);

$this->assertEquals($ravenClient::WARNING, $ravenClient->lastData['level']);
$this->assertContains($record['message'], $ravenClient->lastData['message']);
$this->assertStringContainsString($record['message'], $ravenClient->lastData['message']);
}

public function testTag()
Expand Down Expand Up @@ -181,7 +181,7 @@ public function testUserContext()

// check to see if its reset
$handler->handle($recordWithNoContext);
$this->assertInternalType('array', $ravenClient->context->user);
$this->assertIsArray($ravenClient->context->user);
$this->assertSame('test_user_id', $ravenClient->context->user['id']);
}

Expand Down
16 changes: 5 additions & 11 deletions Tests/Unit/SubscribedProcessor/BrowserDataAppendingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\KernelEvents;

/**
* @covers \Dziki\MonologSentryBundle\SubscribedProcessor\BrowserDataAppending
*
* @uses \Dziki\MonologSentryBundle\UserAgent\UserAgent
* @uses \Dziki\MonologSentryBundle\UserAgent\UserAgent
*/
class BrowserDataAppendingTest extends TestCase
{
Expand Down Expand Up @@ -53,21 +54,14 @@ public function parseUserAgentOnRequest(): BrowserDataAppending
$this->parser
->expects($this->once())
->method('parse')
->willReturn(UserAgent::create('Firefox', '62.0', 'Linux'))
;
->willReturn(UserAgent::create('Firefox', '62.0', 'Linux'));

$headersBag = new HeaderBag(
['User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0']
);
$request = $this->createMock(Request::class);
$request->headers = $headersBag;
/**
* @var GetResponseEvent|MockObject
*/
$event = $this->createMock(GetResponseEvent::class);
$event->method('getRequest')
->willReturn($request)
;
$event = new RequestEvent($this->createMock(Kernel::class), $request, null);

$browserDataAppendingProcessor->onKernelRequest($event);

Expand Down
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
"php": ">=7.1",
"psr/simple-cache": "^1.0",
"psr/simple-cache-implementation": "^1.0",
"symfony/dependency-injection": "^3.4|^4.1.12|^5.0",
"symfony/dependency-injection": "^4.2|^5.0",
"symfony/monolog-bundle": "^3.3",
"symfony/monolog-bridge": "^3.4|^4.1|^5.0",
"monolog/monolog": "^1",
"symfony/monolog-bridge": "^4.2|^5.0",
"sentry/sentry": "^1.9.1"
},
"conflict": {
Expand All @@ -35,7 +36,8 @@
"nyholm/symfony-bundle-test": "^1.4",
"matthiasnoback/symfony-dependency-injection-test": "dev-master",
"donatj/phpuseragentparser": "^0.11",
"symfony/security-bundle": "^3.4|^4.1.12|^5.0"
"symfony/security-bundle": "^4.2|^5.0",
"symfony/string": "^5.0"
},
"suggest": {
"donatj/phpuseragentparser": "Basic package for parsing User-Agent header, faster than native browscap",
Expand Down
9 changes: 9 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '3.7'

services:
php:
user: "${DOCKER_COMPOSE_RUN_AS_USER:?You must define user:group for permissions handling}"
build: .
volumes:
- .:/app
- ~/.composer:/.composer

0 comments on commit 2137a53

Please sign in to comment.