Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
@dawehner pointed out that PHPUnit now ships with phpspec/prophecy, a mocking framework.
I wanted to try it out, figured page_manager would be a good candidate.
Proposed resolution
Use phpspec/prophecy for mocks
Remaining tasks
Decide if this is actually an improvement
Figure out how to replace getMockBuilder calls
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Comment | File | Size | Author |
---|---|---|---|
#1 | 2538794-prophecy-1.patch | 42.67 KB | tim.plunkett |
Comments
Comment #1
tim.plunkettI may be using this completely wrong, couldn't find too many examples to go on.
Comment #2
jibranWoW this looks awesome.
Comment #3
Berdirprophesize can't handle partial mocks?
Comment #4
dawehnerThey don't want to support it by design, see https://github.com/phpspec/prophecy/issues/101.
In an ideal world phpunit would have used mockery.
Comment #5
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commented#3 #4: Yeah, sadly not.
Mockery shines when using partial or even Mocks for classes that do not exist, e.g. interfaces that are not defined.
However Prophecy is really great in overwriting the behavior of a defined mock per test class and also the dynamic binding of allowing a setter to overwrite the expectation of a getter is really great.
http://everzet.com/post/72910908762/conceptual-difference-between-mocker... is an insightful post on that.
Comment #6
tim.plunkettRight. So the question here is, do we want to mix mocking libraries within a test (or project)?
Comment #7
dawehnerWithin a project I would say no problem at all. Within a test, mh, depends how much it improves readability.
Comment #8
BerdirAnd this improves it a lot.
I'd say we should just commit it, want to continue working on #2528370: Simplify block caching and allow to cache the whole page, including access checks but kind of waiting for this to land as it will conflict a lot with the unit test changes that I will have to do there.
Comment #9
dawehnerToo bad that tim is on vacation.
Comment #11
tim.plunkettCommitted, should have done this before I left, sorry!
Comment #12
BerdirWow, is that week already over? :)
Thanks, no problem, didn't have time anyway to work on it :)