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

Nested LoggerChain DoctrineSubscriber #185

Closed
oleg-andreyev opened this issue Oct 31, 2023 · 3 comments
Closed

Nested LoggerChain DoctrineSubscriber #185

oleg-andreyev opened this issue Oct 31, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@oleg-andreyev
Copy link
Contributor

oleg-andreyev commented Oct 31, 2023

Q A
auditor version 2.x
PHP version 8.1
Database MySQL

Summary

<?php

namespace DH\Auditor\Tests\Provider\Doctrine\Event;

use DH\Auditor\Provider\Doctrine\Auditing\Event\DoctrineSubscriber;
use DH\Auditor\Provider\Doctrine\Auditing\Logger\LoggerChain;
use DH\Auditor\Provider\Doctrine\Auditing\Transaction\TransactionManager;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Logging\SQLLogger;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\OnFlushEventArgs;
use Doctrine\Persistence\ObjectManager;
use PHPUnit\Framework\TestCase;

class DoctrineSubscriberTest extends TestCase
{
    public function testMemoryUsage(): void
    {
        $transactionManager = $this->createMock(TransactionManager::class);
        $objectManager = $this->createMock(EntityManagerInterface::class);

        $args = new OnFlushEventArgs($objectManager);

        $objectManager
            ->method('getConnection')
            ->willReturn($connection = $this->createMock(Connection::class));

        $connection
            ->method('getDriver')
            ->willReturn($driver = $this->createMock(Driver::class));

        $connection
            ->method('getConfiguration')
            ->willReturn($configuration = new Configuration());

        $configuration->setSQLLogger(new class implements SQLLogger {
            public function startQuery($sql, ?array $params = null, ?array $types = null)
            {
            }

            public function stopQuery()
            {
            }
        });

        $target = new DoctrineSubscriber($transactionManager);
        $target->onFlush($args);
        $target->onFlush($args);
        $target->onFlush($args);
        $target->onFlush($args);
        $target->onFlush($args);

        $result = $configuration->getSQLLogger();
        self::assertCount(2, $result->getLoggers());
    }
}

Current behavior

Failed asserting that actual size 6 matches expected size 2.
image

Expected behavior

There should be only two logger, native and AuditLogger

@oleg-andreyev oleg-andreyev added the bug Something isn't working label Oct 31, 2023
oleg-andreyev added a commit to oleg-andreyev/auditor that referenced this issue Oct 31, 2023
oleg-andreyev added a commit to oleg-andreyev/auditor that referenced this issue Oct 31, 2023
@oleg-andreyev oleg-andreyev changed the title Memory leak by DoctrineSubscriber Nested LoggerChain DoctrineSubscriber Oct 31, 2023
@oleg-andreyev
Copy link
Contributor Author

result of internal fixes
image
vs
image

oleg-andreyev added a commit to oleg-andreyev/auditor that referenced this issue Nov 3, 2023
DamienHarper added a commit that referenced this issue Dec 19, 2023
* fixes #185

* PHP-CS-Fixer

---------

Co-authored-by: Damien Harper <damien.harper@gmail.com>
@DamienHarper
Copy link
Owner

@oleg-andreyev, thanks for the report and the relevant PR.
Fixed in 2.x branch. I'll make a new release asap.

@DamienHarper
Copy link
Owner

@oleg-andreyev 2.4.8 is available

DamienHarper added a commit that referenced this issue Jul 14, 2024
* Fix bug: exception while creating audit table schema when using single table inheritance (#133)

* fix #132

* entity

Co-authored-by: a.dmitryuk <a.dmitryuk@movavi.com>

* Updated README.md

* Updated CI

* Fixed annotations in tests

* Regression fix.

Fixes DamienHarper/auditor-bundle#334

* Updated CI

* Performance issues with metadatas (#137)

* Cache DH Annotations
* speed
* remove getOwner call

Co-authored-by: a.dmitryuk <a.dmitryuk@movavi.com>

* CreateSchemaListener not updating inheritance tables (#139)

* Fix: Attempted to call an undefined method named "getMetadataCache" of class "Doctrine\ORM\Configuration". (#144)

* Fix: Attempted to call an undefined method named "introspectSchema" of class "Doctrine\DBAL\Schema\PostgreSQLSchemaManager" (#143)

* Fixed invokable storage mapper (see #146) (#148)

* Fixed broken annotation registration since doctrine/orm 2.14

* improved the TransactionProcessor to convert encoding of diff properly (#152)

* improved the TransactionProcessor to convert encoding of diff properly

* adapted quotes in TransactionProcessor to single quotes

* Fixed compatibility issue with doctrine/event-manager ^2.0 (#157)

* PHP-CS-Fixer

* Validate that diff is a string before passing to mb_convert_encoding (#156)

* PHP-CS-Fixer

* Support  doctrine annotations 2.0 (#158)

* topic 344  doctrine annotations 2.0

---------

Co-authored-by: a.dmitryuk <a.dmitryuk@movavi.com>

* PHP-CS-Fixer

* Fix failing CI (lock related)

* PHP-CS-Fixer

* Fixes `diffs` column type when JSON type is supported

* Fixed CI (2.x)

* Fixed CI (2.x)

* Fixed CI (2.x)

* Fixed CI (2.x)

* Fixed CI (2.x)

* Fix 185 (#186)

* fixes #185

* PHP-CS-Fixer

---------

Co-authored-by: Damien Harper <damien.harper@gmail.com>

* skip embedded class from schema listener (#189)

Co-authored-by: Guillaume Sainthillier <guillaume.sainthillier@gmail.com>

* Fixed CI (2.x)

* Typo

* PHP-CS-Fixer

* Update deps + PHP-CS-Fixer

* PHP-CS-Fixer

* PHP-CS-Fixer (3.48.0)

* Detected wrapped driver (#195)

* - updated DHDriver and use parent::connect instead of dedicated field
- added getWrappedDriver to extract wrapped driver.
- tests

Signed-off-by: Oleg Andreyev <oleg@andreyev.lv>

* Fixed PHPStan error

---------

Signed-off-by: Oleg Andreyev <oleg@andreyev.lv>
Co-authored-by: Damien Harper <damien.harper@gmail.com>

* fix

Signed-off-by: Oleg Andreyev <oleg@andreyev.lv>

* php-cs-fixer

Signed-off-by: Oleg Andreyev <oleg@andreyev.lv>

* removed getSubscribedEvents from CreateSchemaListener

Signed-off-by: Oleg Andreyev <oleg@andreyev.lv>

* phpstan

Signed-off-by: Oleg Andreyev <oleg@andreyev.lv>

* fix DoctrineSubscriber + tests

Signed-off-by: Oleg Andreyev <oleg@andreyev.lv>

* fix Issue174Test

Signed-off-by: Oleg Andreyev <oleg@andreyev.lv>

* removed duplicate code, fixed test

Signed-off-by: Oleg Andreyev <oleg@andreyev.lv>

---------

Signed-off-by: Oleg Andreyev <oleg@andreyev.lv>
Co-authored-by: Alexander Dmitryuk <xakzona@bk.ru>
Co-authored-by: a.dmitryuk <a.dmitryuk@movavi.com>
Co-authored-by: damienharper <damien.harper@gmail.com>
Co-authored-by: Jörn Dyherrn <joern@dyherrn.dev>
Co-authored-by: Martijn Boers <2955898+martijnboers@users.noreply.github.com>
Co-authored-by: Guillaume Sainthillier <guillaume.sainthillier@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants