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

BUG: PersistenceManager getObjectByIdentifier does not check for objectType on new objects #3384

Open
1 task done
lufonius opened this issue Jul 30, 2024 · 0 comments
Open
1 task done
Labels

Comments

@lufonius
Copy link

lufonius commented Jul 30, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

I wrote a functional test, where I create multiple new entities, inject some services and assert the results.
The code to be tested takes a persistent_object_identifier $id as a param and checks against two repositories using $repositoryX->findByIdentifier($id) (which uses getObjectByIdentifier in the background). The id could belong to two possible entity types. using the repository method findByIdentifier, the code finds out what entity type the id belongs to and based on that type, the control flow differs.

However, when the entity is marked as new in the persistence manager (NOT in the unit of work, see the link below for the code), this distinction is not made. the object type is being ignored. See here: https://github.com/neos/flow/blob/b44540d13874862e29671e4f7c40127c87b101b9/Classes/Persistence/Doctrine/PersistenceManager.php#L209

Expected Behavior

I expect an API, that doesn't ignore parameters and has no side effects. i don't know neos flow very well, however it seems like there is no unit test for this method. please correct me if I'm wrong.

Steps To Reproduce

Maybe a little code is best to explain it:

class FindByIdentifierExperimentalTest extends FunctionalTestCase
{
    protected static $testablePersistenceEnabled = true;

    public function testAssumptionThatAnyRepoCanFindAnyEntityTypeByIdentifier() {
        // given: an entity of type Price
        $originalPriceEntity = new Price();
        $originalPriceEntity->amount = 5;
        $originalPriceEntity->currency = "EUR";

        $this->persistenceManager->add($originalPriceEntity);
        $this->persistenceManager->persistAll();

        $priceIdentifier = $this->persistenceManager->getIdentifierByObject($originalPriceEntity);

        // when: a repository that manages a totally different entity type searches for the Price Entity
        $voucherRepository = $this->objectManager->get(VoucherRepository::class);
        $priceEntityFoundViaVoucherRepo = $voucherRepository->findByIdentifier($priceIdentifier);

        // Then: the entity is being found, even though the repository queries for Voucher entities. Voucher and Price entity are not related at all.
        $this->assertEquals($originalPriceEntity, $priceEntityFoundViaVoucherRepo);
    }
}

Environment

- Flow:* 8.3.9
- PHP:8.1.23

Anything else?

I got a bit of mixed feelings about that. however, since I don't know the framework I'd like to have your views on this before I settle for an opinion.

@lufonius lufonius added the Bug label Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant