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
Error when collaborator has a final construct #54
Comments
It might be worth treating SimpleXmlElements as value objects and not mocking them. |
Actually this might be possible to fix for PHP classes with final constructors, but not for internals like SimpleXmlElement. |
This is actually possible when the constructor is public. See this example taken from #61 (SQLFilter has a private constructor): class SomeRepositorySpec extends ObjectBehavior
{
function let(
EntityManager $manager,
ClassMetadata $metadata,
FilterCollection $filters,
SoftDeleteableFilter $softDeleteableFilter
) {
// Here, you can specify the constructor argument
// It must be done before $softDeleteableFilter is unwrapped, so the
// beginning of let() is the best location
$softDeleteableFilter->beConstructedWith([$manager->getWrappedObject()]);
$manager->getFilters()->willReturn($filters);
$filters->enable('softdeletable')->willReturn($softDeleteableFilter);
$this->beConstructedWith($manager, $metadata);
}
} Having to unwrap the collaborators is unfortunate and I would consider it as a Prophecy bug |
and for the fatal error, it is solved by the PR above |
If I pass a collaborator that has a final construct to a method I'm specking, phpspec gives me an obvious error.
Is there a workaround about this, by the way that collaborator is an instance of SimpleXMLElement, but it applies to any class that has the same structure.
This leads to this error
The text was updated successfully, but these errors were encountered: