Coder Social home page Coder Social logo

Comments (6)

DamienHarper avatar DamienHarper commented on May 24, 2024 1

@janklan 2.0.1 has just been released, including your fixes, thanks!

from auditor.

janklan avatar janklan commented on May 24, 2024

@DamienHarper I found another related issue that I fixed in the associated PR - after adding the missing $id, one relationship worked fine, but one did not. I don't know enough about Auditor's internals, so I did not track why, but https://github.com/DamienHarper/auditor/blob/master/src/Provider/Doctrine/Auditing/Transaction/TransactionHydrator.php#L102 does not supply the entity ID.

Effectively there are two incompatible disassociation events, one with the ID, one without. I assume the with is the right scenario?

Neither issues were picked up by the test suite.

Also I don't mean to tell you how to do things, but I've had extremely bad experience relying on arrays as data objects passing data around.

Why not use a DTO class with specified properties, data types etc?

So not,

[
    $collection->getOwner(),
    $entity,
    $this->id($entityManager, $entity),
    $mapping,
]

rather

new DisassociationEvent($collection->getOwner(), $entity, $this->id($entityManager, $entity), $mapping);

In a perfect world, this would look like

class DisassociationEvent(public readonly object $source, public readonly object $target, public readonly mixed $id, public readonly array $mapping) {}

Clearly with the need to support older PHP, the actual class would be more verbose, but something like this would let static code analysers pick up errors of this kind - unlike when using vague arrays?

The auditor is an awesome tool, thank you for your work.

from auditor.

DamienHarper avatar DamienHarper commented on May 24, 2024

@janklan Thanks for that clear report and the associated PR, much appreciated.
You're right regarding DTO vs basic arrays, it has to be changed. Feel free to submit a PR if you want to, I'd be glad to merge it.

from auditor.

janklan avatar janklan commented on May 24, 2024

Thanks, it's great to see some quick action!

from auditor.

janklan avatar janklan commented on May 24, 2024

@DamienHarper I tried to work out why didn't the test suite fail even though the coverage was there. It turns out the failing code is not really being covered - I'm not quite sure how would the listed test cases cover the problematic line:

image

Sure enough, when you only run php -d pcov.enabled=1 ./vendor/bin/phpunit --filter=TransactionProcessorTest::testDissociateManyToMany, none of the lines are covered:

image

I tried to extend the test case to actually employ TransactionHydrator to populate a real Transaction object that could then be passed to the TransactionProcessor to trip the error, but quite frankly, my understanding of Doctrine internals is not good enough to get it done. I failed to make the UoW object report any removals from the Post::$tags collection.

If you could push me in the right direction, I'm happy to help out by adding a more complete test suite, and then swap the arrays to DTO classes. I don't dare to touch the code if it's not reliably covered. I'm concerned I could blow up other people's projects.

from auditor.

DamienHarper avatar DamienHarper commented on May 24, 2024

@janklan #93 brings better coverage

from auditor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.