Skip to content

issue in phpspec/phpspec:6.3.1 , \PhpSpec\Matcher\ThrowMatcher and symfony/security:v4.4.37 #1412

Open
@vasilake-v

Description

Hey

I'm at phpspec/phpspec:6.3.1 and facing a issue with \PhpSpec\Matcher\ThrowMatcher when trying to upgrade from symfony/security:v4.4.33 -> symfony/security:v4.4.37

Because:
the new \Symfony\Component\Security\Core\Exception\AuthenticationException extended by \Symfony\Component\Security\Core\Exception\UsernameNotFoundException
defines a protected property $serialized which is unset immediately at __construct.
The $serialized property is used in the __sleep() magic method.

Example
where a spec test is expecting a UsernameNotFoundException exception

function it_throws_exception_when_there_is_no_user_with_given_username_or_email($userRepository, $canonicalizer)
    {
        $canonicalizer->canonicalize('testUser')->willReturn('testuser');

        $userRepository->findOneBy(array('usernameCanonical' => 'testuser'))->willReturn(null);
        $userRepository->findOneByEmail('testuser')->willReturn(null);

        $this->shouldThrow(new UsernameNotFoundException('Username "testuser" does not exist.'))->during('loadUserByUsername', array('testUser'));
    }

test will fail with

  68  - it throws exception when there is no user with given username or email
      warning: Undefined property: Symfony\Component\Security\Core\Exception\UsernameNotFoundException::$serialized in
      /var/www/vendor/phpspec/phpspec/src/PhpSpec/Matcher/ThrowMatcher.php line 148

Possible solution?

I looked up the PhpSpec\Matcher\ThrowMatcher and there is a property
\PhpSpec\Matcher\ThrowMatcher::$ignoredProperties that could be potentially used to dynamically add the new $serialized property to skip it.

final class ThrowMatcher implements Matcher
{
    /**
     * @var array
     */
-    private static $ignoredProperties = array('file', 'line', 'string', 'trace', 'previous');
+    private static $ignoredProperties = array('file', 'line', 'string', 'trace', 'previous', 'serialized');

    /**
     * @var Unwrapper
     */
    private $unwrapper;

(i checked the newer version https://github.com/phpspec/phpspec/blob/7.1.0/src/PhpSpec/Matcher/ThrowMatcher.php and it's not much different than the one i have)

Anyone knows how could I fix it , is there a possibility to ignore this $serialized property somehow in a different way ?

Thanks !

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions