J'essaie de créer un objet fantaisie de type \SplObserver en utilisant PHPunit et en attachant l'objet fantaisie à un fichier de type \SplSubject. Quand j'essaie d'attacher l'objet simulé à une classe qui implémente \SplSubject j'obtiens une erreur fatale rattrapable disant que l'objet simulé n'implémente pas l'option \SplObserver :
PHP Catchable fatal error: Argument 1 passed to ..\AbstractSubject::attach() must implement interface SplObserver, instance of PHPUnit_Framework_MockObject_Builder_InvocationMocker given, called in ../Decorator/ResultCacheTest.php on line 44 and defined in /users/.../AbstractSubject.php on line 49
Plus ou moins, voici le code :
// Edit: Using the fully qualified name doesn't work either
$observer = $this->getMock('SplObserver', array('update'))
->expects($this->once())
->method('update');
// Attach the mock object to the cache object and listen for the results to be set on cache
$this->_cache->attach($observer);
doSomethingThatSetsCache();
Je ne sais pas si cela fait une différence, mais j'utilise PHP 5.3 et PHPUnit 3.4.9.