Comments (4)
The hole point of declaring the class final and setting the property private is, I didn't design the class for extension. Your use case is very unique, as normal clients would not have to mock that class. Couldn't you design your test to use the actual implementation?
If you really need a mock, you could refactor your code to not use PHPProphet directly, but through a proxy. Then you have full control over the design of that proxy.
Please point me to your test, so that I can have a look on my own of the situation.
from php-mock-prophecy.
I wasn't planning on subclassing PHPProphet, but needing to mock PHPProphet as a dependency in another library hardly seems like a unique use case. In my opinion, the only classes that could be final
are those that have no dependencies or side effects of their own and do not need to be mocked, like domain entities or value objects, for example.
from php-mock-prophecy.
needing to mock PHPProphet as a dependency in another library hardly seems like a unique use case
Mocking a mocking library is a unique use case.
In my opinion, the only classes that could be
final
are those that have no dependencies or side effects of their own
Thank you for sharing your opinion on the final
construct. I follow Josh Bloch's approach and protect the clients to mess around with sub classing.
But I see, you don't want to mess around, you just need a mock. As you pointed already out your familiarity with domain driven design, then I suggest using an anti corruption layer which you can mock:
interface MockablePHPProphet {
public function prophesize($namespace);
}
final class PHPProphetProxy implements MockablePHPProphet {
private $phpProphet;
public function prophesize($namespace)
{
return $this->phpProphet->prophesize($namespace);
}
}
from php-mock-prophecy.
I was actually considering doing something similar to what you suggest. However, I think I'm satisfied for now about the test coverage of my classes, given the early stage of the project. If things grow in complexity, I'll probably need a mockable interface for both PHPProphet and the special collaborator class for phpspec, since that has been difficult to mock as well (a collaborator of a collaborator!). Thanks.
from php-mock-prophecy.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-mock-prophecy.