phpspec / prophecy

Highly opinionated mocking framework for PHP 5.3+
MIT License
8.53k stars 241 forks source link

Initial idea for Intersection/Union types #569

Open kschatzle opened 1 year ago

kschatzle commented 1 year ago

Not close to finishing, but what do you think about the direction before I get everything ironed out? (Not all unit tests pass yet).

535

kschatzle commented 1 year ago

Awesome, thanks for the feedback. Seems like you're ok with the BC breaks in signatures.

stof commented 1 year ago

@kschatzle it would be better if ArgumentTypeNode and ReturnTypeNode could have a BC layer for their getTypes method (this BC layer can throw an exception when an intersection type is found, hinting at using the new API to support it). And even better if we can provide a BC layer for the existing constructor signature (with deprecation warnings).

smyhill commented 1 year ago

@kschatzle Is this something still actively being worked on. Can I help out in any way?

kschatzle commented 1 year ago

I need to get back to this eventually when I have time. Some IRL stuff.

dannyvw commented 5 months ago

Doctrine has changed the return type from ObjectRepository to EntityRepository https://github.com/doctrine/DoctrineBundle/blob/2.12.x/src/Repository/RepositoryFactoryCompatibility.php (in ORM 3.x). This triggers now the following error in phpspec "doubling intersection types is not supported"

stof commented 5 months ago

@dannyvw how is this related ? There is no union type nor intersection type in this trait

dannyvw commented 5 months ago

@stof The issue is related to the changes inside EntityRepository (https://github.com/doctrine/orm/blob/3.1.x/src/EntityRepository.php) and the return type change. If you have a test case like below then it triggers this error "doubling intersection types is not supported".

    public function let(EntityManagerInterface $entityManager, EntityRepository $repository): void
    {
        $entityManager->getRepository(SomeEntity::class)->willReturn($repository);
    }
stof commented 5 months ago

I doubt the code you linked is relevant then, as there is no intersection type anywhere in this file.

Anyway, this PR is not ready to be merged. If you want this to move forward without waiting for the author to get back to it, an option is to take over the work to finish it.

dannyvw commented 5 months ago

Not sure either but the EntityRepository was the class inside the error. This error "doubling intersection types is not supported" is only triggered when upgrading doctrine/orm from 2.19 to 3.x.

jdreesen commented 5 months ago

There's this: https://github.com/doctrine/orm/blob/3.1.x/src/EntityRepository.php#L199