Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop support Sf 4.4 & add CI #4

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
/tests export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

# Ignore all test and documentation with "export-ignore".
/.github export-ignore
/tests export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/phpunit.xml export-ignore
23 changes: 23 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 60

# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7

# Issues with these labels will never be considered stale
exemptLabels:
- bug
- enhancement
- RFC

# Label to use when marking an issue as stale
staleLabel: stale

# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.

# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: false
96 changes: 96 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: PHPUnit

on:
push:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

permissions:
contents: read

jobs:

test:
name: "PHP ${{ matrix.php }} - Symfony ${{ matrix.symfony }}"
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.can-fail }}

strategy:
fail-fast: false
matrix:
include:
# Lowest Deps
- php: 7.4
symfony: 5.4.*
coverage: 'none'
composer-flags: '--prefer-stable --prefer-lowest'
can-fail: false
# LTS with latest stable PHP
- php: 8.2
symfony: 5.4.*
coverage: 'none'
composer-flags: '--prefer-stable'
can-fail: false
# Active release
- php: 8.2
symfony: 6.2.*
coverage: pcov
composer-flags: '--prefer-stable'
can-fail: false
# Development release
- php: 8.3
symfony: 6.3.*@dev
coverage: 'none'
composer-flags: ''
can-fail: true

steps:
- name: Checkout
uses: action/checkout@v3
with:
fetch-depth: 2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2, flex
coverage: ${{ matrix.coverage }}
ini-values: date.timezone=UTC,memory_limit=-1,session.gc_probability=0,apc.enable_cli=1,zend.assertions=1
env:
fail-fast: true

- name: Set Composer stability
if: matrix.symfony == '6.3.*@dev'
run: "composer config minimum-stability dev"

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache composer dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: php-${{ matrix.php }}-symfony-${{ matrix.symfony }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: php-${{ matrix.php }}-symfony-${{ matrix.symfony }}-composer-

- name: Install Composer dependencies
run: composer update ${{ matrix.composer-flags }} --no-interaction --no-progress --optimize-autoloader
env:
SYMFONY_REQUIRE: ${{ matrix.symfony }}

- name: Run tests
run: composer test

- name: Monitor coverage
if: matrix.coverage != 'none'
uses: slavcodev/coverage-monitor-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
coverage_path: coverage-report.xml
threshold_alert: 60
threshold_warning: 80
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.php_cs.cache
.phpunit.result.cache
composer.lock
coverage-report.xml
2 changes: 0 additions & 2 deletions CHANGELOG.md

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2021-2021 OD&B
Copyright (c) 2021-present OD&B

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
49 changes: 28 additions & 21 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"name": "odandb/monitoring-metrics-bundle",
"type": "symfony-bundle",
"description": "Provides metrics and assertions for functional testing",
"license": "MIT",
"type": "symfony-bundle",
"keywords": [
"symfony",
"bundle",
"phpunit",
"assert",
"testing"
],
"license": "MIT",
"authors": [
{
"name": "Maxime Hélias",
Expand All @@ -20,29 +22,31 @@
],
"require": {
"php": ">=7.4",
"symfony/config": "^4.4|^5.1|^6.0",
"symfony/dependency-injection": "^4.4|^5.1|^6.0",
"symfony/event-dispatcher": "^4.4|^5.1|^6.0",
"symfony/framework-bundle": "^4.4|^5.1|^6.0",
"symfony/http-kernel": "^4.4|^5.2|^6.0"
},
"conflict": {
"phpunit/phpunit": "<8.0"
"symfony/config": "^5.4 || ^6.0",
"symfony/dependency-injection": "^5.4 || ^6.0",
"symfony/event-dispatcher": "^5.4 || ^6.0",
"symfony/framework-bundle": "^5.4 || ^6.0",
"symfony/http-foundation": "^5.4 || ^6.0",
"symfony/http-kernel": "^5.4 || ^6.0",
"symfony/service-contracts": "^3.2"
},
"require-dev": {
"doctrine/annotations": "^2.0",
"doctrine/doctrine-bundle": "^2.0",
"doctrine/orm": "^2.9",
"phpunit/phpunit": "^9.3",
"symfony/browser-kit": "^4.4|^5.1|^6.0",
"symfony/phpunit-bridge": "^4.4|^5.1|^6.0",
"symfony/yaml": "^5.3|^6.0"
"doctrine/doctrine-bundle": "^2.8",
"doctrine/orm": "^2.10",
"phpunit/phpunit": "^9.5",
"symfony/browser-kit": "^5.4 || ^6.0",
"symfony/doctrine-bridge": "^5.4.7 || ^6.0",
"symfony/phpunit-bridge": "^5.4 || ^6.0",
"symfony/yaml": "^5.4 || ^6.0"
},
"config": {
"sort-packages": true
"conflict": {
"doctrine/dbal": "<3.3",
"phpunit/phpunit": "<8.0",
"symfony/doctrine-bridge": "<5.4.7"
},
"suggest": {
"doctrine/doctrine-bundle": "To retrieve information related to doctrine"
"doctrine/doctrine-bundle": "To retrieve information related to doctrine",
"phpunit/phpunit": "To use assertion trait with PHPUnit"
},
"autoload": {
"psr-4": {
Expand All @@ -54,7 +58,10 @@
"Odandb\\MonitoringMetricsBundle\\Tests\\": "tests/"
}
},
"config": {
"sort-packages": true
},
"scripts": {
"test": "vendor/bin/phpunit"
"test": "vendor/bin/phpunit --coverage-clover=coverage-report.xml"
}
}
7 changes: 1 addition & 6 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,13 @@
use Odandb\MonitoringMetricsBundle\Metric\MetricRegistry;
use Symfony\Component\DependencyInjection\Reference;

return static function (ContainerConfigurator $container) {
return static function (ContainerConfigurator $container): void {
$container->services()
->instanceof(AbstractMetric::class)
->tag('monitoring.metric')

->set('monitoring.metrics', MetricRegistry::class)

->set('monitoring.metric.doctrine', DoctrineMetric::class)
->args([
service('doctrine.debug_data_holder')->nullOnInvalid()
])
->tag('monitoring.metric')
->set('monitoring.metric.memory', MemoryMetric::class)
->tag('monitoring.metric')

Expand Down
6 changes: 2 additions & 4 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
bootstrap="tests/phpunit-bootstrap.php"
colors="true"
convertDeprecationsToExceptions="false"
verbose="true" >

<php>
Expand All @@ -15,12 +13,12 @@
<server name="APP_ENV" value="test" force="true" />
<server name="APP_DEBUG" value="1" force="true" />
<server name="SHELL_VERBOSITY" value="-1" />
<server name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0" />
<server name="SYMFONY_DEPRECATIONS_HELPER" value="max[total]=30&amp;max[self]=0" />
</php>

<testsuites>
<testsuite name="MonitoringMetricsBundle test suite">
<directory suffix="Test.php">./tests/Functional</directory>
<directory>./tests/Functional</directory>
</testsuite>
</testsuites>

Expand Down
44 changes: 10 additions & 34 deletions src/DependencyInjection/Compiler/AddDoctrineLoggerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,26 @@

namespace Odandb\MonitoringMetricsBundle\DependencyInjection\Compiler;

use Odandb\MonitoringMetricsBundle\Metric\DoctrineMetric;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class AddDoctrineLoggerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
if (!$container->has('monitoring.metric.doctrine')) {
if (!$container->has('doctrine.debug_data_holder')) {
return;
}

// With DebugDataHolder, no need to use logger
if ($container->has('doctrine.debug_data_holder')) {
return;
}

$definition = $container->getDefinition('monitoring.metric.doctrine');

$connections = $container->getParameter('doctrine.connections');
$loggers = [];
foreach ($connections as $name => $connection) {
$profilingLogger = null;
if ($container->has(sprintf('doctrine.dbal.logger.backtrace.%s', $name))) {
$profilingLogger = new Reference(sprintf('doctrine.dbal.logger.backtrace.%s', $name));
}

if ($container->has(sprintf('doctrine.dbal.logger.profiling.%s', $name))) {
$profilingLogger = new Reference(sprintf('doctrine.dbal.logger.profiling.%s', $name));
}

if (null !== $profilingLogger) {
$loggers[] = [$name, $profilingLogger];
}
}

if (0 === \count($loggers)) {
$container->removeDefinition('monitoring.metric.doctrine');

return;
}

foreach ($loggers as $logger) {
$definition->addMethodCall('addLogger', $logger);
}
$metricDefinition = (new Definition(DoctrineMetric::class))
->setArguments([
new Reference('doctrine.debug_data_holder')
])
->addTag('monitoring.metric')
;
$container->setDefinition('monitoring.metric.doctrine', $metricDefinition);
}
}
Loading