Comments (8)
Matcher
class is marked as final
for a reason. It is so simple that you should use it. I suggest you to check your code and ensure is everything is ok. In most cases your design is broken.
Can you provide example why you want to mock Matcher
?
from php-matcher.
Because I am building code arround the matcher and I need to test what happend when matcher failed or succeded. I could write some fake data but that sould not concerne my test. And your code is used as a service and therefore could be mock.
Anyway, I have forked it because @uuid@
is missing some implementation. So I also use it to allow mocking.
from php-matcher.
I think in this case we can remove final statement from Matcher
from php-matcher.
Still not sure is that a good way to use it. I use Matcher
like if
construct in order to check some more complex conditions.
IMO you don't need to mock Matcher
but create some abstraction for it. You can create your own Matcher
interface and mock it. Next create class which implements your interface and extends a coduo Matcher
BTW. Adding uuid pattern for RegexConverter
looks interesting.
from php-matcher.
Yes it work too. It seems to me like adding another layer of abstraction only for mocking. Not very fan of this solution, but it does not require to fork the all project, which is a plus.
I might go fir this solution if you add uuid pattern to RegexConverter.
I use this pattern in unit test of api with hateos implementation. Wich has a lot a autoreferencing link, with obviously a lot of uuid.
from php-matcher.
@norzechowicz would you remove final statement from Matcher?
from php-matcher.
Iām not sure, this final statement is so meaningless and creatig abstraction just to mock Matcher, sounds a bit like overengeneerig something simple. I would say, lets remove it
from php-matcher.
Before you do anything, removing the final statement is not enough to allow mocking, I had to do some other minor fix. You can have a lot at what I have on my fork. (From memory I have also hadded an interface and make the factory return the interface)
For the exact use case here how Create my mock.
$simpleFactory = $this->getMockBuilder('Coduo\PHPMatcher\Factory\SimpleFactory')
->setMethods(['createMatcher'])
->getMock();
$matcher = $this->getMockBuilder('Coduo\PHPMatcher\MatcherInterface')
->setMethods(['match','getError'])
->getMock();
$simpleFactory->method('createMatcher')->willReturn($matcher);
$matcher->method('match')->willReturn($matcherReturn);
$matcher->method('getError')->willReturn('mock error');
Also one last thing, I have written the first version of this mock of your service montg ago, the issue only occured recently when you changed the interface.
edit : after reflexion, removing the final keywork is not necessary if you had an interface, because I mock the interface and not the matcher itself, wich is way cleaner.
from php-matcher.
Related Issues (20)
- Confusing error message HOT 3
- How does the `.inArray()` pattern expander work ? HOT 3
- Expecting null but give an array throws strange runtime error HOT 3
- Make possible to use assertMatchesPattern in static methods HOT 2
- generate php-matcher checking rules from Open API swagger annotation
- ValueError: array_fill(): Argument #2 ($count) must be greater than or equal to 0
- Use of mutation testing in php-matcher - Help needed
- Type pattern "@...@" is not supported by TextMatcher. HOT 4
- Cannot use positional argument after named argument HOT 1
- PHPUnit 10 support
- Consider upgrade doctrine/lexer to 2.x branch HOT 3
- Json array of object compare
- When new release with PHP Unit support? HOT 1
- Release 6.0.12 not longer compatible with PHPUnit 9 HOT 1
- Type pattern "@boolean@" is not supported? HOT 1
- Do not hide parsing error exceptions deeply in the code
- The match of type @integer@ doesn't work. HOT 3
- Not able to match `@null@||@array@` (again) HOT 3
- Consider adding support for doctrine/lexer 3 HOT 9
- Deprecation notice using Doctrine\Common\Lexer\Token properties via ArrayAccess HOT 1
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-matcher.