Skip to content

Commit eb22a59

Browse files
authored
Merge pull request #2 from okvpn/feature/php7.3
Test against PHP 7.3
2 parents 24a6edc + 4aeeedb commit eb22a59

13 files changed

+238
-32
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ matrix:
1212
env: SYMFONY_VERSION="2.8.*"
1313
- php: 7.2
1414
env: SYMFONY_VERSION="3.4.*"
15-
- php: 7.2
15+
- php: 7.3
1616
env: SYMFONY_VERSION="4.1.*"
1717

1818
cache:

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
"require": {
2323
"php":">=7.1",
2424
"symfony/framework-bundle": "^2.8 || ^3.0 || ^4.0",
25-
"symfony/yaml": "^2.8 || ^3.4 || ^4.0",
25+
"symfony/yaml": "^2.8 || ^3.0 || ^4.0",
2626
"graze/dog-statsd": "^0.4"
2727
},
2828
"require-dev": {
2929
"ext-pdo_sqlite": "*",
3030
"doctrine/doctrine-bundle": "^1.6.10",
31-
"doctrine/orm": "^2.5.11",
31+
"doctrine/orm": "2.5.11 || 2.6.x-dev as 2.6.3",
3232
"phpunit/phpunit": "^6.2",
3333
"symfony/browser-kit": "^2.8 || ^3.4 || ^4.0",
3434
"symfony/console": "^2.8 || ^3.4 || ^4.0",

src/EventListener/ResponseTimeListener.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ResponseTimeListener
1313
private $kernel;
1414
private $dogStats;
1515

16-
public function __construct(KernelInterface $kernel = null, DogStatsInterface $dogStats)
16+
public function __construct(DogStatsInterface $dogStats, KernelInterface $kernel = null)
1717
{
1818
$this->kernel = $kernel;
1919
$this->dogStats = $dogStats;

src/Logging/DatadogHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected function write(array $record): void
3838
}
3939
}
4040

41-
if ($exception && false === $this->skipCaptureService->shouldExceptionCaptureBeSkipped($exception)) {
41+
if ($exception && false === $this->skipCaptureService->shouldExceptionCaptureBeSkipped($exception) && false === $this->skipCaptureService->shouldMessageCaptureBeSkipped($record['message'])) {
4242
$this->errorBag->pushError($record);
4343
}
4444
}

src/Resources/config/listener.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ services:
1111

1212
okvpn_datadog.timming_http_listener:
1313
class: Okvpn\Bundle\DatadogBundle\EventListener\ResponseTimeListener
14-
arguments: ['@kernel', '@okvpn_datadog.client']
14+
arguments: ['@okvpn_datadog.client', '@?kernel']
1515
tags:
1616
- { name: kernel.event_listener, event: kernel.terminate, method: onKernelTerminate }
1717

tests/Functional/App/Command/DatadogExceptionCommand.php

+32-1
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,30 @@
44

55
namespace Okvpn\Bundle\DatadogBundle\Tests\Functional\App\Command;
66

7+
use Psr\Log\LoggerInterface;
78
use Symfony\Component\Console\Command\Command;
89
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Input\InputOption;
911
use Symfony\Component\Console\Output\OutputInterface;
1012

