mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-04 12:17:35 +02:00
ElasticSearch v8 support (#1662)
* ElasticSearch v8 support * CI updates Co-authored-by: Thomas Müller <mimmi20@live.de>
This commit is contained in:
227
.github/workflows/continuous-integration.yml
vendored
227
.github/workflows/continuous-integration.yml
vendored
@@ -4,71 +4,242 @@ on:
|
|||||||
- push
|
- push
|
||||||
- pull_request
|
- pull_request
|
||||||
|
|
||||||
env:
|
|
||||||
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist"
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
tests:
|
tests:
|
||||||
name: "CI"
|
name: "CI"
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: "${{ matrix.operating-system }}"
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
php-version:
|
php-version:
|
||||||
- "7.2"
|
- "7.2"
|
||||||
- "7.3"
|
- "7.3"
|
||||||
- "7.4"
|
- "7.4"
|
||||||
- "8.0"
|
- "8.0"
|
||||||
# disabled for now as phpspec/prophecy does not allow 8.1
|
- "8.1"
|
||||||
# - "8.1"
|
|
||||||
dependencies: [highest]
|
dependencies: [highest]
|
||||||
|
|
||||||
|
operating-system:
|
||||||
|
- "ubuntu-latest"
|
||||||
|
|
||||||
include:
|
include:
|
||||||
- php-version: "7.2"
|
- php-version: "7.2"
|
||||||
dependencies: lowest
|
dependencies: lowest
|
||||||
- php-version: "8.0"
|
operating-system: ubuntu-latest
|
||||||
|
- php-version: "8.1"
|
||||||
dependencies: lowest
|
dependencies: lowest
|
||||||
|
operating-system: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: "Checkout"
|
- name: "Checkout"
|
||||||
uses: "actions/checkout@v2"
|
uses: "actions/checkout@v2"
|
||||||
|
|
||||||
|
- name: Run CouchDB
|
||||||
|
timeout-minutes: 1
|
||||||
|
continue-on-error: true
|
||||||
|
uses: "cobot/couchdb-action@master"
|
||||||
|
with:
|
||||||
|
couchdb version: '2.3.1'
|
||||||
|
|
||||||
|
- name: Run MongoDB
|
||||||
|
uses: supercharge/mongodb-github-action@1.7.0
|
||||||
|
with:
|
||||||
|
mongodb-version: 5.0
|
||||||
|
|
||||||
- name: "Install PHP"
|
- name: "Install PHP"
|
||||||
uses: "shivammathur/setup-php@v2"
|
uses: "shivammathur/setup-php@v2"
|
||||||
with:
|
with:
|
||||||
coverage: "none"
|
coverage: "none"
|
||||||
php-version: "${{ matrix.php-version }}"
|
php-version: "${{ matrix.php-version }}"
|
||||||
extensions: mongodb, redis, amqp
|
extensions: mongodb, redis, amqp
|
||||||
|
tools: "composer:v2"
|
||||||
- name: Get composer cache directory
|
ini-values: "memory_limit=-1"
|
||||||
id: composercache
|
|
||||||
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
|
|
||||||
|
|
||||||
- name: Cache dependencies
|
|
||||||
uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: ${{ steps.composercache.outputs.dir }}
|
|
||||||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
|
|
||||||
restore-keys: ${{ runner.os }}-composer-
|
|
||||||
|
|
||||||
- name: Add require for mongodb/mongodb to make tests runnable
|
- name: Add require for mongodb/mongodb to make tests runnable
|
||||||
run: 'composer require ${{ env.COMPOSER_FLAGS }} mongodb/mongodb --dev --no-update'
|
run: 'composer require mongodb/mongodb --dev --no-update'
|
||||||
|
|
||||||
- name: "Handle lowest dependencies update"
|
- name: "Change dependencies"
|
||||||
if: "contains(matrix.dependencies, 'lowest')"
|
|
||||||
run: "echo \"COMPOSER_FLAGS=$COMPOSER_FLAGS --prefer-lowest\" >> $GITHUB_ENV"
|
|
||||||
|
|
||||||
- name: "Install latest dependencies"
|
|
||||||
run: |
|
run: |
|
||||||
composer update ${{ env.COMPOSER_FLAGS }}
|
composer require --no-update --no-interaction --dev elasticsearch/elasticsearch:^7
|
||||||
|
composer config --no-plugins allow-plugins.ocramius/package-versions true
|
||||||
|
|
||||||
|
- name: "Update dependencies with composer"
|
||||||
|
uses: "ramsey/composer-install@v1"
|
||||||
|
with:
|
||||||
|
dependency-versions: "${{ matrix.dependencies }}"
|
||||||
|
|
||||||
- name: "Run tests"
|
- name: "Run tests"
|
||||||
run: "composer exec phpunit -- --verbose"
|
run: "composer exec phpunit -- --exclude-group Elasticsearch,Elastica --verbose"
|
||||||
|
|
||||||
- name: "Run tests with psr/log 3"
|
- name: "Run tests with psr/log 3"
|
||||||
if: "contains(matrix.dependencies, 'highest') && matrix.php-version >= '8.0'"
|
if: "contains(matrix.dependencies, 'highest') && matrix.php-version >= '8.0'"
|
||||||
run: |
|
run: |
|
||||||
composer remove --no-update --dev graylog2/gelf-php ruflin/elastica elasticsearch/elasticsearch rollbar/rollbar
|
composer remove --no-update --dev graylog2/gelf-php ruflin/elastica elasticsearch/elasticsearch rollbar/rollbar
|
||||||
composer require --no-update psr/log:^3
|
composer require --no-update psr/log:^3
|
||||||
composer update -W ${{ env.COMPOSER_FLAGS }}
|
composer update -W
|
||||||
composer exec phpunit -- --verbose
|
composer exec phpunit -- --exclude-group Elasticsearch,Elastica --verbose
|
||||||
|
|
||||||
|
tests-es-7:
|
||||||
|
name: "CI with ES ${{ matrix.es-version }} on PHP ${{ matrix.php-version }}"
|
||||||
|
|
||||||
|
needs: "tests"
|
||||||
|
|
||||||
|
runs-on: "${{ matrix.operating-system }}"
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
operating-system:
|
||||||
|
- "ubuntu-latest"
|
||||||
|
|
||||||
|
php-version:
|
||||||
|
- "7.2"
|
||||||
|
- "7.3"
|
||||||
|
- "7.4"
|
||||||
|
- "8.0"
|
||||||
|
- "8.1"
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
- "highest"
|
||||||
|
- "lowest"
|
||||||
|
|
||||||
|
es-version:
|
||||||
|
- "7.0.0"
|
||||||
|
- "7.17.0"
|
||||||
|
|
||||||
|
exclude:
|
||||||
|
# php 7.3 is required
|
||||||
|
- php-version: "7.2"
|
||||||
|
es-version: "7.17.0"
|
||||||
|
# tests failing due an error in deprecated guzzlehttp/ringphp
|
||||||
|
- php-version: "7.3"
|
||||||
|
es-version: "7.0.0"
|
||||||
|
- php-version: "7.4"
|
||||||
|
es-version: "7.0.0"
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: "Checkout"
|
||||||
|
uses: "actions/checkout@v2"
|
||||||
|
|
||||||
|
# required for elasticsearch
|
||||||
|
- name: Configure sysctl limits
|
||||||
|
run: |
|
||||||
|
sudo swapoff -a
|
||||||
|
sudo sysctl -w vm.swappiness=1
|
||||||
|
sudo sysctl -w fs.file-max=262144
|
||||||
|
sudo sysctl -w vm.max_map_count=262144
|
||||||
|
|
||||||
|
- name: Run Elasticsearch
|
||||||
|
timeout-minutes: 1
|
||||||
|
uses: elastic/elastic-github-actions/elasticsearch@master
|
||||||
|
with:
|
||||||
|
stack-version: "${{ matrix.es-version }}"
|
||||||
|
|
||||||
|
- name: "Install PHP"
|
||||||
|
uses: "shivammathur/setup-php@v2"
|
||||||
|
with:
|
||||||
|
coverage: "none"
|
||||||
|
php-version: "${{ matrix.php-version }}"
|
||||||
|
extensions: mongodb, redis, amqp
|
||||||
|
tools: "composer:v2"
|
||||||
|
ini-values: "memory_limit=-1"
|
||||||
|
|
||||||
|
- name: "Change dependencies"
|
||||||
|
run: "composer require --no-update --no-interaction --dev elasticsearch/elasticsearch:^${{ matrix.es-version }}"
|
||||||
|
|
||||||
|
- name: "Update dependencies with composer"
|
||||||
|
uses: "ramsey/composer-install@v1"
|
||||||
|
with:
|
||||||
|
dependency-versions: "${{ matrix.dependencies }}"
|
||||||
|
|
||||||
|
- name: "Run tests"
|
||||||
|
run: "composer exec phpunit -- --group Elasticsearch,Elastica --verbose"
|
||||||
|
|
||||||
|
- name: "Run tests with psr/log 3"
|
||||||
|
if: "contains(matrix.dependencies, 'highest') && matrix.php-version >= '8.0'"
|
||||||
|
run: |
|
||||||
|
composer remove --no-update --dev graylog2/gelf-php ruflin/elastica elasticsearch/elasticsearch rollbar/rollbar
|
||||||
|
composer require --no-update --no-interaction --dev ruflin/elastica elasticsearch/elasticsearch:^7
|
||||||
|
composer require --no-update psr/log:^3
|
||||||
|
composer update -W
|
||||||
|
composer exec phpunit -- --group Elasticsearch,Elastica --verbose
|
||||||
|
|
||||||
|
tests-es-8:
|
||||||
|
name: "CI with ES ${{ matrix.es-version }} on PHP ${{ matrix.php-version }}"
|
||||||
|
|
||||||
|
needs: "tests"
|
||||||
|
|
||||||
|
runs-on: "${{ matrix.operating-system }}"
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
operating-system:
|
||||||
|
- "ubuntu-latest"
|
||||||
|
|
||||||
|
php-version:
|
||||||
|
# ES 8 requires PHP 7.4+
|
||||||
|
- "7.4"
|
||||||
|
- "8.0"
|
||||||
|
- "8.1"
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
- "highest"
|
||||||
|
- "lowest"
|
||||||
|
|
||||||
|
es-version:
|
||||||
|
- "8.0.0"
|
||||||
|
- "8.2.0"
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: "Checkout"
|
||||||
|
uses: "actions/checkout@v2"
|
||||||
|
|
||||||
|
# required for elasticsearch
|
||||||
|
- name: Configure sysctl limits
|
||||||
|
run: |
|
||||||
|
sudo swapoff -a
|
||||||
|
sudo sysctl -w vm.swappiness=1
|
||||||
|
sudo sysctl -w fs.file-max=262144
|
||||||
|
sudo sysctl -w vm.max_map_count=262144
|
||||||
|
|
||||||
|
- name: Run Elasticsearch
|
||||||
|
timeout-minutes: 1
|
||||||
|
uses: elastic/elastic-github-actions/elasticsearch@master
|
||||||
|
with:
|
||||||
|
stack-version: "${{ matrix.es-version }}"
|
||||||
|
|
||||||
|
- name: "Install PHP"
|
||||||
|
uses: "shivammathur/setup-php@v2"
|
||||||
|
with:
|
||||||
|
coverage: "none"
|
||||||
|
php-version: "${{ matrix.php-version }}"
|
||||||
|
extensions: mongodb, redis, amqp
|
||||||
|
tools: "composer:v2"
|
||||||
|
ini-values: "memory_limit=-1"
|
||||||
|
|
||||||
|
- name: "Change dependencies"
|
||||||
|
run: |
|
||||||
|
composer remove --no-update --dev graylog2/gelf-php ruflin/elastica elasticsearch/elasticsearch rollbar/rollbar
|
||||||
|
composer require --no-update --no-interaction --dev elasticsearch/elasticsearch:^8
|
||||||
|
|
||||||
|
- name: "Update dependencies with composer"
|
||||||
|
uses: "ramsey/composer-install@v1"
|
||||||
|
with:
|
||||||
|
dependency-versions: "${{ matrix.dependencies }}"
|
||||||
|
|
||||||
|
- name: "Run tests"
|
||||||
|
run: "composer exec phpunit -- --group Elasticsearch,Elastica --verbose"
|
||||||
|
|
||||||
|
- name: "Run tests with psr/log 3"
|
||||||
|
if: "contains(matrix.dependencies, 'highest') && matrix.php-version >= '8.0'"
|
||||||
|
run: |
|
||||||
|
composer require --no-update psr/log:^3
|
||||||
|
composer update -W
|
||||||
|
composer exec phpunit -- --group Elasticsearch,Elastica --verbose
|
||||||
|
@@ -17,19 +17,22 @@
|
|||||||
"psr/log": "^1.0.1 || ^2.0 || ^3.0"
|
"psr/log": "^1.0.1 || ^2.0 || ^3.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
"ext-json": "*",
|
||||||
"aws/aws-sdk-php": "^2.4.9 || ^3.0",
|
"aws/aws-sdk-php": "^2.4.9 || ^3.0",
|
||||||
"doctrine/couchdb": "~1.0@dev",
|
"doctrine/couchdb": "~1.0@dev",
|
||||||
"elasticsearch/elasticsearch": "^7",
|
"elasticsearch/elasticsearch": "^7 || ^8",
|
||||||
"graylog2/gelf-php": "^1.4.2",
|
"graylog2/gelf-php": "^1.4.2",
|
||||||
|
"guzzlehttp/guzzle": "^7.4",
|
||||||
|
"guzzlehttp/psr7": "^2.2",
|
||||||
"mongodb/mongodb": "^1.8",
|
"mongodb/mongodb": "^1.8",
|
||||||
"php-amqplib/php-amqplib": "~2.4 || ^3",
|
"php-amqplib/php-amqplib": "~2.4 || ^3",
|
||||||
"php-console/php-console": "^3.1.3",
|
"php-console/php-console": "^3.1.3",
|
||||||
"phpspec/prophecy": "^1.15",
|
"phpspec/prophecy": "^1.15",
|
||||||
"phpstan/phpstan": "^0.12.91",
|
"phpstan/phpstan": "^0.12.91",
|
||||||
"phpunit/phpunit": "^8.5",
|
"phpunit/phpunit": "^8.5.14",
|
||||||
"predis/predis": "^1.1",
|
"predis/predis": "^1.1",
|
||||||
"rollbar/rollbar": "^1.3 || ^2 || ^3",
|
"rollbar/rollbar": "^1.3 || ^2 || ^3",
|
||||||
"ruflin/elastica": ">=0.90@dev",
|
"ruflin/elastica": "^7",
|
||||||
"swiftmailer/swiftmailer": "^5.3|^6.0",
|
"swiftmailer/swiftmailer": "^5.3|^6.0",
|
||||||
"symfony/mailer": "^5.4 || ^6",
|
"symfony/mailer": "^5.4 || ^6",
|
||||||
"symfony/mime": "^5.4 || ^6"
|
"symfony/mime": "^5.4 || ^6"
|
||||||
@@ -72,6 +75,9 @@
|
|||||||
"config": {
|
"config": {
|
||||||
"lock": false,
|
"lock": false,
|
||||||
"sort-packages": true,
|
"sort-packages": true,
|
||||||
"platform-check": false
|
"platform-check": false,
|
||||||
|
"allow-plugins": {
|
||||||
|
"composer/package-versions-deprecated": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -35,3 +35,6 @@ parameters:
|
|||||||
- '#::popProcessor\(\) should return callable#'
|
- '#::popProcessor\(\) should return callable#'
|
||||||
- '#Parameter \#1 \$ of callable \(callable\(Monolog\\Handler\\Record\): Monolog\\Handler\\Record\)#'
|
- '#Parameter \#1 \$ of callable \(callable\(Monolog\\Handler\\Record\): Monolog\\Handler\\Record\)#'
|
||||||
- '#is incompatible with native type array.#'
|
- '#is incompatible with native type array.#'
|
||||||
|
|
||||||
|
# legacy elasticsearch namespace failures
|
||||||
|
- '# Elastic\\Elasticsearch\\#'
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Monolog\Handler;
|
namespace Monolog\Handler;
|
||||||
|
|
||||||
|
use Elastic\Elasticsearch\Response\Elasticsearch;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
@@ -19,6 +20,8 @@ use Monolog\Formatter\ElasticsearchFormatter;
|
|||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Elasticsearch\Common\Exceptions\RuntimeException as ElasticsearchRuntimeException;
|
use Elasticsearch\Common\Exceptions\RuntimeException as ElasticsearchRuntimeException;
|
||||||
use Elasticsearch\Client;
|
use Elasticsearch\Client;
|
||||||
|
use Elastic\Elasticsearch\Exception\InvalidArgumentException as ElasticInvalidArgumentException;
|
||||||
|
use Elastic\Elasticsearch\Client as Client8;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Elasticsearch handler
|
* Elasticsearch handler
|
||||||
@@ -44,7 +47,7 @@ use Elasticsearch\Client;
|
|||||||
class ElasticsearchHandler extends AbstractProcessingHandler
|
class ElasticsearchHandler extends AbstractProcessingHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Client
|
* @var Client|Client8
|
||||||
*/
|
*/
|
||||||
protected $client;
|
protected $client;
|
||||||
|
|
||||||
@@ -54,11 +57,20 @@ class ElasticsearchHandler extends AbstractProcessingHandler
|
|||||||
protected $options = [];
|
protected $options = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Client $client Elasticsearch Client object
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $needsType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Client|Client8 $client Elasticsearch Client object
|
||||||
* @param mixed[] $options Handler configuration
|
* @param mixed[] $options Handler configuration
|
||||||
*/
|
*/
|
||||||
public function __construct(Client $client, array $options = [], $level = Logger::DEBUG, bool $bubble = true)
|
public function __construct($client, array $options = [], $level = Logger::DEBUG, bool $bubble = true)
|
||||||
{
|
{
|
||||||
|
if (!$client instanceof Client && !$client instanceof Client8) {
|
||||||
|
throw new \TypeError('Elasticsearch\Client or Elastic\Elasticsearch\Client instance required');
|
||||||
|
}
|
||||||
|
|
||||||
parent::__construct($level, $bubble);
|
parent::__construct($level, $bubble);
|
||||||
$this->client = $client;
|
$this->client = $client;
|
||||||
$this->options = array_merge(
|
$this->options = array_merge(
|
||||||
@@ -69,6 +81,14 @@ class ElasticsearchHandler extends AbstractProcessingHandler
|
|||||||
],
|
],
|
||||||
$options
|
$options
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($client instanceof Client8 || $client::VERSION[0] === '7') {
|
||||||
|
$this->needsType = false;
|
||||||
|
// force the type to _doc for ES8/ES7
|
||||||
|
$this->options['type'] = '_doc';
|
||||||
|
} else {
|
||||||
|
$this->needsType = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -133,9 +153,11 @@ class ElasticsearchHandler extends AbstractProcessingHandler
|
|||||||
|
|
||||||
foreach ($records as $record) {
|
foreach ($records as $record) {
|
||||||
$params['body'][] = [
|
$params['body'][] = [
|
||||||
'index' => [
|
'index' => $this->needsType ? [
|
||||||
'_index' => $record['_index'],
|
'_index' => $record['_index'],
|
||||||
'_type' => $record['_type'],
|
'_type' => $record['_type'],
|
||||||
|
] : [
|
||||||
|
'_index' => $record['_index'],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
unset($record['_index'], $record['_type']);
|
unset($record['_index'], $record['_type']);
|
||||||
@@ -143,6 +165,7 @@ class ElasticsearchHandler extends AbstractProcessingHandler
|
|||||||
$params['body'][] = $record;
|
$params['body'][] = $record;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @var Elasticsearch */
|
||||||
$responses = $this->client->bulk($params);
|
$responses = $this->client->bulk($params);
|
||||||
|
|
||||||
if ($responses['errors'] === true) {
|
if ($responses['errors'] === true) {
|
||||||
@@ -160,9 +183,9 @@ class ElasticsearchHandler extends AbstractProcessingHandler
|
|||||||
*
|
*
|
||||||
* Only the first error is converted into an exception.
|
* Only the first error is converted into an exception.
|
||||||
*
|
*
|
||||||
* @param mixed[] $responses returned by $this->client->bulk()
|
* @param mixed[]|Elasticsearch $responses returned by $this->client->bulk()
|
||||||
*/
|
*/
|
||||||
protected function createExceptionFromResponses(array $responses): ElasticsearchRuntimeException
|
protected function createExceptionFromResponses($responses): Throwable
|
||||||
{
|
{
|
||||||
foreach ($responses['items'] ?? [] as $item) {
|
foreach ($responses['items'] ?? [] as $item) {
|
||||||
if (isset($item['index']['error'])) {
|
if (isset($item['index']['error'])) {
|
||||||
@@ -170,6 +193,10 @@ class ElasticsearchHandler extends AbstractProcessingHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (class_exists(ElasticInvalidArgumentException::class)) {
|
||||||
|
return new ElasticInvalidArgumentException('Elasticsearch failed to index one or more records.');
|
||||||
|
}
|
||||||
|
|
||||||
return new ElasticsearchRuntimeException('Elasticsearch failed to index one or more records.');
|
return new ElasticsearchRuntimeException('Elasticsearch failed to index one or more records.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,10 +205,14 @@ class ElasticsearchHandler extends AbstractProcessingHandler
|
|||||||
*
|
*
|
||||||
* @param mixed[] $error
|
* @param mixed[] $error
|
||||||
*/
|
*/
|
||||||
protected function createExceptionFromError(array $error): ElasticsearchRuntimeException
|
protected function createExceptionFromError(array $error): Throwable
|
||||||
{
|
{
|
||||||
$previous = isset($error['caused_by']) ? $this->createExceptionFromError($error['caused_by']) : null;
|
$previous = isset($error['caused_by']) ? $this->createExceptionFromError($error['caused_by']) : null;
|
||||||
|
|
||||||
|
if (class_exists(ElasticInvalidArgumentException::class)) {
|
||||||
|
return new ElasticInvalidArgumentException($error['type'] . ': ' . $error['reason'], 0, $previous);
|
||||||
|
}
|
||||||
|
|
||||||
return new ElasticsearchRuntimeException($error['type'] . ': ' . $error['reason'], 0, $previous);
|
return new ElasticsearchRuntimeException($error['type'] . ': ' . $error['reason'], 0, $previous);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,6 +25,15 @@ use Monolog\Formatter\FormatterInterface;
|
|||||||
*/
|
*/
|
||||||
class TestCase extends \PHPUnit\Framework\TestCase
|
class TestCase extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
if (isset($this->handler)) {
|
||||||
|
unset($this->handler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed[] $context
|
* @param mixed[] $context
|
||||||
*
|
*
|
||||||
|
@@ -22,6 +22,13 @@ class ScalarFormatterTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->formatter = new ScalarFormatter();
|
$this->formatter = new ScalarFormatter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
unset($this->formatter);
|
||||||
|
}
|
||||||
|
|
||||||
public function buildTrace(\Exception $e)
|
public function buildTrace(\Exception $e)
|
||||||
{
|
{
|
||||||
$data = [];
|
$data = [];
|
||||||
|
@@ -78,7 +78,7 @@ class AmqpHandlerTest extends TestCase
|
|||||||
|
|
||||||
public function testHandlePhpAmqpLib()
|
public function testHandlePhpAmqpLib()
|
||||||
{
|
{
|
||||||
if (!class_exists('PhpAmqpLib\Connection\AMQPConnection')) {
|
if (!class_exists('PhpAmqpLib\Channel\AMQPChannel')) {
|
||||||
$this->markTestSkipped("php-amqplib not installed");
|
$this->markTestSkipped("php-amqplib not installed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -45,6 +45,13 @@ class DynamoDbHandlerTest extends TestCase
|
|||||||
$this->client = $clientMockBuilder->getMock();
|
$this->client = $clientMockBuilder->getMock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
unset($this->client);
|
||||||
|
}
|
||||||
|
|
||||||
public function testConstruct()
|
public function testConstruct()
|
||||||
{
|
{
|
||||||
$this->assertInstanceOf('Monolog\Handler\DynamoDbHandler', new DynamoDbHandler($this->client, 'foo'));
|
$this->assertInstanceOf('Monolog\Handler\DynamoDbHandler', new DynamoDbHandler($this->client, 'foo'));
|
||||||
|
@@ -19,6 +19,9 @@ use Elastica\Client;
|
|||||||
use Elastica\Request;
|
use Elastica\Request;
|
||||||
use Elastica\Response;
|
use Elastica\Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group Elastica
|
||||||
|
*/
|
||||||
class ElasticaHandlerTest extends TestCase
|
class ElasticaHandlerTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -48,6 +51,13 @@ class ElasticaHandlerTest extends TestCase
|
|||||||
->getMock();
|
->getMock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
unset($this->client);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Monolog\Handler\ElasticaHandler::write
|
* @covers Monolog\Handler\ElasticaHandler::write
|
||||||
* @covers Monolog\Handler\ElasticaHandler::handleBatch
|
* @covers Monolog\Handler\ElasticaHandler::handleBatch
|
||||||
@@ -155,60 +165,6 @@ class ElasticaHandlerTest extends TestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Integration test using localhost Elastic Search server version <7
|
|
||||||
*
|
|
||||||
* @covers Monolog\Handler\ElasticaHandler::__construct
|
|
||||||
* @covers Monolog\Handler\ElasticaHandler::handleBatch
|
|
||||||
* @covers Monolog\Handler\ElasticaHandler::bulkSend
|
|
||||||
* @covers Monolog\Handler\ElasticaHandler::getDefaultFormatter
|
|
||||||
*/
|
|
||||||
public function testHandleIntegration()
|
|
||||||
{
|
|
||||||
$msg = [
|
|
||||||
'level' => Logger::ERROR,
|
|
||||||
'level_name' => 'ERROR',
|
|
||||||
'channel' => 'meh',
|
|
||||||
'context' => ['foo' => 7, 'bar', 'class' => new \stdClass],
|
|
||||||
'datetime' => new \DateTimeImmutable("@0"),
|
|
||||||
'extra' => [],
|
|
||||||
'message' => 'log',
|
|
||||||
];
|
|
||||||
|
|
||||||
$expected = $msg;
|
|
||||||
$expected['datetime'] = $msg['datetime']->format(\DateTime::ISO8601);
|
|
||||||
$expected['context'] = [
|
|
||||||
'class' => '[object] (stdClass: {})',
|
|
||||||
'foo' => 7,
|
|
||||||
0 => 'bar',
|
|
||||||
];
|
|
||||||
|
|
||||||
$client = new Client();
|
|
||||||
$handler = new ElasticaHandler($client, $this->options);
|
|
||||||
|
|
||||||
try {
|
|
||||||
$handler->handleBatch([$msg]);
|
|
||||||
} catch (\RuntimeException $e) {
|
|
||||||
$this->markTestSkipped("Cannot connect to Elastic Search server on localhost");
|
|
||||||
}
|
|
||||||
|
|
||||||
// check document id from ES server response
|
|
||||||
$documentId = $this->getCreatedDocId($client->getLastResponse());
|
|
||||||
$this->assertNotEmpty($documentId, 'No elastic document id received');
|
|
||||||
|
|
||||||
// retrieve document source from ES and validate
|
|
||||||
$document = $this->getDocSourceFromElastic(
|
|
||||||
$client,
|
|
||||||
$this->options['index'],
|
|
||||||
$this->options['type'],
|
|
||||||
$documentId
|
|
||||||
);
|
|
||||||
$this->assertEquals($expected, $document);
|
|
||||||
|
|
||||||
// remove test index from ES
|
|
||||||
$client->request("/{$this->options['index']}", Request::DELETE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration test using localhost Elastic Search server version 7+
|
* Integration test using localhost Elastic Search server version 7+
|
||||||
*
|
*
|
||||||
@@ -237,7 +193,9 @@ class ElasticaHandlerTest extends TestCase
|
|||||||
0 => 'bar',
|
0 => 'bar',
|
||||||
];
|
];
|
||||||
|
|
||||||
$client = new Client();
|
$clientOpts = ['url' => 'http://elastic:changeme@127.0.0.1:9200'];
|
||||||
|
$client = new Client($clientOpts);
|
||||||
|
|
||||||
$handler = new ElasticaHandler($client, $this->options);
|
$handler = new ElasticaHandler($client, $this->options);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -271,9 +229,14 @@ class ElasticaHandlerTest extends TestCase
|
|||||||
protected function getCreatedDocId(Response $response)
|
protected function getCreatedDocId(Response $response)
|
||||||
{
|
{
|
||||||
$data = $response->getData();
|
$data = $response->getData();
|
||||||
if (!empty($data['items'][0]['create']['_id'])) {
|
|
||||||
return $data['items'][0]['create']['_id'];
|
if (!empty($data['items'][0]['index']['_id'])) {
|
||||||
|
return $data['items'][0]['index']['_id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var_dump('Unexpected response: ', $data);
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -11,17 +11,22 @@
|
|||||||
|
|
||||||
namespace Monolog\Handler;
|
namespace Monolog\Handler;
|
||||||
|
|
||||||
use Elasticsearch\ClientBuilder;
|
|
||||||
use Monolog\Formatter\ElasticsearchFormatter;
|
use Monolog\Formatter\ElasticsearchFormatter;
|
||||||
use Monolog\Formatter\NormalizerFormatter;
|
use Monolog\Formatter\NormalizerFormatter;
|
||||||
use Monolog\Test\TestCase;
|
use Monolog\Test\TestCase;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
use Elasticsearch\Client;
|
use Elasticsearch\Client;
|
||||||
|
use Elastic\Elasticsearch\Client as Client8;
|
||||||
|
use Elasticsearch\ClientBuilder;
|
||||||
|
use Elastic\Elasticsearch\ClientBuilder as ClientBuilder8;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group Elasticsearch
|
||||||
|
*/
|
||||||
class ElasticsearchHandlerTest extends TestCase
|
class ElasticsearchHandlerTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Client mock
|
* @var Client|Client8 mock
|
||||||
*/
|
*/
|
||||||
protected $client;
|
protected $client;
|
||||||
|
|
||||||
@@ -35,63 +40,23 @@ class ElasticsearchHandlerTest extends TestCase
|
|||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
// Elasticsearch lib required
|
$hosts = ['http://elastic:changeme@127.0.0.1:9200'];
|
||||||
if (!class_exists('Elasticsearch\Client')) {
|
$this->client = $this->getClientBuilder()
|
||||||
$this->markTestSkipped('elasticsearch/elasticsearch not installed');
|
->setHosts($hosts)
|
||||||
|
->build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->client->info();
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
$this->markTestSkipped('Could not connect to Elasticsearch on 127.0.0.1:9200');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// base mock Elasticsearch Client object
|
public function tearDown(): void
|
||||||
$this->client = $this->getMockBuilder('Elasticsearch\Client')
|
|
||||||
->onlyMethods(['bulk'])
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers Monolog\Handler\ElasticsearchHandler::write
|
|
||||||
* @covers Monolog\Handler\ElasticsearchHandler::handleBatch
|
|
||||||
* @covers Monolog\Handler\ElasticsearchHandler::bulkSend
|
|
||||||
* @covers Monolog\Handler\ElasticsearchHandler::getDefaultFormatter
|
|
||||||
*/
|
|
||||||
public function testHandle()
|
|
||||||
{
|
{
|
||||||
// log message
|
parent::tearDown();
|
||||||
$msg = [
|
|
||||||
'level' => Logger::ERROR,
|
|
||||||
'level_name' => 'ERROR',
|
|
||||||
'channel' => 'meh',
|
|
||||||
'context' => ['foo' => 7, 'bar', 'class' => new \stdClass],
|
|
||||||
'datetime' => new \DateTimeImmutable("@0"),
|
|
||||||
'extra' => [],
|
|
||||||
'message' => 'log',
|
|
||||||
];
|
|
||||||
|
|
||||||
// format expected result
|
unset($this->client);
|
||||||
$formatter = new ElasticsearchFormatter($this->options['index'], $this->options['type']);
|
|
||||||
$data = $formatter->format($msg);
|
|
||||||
unset($data['_index'], $data['_type']);
|
|
||||||
|
|
||||||
$expected = [
|
|
||||||
'body' => [
|
|
||||||
[
|
|
||||||
'index' => [
|
|
||||||
'_index' => $this->options['index'],
|
|
||||||
'_type' => $this->options['type'],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
$data,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
// setup ES client mock
|
|
||||||
$this->client->expects($this->any())
|
|
||||||
->method('bulk')
|
|
||||||
->with($expected);
|
|
||||||
|
|
||||||
// perform tests
|
|
||||||
$handler = new ElasticsearchHandler($this->client, $this->options);
|
|
||||||
$handler->handle($msg);
|
|
||||||
$handler->handleBatch([$msg]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -132,6 +97,11 @@ class ElasticsearchHandlerTest extends TestCase
|
|||||||
'type' => $this->options['type'],
|
'type' => $this->options['type'],
|
||||||
'ignore_error' => false,
|
'ignore_error' => false,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if ($this->client instanceof Client8 || $this->client::VERSION[0] === '7') {
|
||||||
|
$expected['type'] = '_doc';
|
||||||
|
}
|
||||||
|
|
||||||
$handler = new ElasticsearchHandler($this->client, $this->options);
|
$handler = new ElasticsearchHandler($this->client, $this->options);
|
||||||
$this->assertEquals($expected, $handler->getOptions());
|
$this->assertEquals($expected, $handler->getOptions());
|
||||||
}
|
}
|
||||||
@@ -142,8 +112,8 @@ class ElasticsearchHandlerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testConnectionErrors($ignore, $expectedError)
|
public function testConnectionErrors($ignore, $expectedError)
|
||||||
{
|
{
|
||||||
$hosts = [['host' => '127.0.0.1', 'port' => 1]];
|
$hosts = ['http://127.0.0.1:1'];
|
||||||
$client = ClientBuilder::create()
|
$client = $this->getClientBuilder()
|
||||||
->setHosts($hosts)
|
->setHosts($hosts)
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
@@ -178,7 +148,7 @@ class ElasticsearchHandlerTest extends TestCase
|
|||||||
* @covers Monolog\Handler\ElasticsearchHandler::bulkSend
|
* @covers Monolog\Handler\ElasticsearchHandler::bulkSend
|
||||||
* @covers Monolog\Handler\ElasticsearchHandler::getDefaultFormatter
|
* @covers Monolog\Handler\ElasticsearchHandler::getDefaultFormatter
|
||||||
*/
|
*/
|
||||||
public function testHandleIntegration()
|
public function testHandleBatchIntegration()
|
||||||
{
|
{
|
||||||
$msg = [
|
$msg = [
|
||||||
'level' => Logger::ERROR,
|
'level' => Logger::ERROR,
|
||||||
@@ -198,21 +168,26 @@ class ElasticsearchHandlerTest extends TestCase
|
|||||||
0 => 'bar',
|
0 => 'bar',
|
||||||
];
|
];
|
||||||
|
|
||||||
$hosts = [['host' => '127.0.0.1', 'port' => 9200]];
|
$hosts = ['http://elastic:changeme@127.0.0.1:9200'];
|
||||||
$client = ClientBuilder::create()
|
$client = $this->getClientBuilder()
|
||||||
->setHosts($hosts)
|
->setHosts($hosts)
|
||||||
->build();
|
->build();
|
||||||
$handler = new ElasticsearchHandler($client, $this->options);
|
$handler = new ElasticsearchHandler($client, $this->options);
|
||||||
|
|
||||||
try {
|
|
||||||
$handler->handleBatch([$msg]);
|
$handler->handleBatch([$msg]);
|
||||||
} catch (\RuntimeException $e) {
|
|
||||||
$this->markTestSkipped('Cannot connect to Elasticsearch server on localhost');
|
|
||||||
}
|
|
||||||
|
|
||||||
// check document id from ES server response
|
// check document id from ES server response
|
||||||
|
if ($client instanceof Client8) {
|
||||||
|
$messageBody = $client->getTransport()->getLastResponse()->getBody();
|
||||||
|
|
||||||
|
$info = json_decode((string) $messageBody, true);
|
||||||
|
$this->assertNotNull($info, 'Decoding failed');
|
||||||
|
|
||||||
|
$documentId = $this->getCreatedDocIdV8($info);
|
||||||
|
$this->assertNotEmpty($documentId, 'No elastic document id received');
|
||||||
|
} else {
|
||||||
$documentId = $this->getCreatedDocId($client->transport->getLastConnection()->getLastRequestInfo());
|
$documentId = $this->getCreatedDocId($client->transport->getLastConnection()->getLastRequestInfo());
|
||||||
$this->assertNotEmpty($documentId, 'No elastic document id received');
|
$this->assertNotEmpty($documentId, 'No elastic document id received');
|
||||||
|
}
|
||||||
|
|
||||||
// retrieve document source from ES and validate
|
// retrieve document source from ES and validate
|
||||||
$document = $this->getDocSourceFromElastic(
|
$document = $this->getDocSourceFromElastic(
|
||||||
@@ -241,25 +216,45 @@ class ElasticsearchHandlerTest extends TestCase
|
|||||||
if (!empty($data['items'][0]['index']['_id'])) {
|
if (!empty($data['items'][0]['index']['_id'])) {
|
||||||
return $data['items'][0]['index']['_id'];
|
return $data['items'][0]['index']['_id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return last created document id from ES response
|
||||||
|
*
|
||||||
|
* @param array $data Elasticsearch last request info
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
protected function getCreatedDocIdV8(array $data)
|
||||||
|
{
|
||||||
|
if (!empty($data['items'][0]['index']['_id'])) {
|
||||||
|
return $data['items'][0]['index']['_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve document by id from Elasticsearch
|
* Retrieve document by id from Elasticsearch
|
||||||
*
|
*
|
||||||
* @param Client $client Elasticsearch client
|
* @param Client|Client8 $client Elasticsearch client
|
||||||
* @param string $index
|
* @param string $index
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param string $documentId
|
* @param string $documentId
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getDocSourceFromElastic(Client $client, $index, $type, $documentId)
|
protected function getDocSourceFromElastic($client, $index, $type, $documentId)
|
||||||
{
|
{
|
||||||
$params = [
|
$params = [
|
||||||
'index' => $index,
|
'index' => $index,
|
||||||
'type' => $type,
|
|
||||||
'id' => $documentId,
|
'id' => $documentId,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (!$client instanceof Client8 && $client::VERSION[0] !== '7') {
|
||||||
|
$params['type'] = $type;
|
||||||
|
}
|
||||||
|
|
||||||
$data = $client->get($params);
|
$data = $client->get($params);
|
||||||
|
|
||||||
if (!empty($data['_source'])) {
|
if (!empty($data['_source'])) {
|
||||||
@@ -268,4 +263,16 @@ class ElasticsearchHandlerTest extends TestCase
|
|||||||
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return ClientBuilder|ClientBuilder8
|
||||||
|
*/
|
||||||
|
private function getClientBuilder()
|
||||||
|
{
|
||||||
|
if (class_exists(ClientBuilder8::class)) {
|
||||||
|
return ClientBuilder8::create();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ClientBuilder::create();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -38,6 +38,13 @@ class FlowdockHandlerTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
unset($this->res);
|
||||||
|
}
|
||||||
|
|
||||||
public function testWriteHeader()
|
public function testWriteHeader()
|
||||||
{
|
{
|
||||||
$this->createHandler();
|
$this->createHandler();
|
||||||
|
@@ -32,6 +32,13 @@ class HandlerWrapperTest extends TestCase
|
|||||||
$this->wrapper = new HandlerWrapper($this->handler);
|
$this->wrapper = new HandlerWrapper($this->handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
unset($this->wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
@@ -30,6 +30,13 @@ class InsightOpsHandlerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
private $handler;
|
private $handler;
|
||||||
|
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
unset($this->resource);
|
||||||
|
}
|
||||||
|
|
||||||
public function testWriteContent()
|
public function testWriteContent()
|
||||||
{
|
{
|
||||||
$this->createHandler();
|
$this->createHandler();
|
||||||
|
@@ -29,6 +29,13 @@ class LogEntriesHandlerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
private $handler;
|
private $handler;
|
||||||
|
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
unset($this->res);
|
||||||
|
}
|
||||||
|
|
||||||
public function testWriteContent()
|
public function testWriteContent()
|
||||||
{
|
{
|
||||||
$this->createHandler();
|
$this->createHandler();
|
||||||
|
@@ -29,6 +29,13 @@ class LogmaticHandlerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
private $handler;
|
private $handler;
|
||||||
|
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
unset($this->res);
|
||||||
|
}
|
||||||
|
|
||||||
public function testWriteContent()
|
public function testWriteContent()
|
||||||
{
|
{
|
||||||
$this->createHandler();
|
$this->createHandler();
|
||||||
|
@@ -56,6 +56,13 @@ class PHPConsoleHandlerTest extends TestCase
|
|||||||
$this->connector->setErrorsDispatcher($this->errorDispatcher);
|
$this->connector->setErrorsDispatcher($this->errorDispatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
unset($this->connector, $this->debugDispatcher, $this->errorDispatcher);
|
||||||
|
}
|
||||||
|
|
||||||
protected function initDebugDispatcherMock(Connector $connector)
|
protected function initDebugDispatcherMock(Connector $connector)
|
||||||
{
|
{
|
||||||
return $this->getMockBuilder('PhpConsole\Dispatcher\Debug')
|
return $this->getMockBuilder('PhpConsole\Dispatcher\Debug')
|
||||||
|
@@ -25,6 +25,13 @@ class PushoverHandlerTest extends TestCase
|
|||||||
private $res;
|
private $res;
|
||||||
private $handler;
|
private $handler;
|
||||||
|
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
unset($this->res);
|
||||||
|
}
|
||||||
|
|
||||||
public function testWriteHeader()
|
public function testWriteHeader()
|
||||||
{
|
{
|
||||||
$this->createHandler();
|
$this->createHandler();
|
||||||
|
@@ -44,6 +44,13 @@ class RollbarHandlerTest extends TestCase
|
|||||||
$this->setupRollbarLoggerMock();
|
$this->setupRollbarLoggerMock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
unset($this->rollbarLogger, $this->reportedExceptionArguments);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When reporting exceptions to Rollbar the
|
* When reporting exceptions to Rollbar the
|
||||||
* level has to be set in the payload data
|
* level has to be set in the payload data
|
||||||
|
@@ -39,6 +39,18 @@ class RotatingFileHandlerTest extends TestCase
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
foreach (glob(__DIR__.'/Fixtures/*.rot') as $file) {
|
||||||
|
unlink($file);
|
||||||
|
}
|
||||||
|
restore_error_handler();
|
||||||
|
|
||||||
|
unset($this->lastError);
|
||||||
|
}
|
||||||
|
|
||||||
private function assertErrorWasTriggered($code, $message)
|
private function assertErrorWasTriggered($code, $message)
|
||||||
{
|
{
|
||||||
if (empty($this->lastError)) {
|
if (empty($this->lastError)) {
|
||||||
@@ -239,12 +251,4 @@ class RotatingFileHandlerTest extends TestCase
|
|||||||
$handler->handle($this->getRecord());
|
$handler->handle($this->getRecord());
|
||||||
$this->assertEquals('footest', file_get_contents($log));
|
$this->assertEquals('footest', file_get_contents($log));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown(): void
|
|
||||||
{
|
|
||||||
foreach (glob(__DIR__.'/Fixtures/*.rot') as $file) {
|
|
||||||
unlink($file);
|
|
||||||
}
|
|
||||||
restore_error_handler();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -39,6 +39,13 @@ class SlackHandlerTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
unset($this->res);
|
||||||
|
}
|
||||||
|
|
||||||
public function testWriteHeader()
|
public function testWriteHeader()
|
||||||
{
|
{
|
||||||
$this->createHandler();
|
$this->createHandler();
|
||||||
|
@@ -30,6 +30,13 @@ class SocketHandlerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
private $res;
|
private $res;
|
||||||
|
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
unset($this->res);
|
||||||
|
}
|
||||||
|
|
||||||
public function testInvalidHostname()
|
public function testInvalidHostname()
|
||||||
{
|
{
|
||||||
$this->expectException(\UnexpectedValueException::class);
|
$this->expectException(\UnexpectedValueException::class);
|
||||||
|
@@ -271,20 +271,20 @@ STRING;
|
|||||||
$this->markTestSkipped('We could not set a memory limit that would trigger the error.');
|
$this->markTestSkipped('We could not set a memory limit that would trigger the error.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
$stream = tmpfile();
|
$stream = tmpfile();
|
||||||
|
|
||||||
if ($stream === false) {
|
if ($stream === false) {
|
||||||
$this->markTestSkipped('We could not create a temp file to be use as a stream.');
|
$this->markTestSkipped('We could not create a temp file to be use as a stream.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$exceptionRaised = false;
|
|
||||||
|
|
||||||
$handler = new StreamHandler($stream);
|
$handler = new StreamHandler($stream);
|
||||||
stream_get_contents($stream, 1024);
|
stream_get_contents($stream, 1024);
|
||||||
|
|
||||||
ini_set('memory_limit', $previousValue);
|
|
||||||
|
|
||||||
$this->assertEquals($expectedChunkSize, $handler->getStreamChunkSize());
|
$this->assertEquals($expectedChunkSize, $handler->getStreamChunkSize());
|
||||||
|
} finally {
|
||||||
|
ini_set('memory_limit', $previousValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -298,10 +298,13 @@ STRING;
|
|||||||
$this->markTestSkipped('We could not set a memory limit that would trigger the error.');
|
$this->markTestSkipped('We could not set a memory limit that would trigger the error.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
$stream = tmpfile();
|
$stream = tmpfile();
|
||||||
new StreamHandler($stream);
|
new StreamHandler($stream);
|
||||||
stream_get_contents($stream);
|
stream_get_contents($stream);
|
||||||
ini_set('memory_limit', $previousValue);
|
|
||||||
$this->assertTrue(true);
|
$this->assertTrue(true);
|
||||||
|
} finally {
|
||||||
|
ini_set('memory_limit', $previousValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,6 +28,13 @@ class SwiftMailerHandlerTest extends TestCase
|
|||||||
->getMock();
|
->getMock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
unset($this->mailer);
|
||||||
|
}
|
||||||
|
|
||||||
public function testMessageCreationIsLazyWhenUsingCallback()
|
public function testMessageCreationIsLazyWhenUsingCallback()
|
||||||
{
|
{
|
||||||
$this->mailer->expects($this->never())
|
$this->mailer->expects($this->never())
|
||||||
|
@@ -30,6 +30,13 @@ class SymfonyMailerHandlerTest extends TestCase
|
|||||||
->getMock();
|
->getMock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
unset($this->mailer);
|
||||||
|
}
|
||||||
|
|
||||||
public function testMessageCreationIsLazyWhenUsingCallback()
|
public function testMessageCreationIsLazyWhenUsingCallback()
|
||||||
{
|
{
|
||||||
$this->mailer->expects($this->never())
|
$this->mailer->expects($this->never())
|
||||||
|
@@ -25,6 +25,13 @@ class ZendMonitorHandlerTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
unset($this->zendMonitorHandler);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Monolog\Handler\ZendMonitorHandler::write
|
* @covers Monolog\Handler\ZendMonitorHandler::write
|
||||||
*/
|
*/
|
||||||
|
@@ -25,6 +25,13 @@ class PsrLogCompatTest extends TestCase
|
|||||||
{
|
{
|
||||||
private $handler;
|
private $handler;
|
||||||
|
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
unset($this->handler);
|
||||||
|
}
|
||||||
|
|
||||||
public function getLogger(): LoggerInterface
|
public function getLogger(): LoggerInterface
|
||||||
{
|
{
|
||||||
$logger = new Logger('foo');
|
$logger = new Logger('foo');
|
||||||
|
@@ -39,8 +39,10 @@ class SignalHandlerTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown(): void
|
public function tearDown(): void
|
||||||
{
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
if ($this->asyncSignalHandling !== null) {
|
if ($this->asyncSignalHandling !== null) {
|
||||||
pcntl_async_signals($this->asyncSignalHandling);
|
pcntl_async_signals($this->asyncSignalHandling);
|
||||||
}
|
}
|
||||||
@@ -53,6 +55,8 @@ class SignalHandlerTest extends TestCase
|
|||||||
pcntl_signal($signo, $handler);
|
pcntl_signal($signo, $handler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unset($this->signalHandlers, $this->blockedSignals, $this->asyncSignalHandling);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setSignalHandler($signo, $handler = SIG_DFL)
|
private function setSignalHandler($signo, $handler = SIG_DFL)
|
||||||
|
Reference in New Issue
Block a user