phpspec / prophecy

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

PHP 8.0 compatibility #491

Closed garak closed 3 years ago

garak commented 4 years ago

Can we allow php 8 in composer.json? I see that some tests are already passing on travis

Glancu commented 4 years ago

I add PR - #492

ciaranmcnulty commented 4 years ago

Not before feature freeze at the very earliest

GrahamCampbell commented 4 years ago

I think revisiting this after PHP 8.0.0 beta 1 and PHPUnit 9.3.0 has been tagged would be a good idea. We might actually be able to install all dependencies without ignoring platform-reqs at that point.

GrahamCampbell commented 4 years ago

I think, that is 10th August, from memory.... something around that date anyway. ;)

ciaranmcnulty commented 4 years ago

that's what 'feature freeze' is :)

sebastianbergmann commented 4 years ago

PHP 8 is feature-frozen and PHP 8.0.0 Beta 1 was released yesterday. Today PHPUnit 9.3.0 has been released.

MAXakaWIZARD commented 4 years ago

@sebastianbergmann currently PHPUnit 9.3 cannot be installed under PHP 8.0 because phpspec/prophecy does not allow it. I'm curious how phpunit 9.3 was released despite the fact that dependencies cannot be resolved at the moment. Have you built it under PHP 7.x?

sebastianbergmann commented 4 years ago

Have you built it under PHP 7.x?

Yes.

TeBoring commented 4 years ago

When can prophecy be released?

ciaranmcnulty commented 4 years ago

482 is outstanding. I made some start on it already and may be able to push it over the line in the next few days

If anyone wants to jump in please do

ciaranmcnulty commented 4 years ago

Feedback on #495 will help

ciaranmcnulty commented 4 years ago

Review of #495 would be helpful to move forward

alexpott commented 4 years ago

EDIT: my bad - had some old code lying around - once I got rid of this everything worked as expected. Apologies.

i don't know whether to create a new issue but there's an issue with creating doubles where the class has a parameter declared as mixed. In this case \Drupal\Core\Php8\Phpspec\Prophecy\ClassMirror::isNullable() returns true because mixed allows null but null !== $this->getTypeHint($parameter). Then \Prophecy\Doubler\Generator\Node\TypeNodeAbstract::guardIsValidType() throws an exception because

        if (\PHP_VERSION_ID >= 80000 && isset($this->types['mixed']) && count($this->types) !== 1) {
            throw new DoubleException('mixed cannot be part of a union');
        }

I think the solution is to change isNullable() to

    private function isNullable(ReflectionParameter $parameter)
    {
        $typehint = $this->getTypeHint($parameter);
        return $parameter->allowsNull() && !(null === $typehint || 'mixed' === $typehint);
    }

Because in PHP 8.0 nullable mixed types are not allowed. See https://php.watch/versions/8.0/mixed-type#nullable

garak commented 3 years ago

Is there anything still blocking this?

Glancu commented 3 years ago

We can close. https://github.com/sonata-project/SonataAdminBundle/pull/6476