1113
class DatadogExceptionCommand extends Command
1214
{
15+
private $logger;
16+
17+
public function __construct(LoggerInterface $logger)
18+
{
19+
$this->logger = $logger;
20+
parent::__construct();
21+
}
22+
1323
/**
1424
* {@inheritdoc}
1525
*/
1626
protected function configure()
1727
{
1828
$this
1929
->setName('app:exception')
30+
->addOption('filter', null, InputOption::VALUE_OPTIONAL)
2031
->setDescription('Trigger error');
2132
}
2233

@@ -25,6 +36,26 @@ protected function configure()
2536
*/
2637
protected function execute(InputInterface $input, OutputInterface $output)
2738
{
28-
\function_do_not_exists();
39+
switch ($input->getOption('filter')) {
40+
case 'skip_instanceof':
41+
throw new DemoDatadogException('Test datadog handle exception');
42+
break;
43+
case 'skip_capture':
44+
throw new \UnderflowException('Test datadog handle exception');
45+
break;
46+
case 'skip_wildcard':
47+
throw new \RuntimeException('Loading of entity aliases failed');
48+
break;
49+
case 'test_logger':
50+
$exception = new \RuntimeException('Logger exception');
51+
$this->logger->error('Unhatched exception', ['exception' => $exception]);
52+
break;
53+
case 'test_logger_wildcard':
54+
$exception = new \RuntimeException('Logger exception');
55+
$this->logger->error('Loading of entity aliases failed', ['exception' => $exception]);
56+
break;
57+
default:
58+
\function_do_not_exists();
59+
}
2960
}
3061
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Okvpn\Bundle\DatadogBundle\Tests\Functional\App\Command;
6+
7+
class DemoDatadogException extends \RuntimeException implements DemoDatadogExceptionInterface
8+
{
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Okvpn\Bundle\DatadogBundle\Tests\Functional\App\Command;
6+
7+
interface DemoDatadogExceptionInterface
8+
{
9+
}

tests/Functional/App/Controller/AppDatadogController.php

+14
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
namespace Okvpn\Bundle\DatadogBundle\Tests\Functional\App\Controller;
66

7+
use Okvpn\Bundle\DatadogBundle\Tests\Functional\App\Entity\DatadogUser;
78
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
9+
use Symfony\Component\HttpFoundation\JsonResponse;
810
use Symfony\Component\HttpFoundation\Response;
911

1012
class AppDatadogController extends Controller
@@ -18,4 +20,16 @@ public function exception()
1820
{
1921
// Exception
2022
}
23+
24+
public function entity()
25+
{
26+
$user = (new DatadogUser())
27+
->setUsername('foo');
28+
29+
$em = $this->getDoctrine()->getManager();
30+
$em->persist($user);
31+
$em->flush();
32+
33+
return new JsonResponse(['status' => true]);
34+
}
2135
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Okvpn\Bundle\DatadogBundle\Tests\Functional\App\Entity;
6+
7+
use Doctrine\ORM\Mapping as ORM;
8+
9+
/**
10+
* @ORM\Entity
11+
*/
12+
class DatadogUser
13+
{
14+
/**
15+
* @var int
16+
*
17+
* @ORM\Column(type="integer")
18+
* @ORM\Id
19+
* @ORM\GeneratedValue(strategy="IDENTITY")
20+
*/
21+
private $id;
22+
23+
/**
24+
* @var string
25+
*
26+
* @ORM\Column(type="string", length=64)
27+
*/
28+
private $username;
29+
30+
/**
31+
* @return int
32+
*/
33+
public function getId(): int
34+
{
35+
return $this->id;
36+
}
37+
38+
/**
39+
* @return string
40+
*/
41+
public function getUsername(): string
42+
{
43+
return $this->username;
44+
}
45+
46+
/**
47+
* @param string $username
48+
* @return self
49+
*/
50+
public function setUsername(string $username): DatadogUser
51+
{
52+
$this->username = $username;
53+
54+
return $this;
55+
}
56+
}

tests/Functional/App/OkvpnKernel.php

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public function loadRoutes(LoaderInterface $loader)
5959

6060
$routes->add('/', "app.controller.base_controller:index");
6161
$routes->add('/exception', "app.controller.base_controller:exception");
62+
$routes->add('/entity', "app.controller.base_controller:entity");
6263

6364
return $routes->build();
6465
}

tests/Functional/App/config.yml

+18-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ framework:
99
doctrine:
1010
dbal:
1111
driver: 'pdo_sqlite'
12-
path: '%kernel.root_dir%/var/test.db'
12+
path: '%kernel.root_dir%/test.db'
1313
orm:
1414
auto_generate_proxy_classes: '%kernel.debug%'
1515
naming_strategy: doctrine.orm.naming_strategy.underscore
1616
auto_mapping: true
17+
mappings:
18+
App:
19+
is_bundle: false
20+
type: annotation
21+
dir: '%kernel.root_dir%/../Entity'
22+
prefix: 'Okvpn\Bundle\DatadogBundle\Tests\Functional\App\Entity'
1723

1824
monolog:
1925
handlers:
@@ -33,6 +39,14 @@ security:
3339
okvpn_datadog:
3440
profiling: true
3541
namespace: app
42+
dedup_keep_time: 5
43+
handle_exceptions:
44+
skip_instanceof:
45+
- 'Okvpn\Bundle\DatadogBundle\Tests\Functional\App\Command\DemoDatadogExceptionInterface'
46+
skip_capture:
47+
- 'UnderflowException'
48+
skip_wildcard:
49+
- '*entity aliases failed*'
3650

3751
parameters:
3852
request_listener.http_port: 80
@@ -47,9 +61,12 @@ services:
4761

4862
app.command.exception_command:
4963
class: Okvpn\Bundle\DatadogBundle\Tests\Functional\App\Command\DatadogExceptionCommand
64+
arguments: ['@logger']
5065
tags:
5166
- { name: console.command }
5267

5368
app.controller.base_controller:
5469
class: Okvpn\Bundle\DatadogBundle\Tests\Functional\App\Controller\AppDatadogController
5570
public: true
71+
calls:
72+
- [setContainer, ['@service_container']]

0 commit comments

Comments
 (0)