Skip to content

Commit

Permalink
Merge pull request #2 from okvpn/feature/php7.3
Browse files Browse the repository at this point in the history
Test against PHP 7.3
  • Loading branch information
vtsykun authored Oct 28, 2018
2 parents 24a6edc + 4aeeedb commit eb22a59
Show file tree
Hide file tree
Showing 13 changed files with 238 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ matrix:
env: SYMFONY_VERSION="2.8.*"
- php: 7.2
env: SYMFONY_VERSION="3.4.*"
- php: 7.2
- php: 7.3
env: SYMFONY_VERSION="4.1.*"

cache:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
"require": {
"php":">=7.1",
"symfony/framework-bundle": "^2.8 || ^3.0 || ^4.0",
"symfony/yaml": "^2.8 || ^3.4 || ^4.0",
"symfony/yaml": "^2.8 || ^3.0 || ^4.0",
"graze/dog-statsd": "^0.4"
},
"require-dev": {
"ext-pdo_sqlite": "*",
"doctrine/doctrine-bundle": "^1.6.10",
"doctrine/orm": "^2.5.11",
"doctrine/orm": "2.5.11 || 2.6.x-dev as 2.6.3",
"phpunit/phpunit": "^6.2",
"symfony/browser-kit": "^2.8 || ^3.4 || ^4.0",
"symfony/console": "^2.8 || ^3.4 || ^4.0",
Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/ResponseTimeListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ResponseTimeListener
private $kernel;
private $dogStats;

public function __construct(KernelInterface $kernel = null, DogStatsInterface $dogStats)
public function __construct(DogStatsInterface $dogStats, KernelInterface $kernel = null)
{
$this->kernel = $kernel;
$this->dogStats = $dogStats;
Expand Down
2 changes: 1 addition & 1 deletion src/Logging/DatadogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function write(array $record): void
}
}

if ($exception && false === $this->skipCaptureService->shouldExceptionCaptureBeSkipped($exception)) {
if ($exception && false === $this->skipCaptureService->shouldExceptionCaptureBeSkipped($exception) && false === $this->skipCaptureService->shouldMessageCaptureBeSkipped($record['message'])) {
$this->errorBag->pushError($record);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/listener.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:

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

Expand Down
33 changes: 32 additions & 1 deletion tests/Functional/App/Command/DatadogExceptionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,30 @@

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

use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class DatadogExceptionCommand extends Command
{
private $logger;

public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
parent::__construct();
}

/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('app:exception')
->addOption('filter', null, InputOption::VALUE_OPTIONAL)
->setDescription('Trigger error');
}

Expand All @@ -25,6 +36,26 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
\function_do_not_exists();
switch ($input->getOption('filter')) {
case 'skip_instanceof':
throw new DemoDatadogException('Test datadog handle exception');
break;
case 'skip_capture':
throw new \UnderflowException('Test datadog handle exception');
break;
case 'skip_wildcard':
throw new \RuntimeException('Loading of entity aliases failed');
break;
case 'test_logger':
$exception = new \RuntimeException('Logger exception');
$this->logger->error('Unhatched exception', ['exception' => $exception]);
break;
case 'test_logger_wildcard':
$exception = new \RuntimeException('Logger exception');
$this->logger->error('Loading of entity aliases failed', ['exception' => $exception]);
break;
default:
\function_do_not_exists();
}
}
}
9 changes: 9 additions & 0 deletions tests/Functional/App/Command/DemoDatadogException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

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

class DemoDatadogException extends \RuntimeException implements DemoDatadogExceptionInterface
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

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

interface DemoDatadogExceptionInterface
{
}
14 changes: 14 additions & 0 deletions tests/Functional/App/Controller/AppDatadogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

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

use Okvpn\Bundle\DatadogBundle\Tests\Functional\App\Entity\DatadogUser;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;

class AppDatadogController extends Controller
Expand All @@ -18,4 +20,16 @@ public function exception()
{
// Exception
}

public function entity()
{
$user = (new DatadogUser())
->setUsername('foo');

$em = $this->getDoctrine()->getManager();
$em->persist($user);
$em->flush();

return new JsonResponse(['status' => true]);
}
}
56 changes: 56 additions & 0 deletions tests/Functional/App/Entity/DatadogUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

namespace Okvpn\Bundle\DatadogBundle\Tests\Functional\App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
class DatadogUser
{
/**
* @var int
*
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;

/**
* @var string
*
* @ORM\Column(type="string", length=64)
*/
private $username;

/**
* @return int
*/
public function getId(): int
{
return $this->id;
}

/**
* @return string
*/
public function getUsername(): string
{
return $this->username;
}

/**
* @param string $username
* @return self
*/
public function setUsername(string $username): DatadogUser
{
$this->username = $username;

return $this;
}
}
1 change: 1 addition & 0 deletions tests/Functional/App/OkvpnKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function loadRoutes(LoaderInterface $loader)

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

return $routes->build();
}
Expand Down
19 changes: 18 additions & 1 deletion tests/Functional/App/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ framework:
doctrine:
dbal:
driver: 'pdo_sqlite'
path: '%kernel.root_dir%/var/test.db'
path: '%kernel.root_dir%/test.db'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.root_dir%/../Entity'
prefix: 'Okvpn\Bundle\DatadogBundle\Tests\Functional\App\Entity'

monolog:
handlers:
Expand All @@ -33,6 +39,14 @@ security:
okvpn_datadog:
profiling: true
namespace: app
dedup_keep_time: 5
handle_exceptions:
skip_instanceof:
- 'Okvpn\Bundle\DatadogBundle\Tests\Functional\App\Command\DemoDatadogExceptionInterface'
skip_capture:
- 'UnderflowException'
skip_wildcard:
- '*entity aliases failed*'

parameters:
request_listener.http_port: 80
Expand All @@ -47,9 +61,12 @@ services:

app.command.exception_command:
class: Okvpn\Bundle\DatadogBundle\Tests\Functional\App\Command\DatadogExceptionCommand
arguments: ['@logger']
tags:
- { name: console.command }

app.controller.base_controller:
class: Okvpn\Bundle\DatadogBundle\Tests\Functional\App\Controller\AppDatadogController
public: true
calls:
- [setContainer, ['@service_container']]
Loading

0 comments on commit eb22a59

Please sign in to comment.