arashja / hamcrest

Automatically exported from code.google.com/p/hamcrest
0 stars 0 forks source link

Add matchesPatternCount() to assert preg_match_all() #118

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
matchesPatternCount($pattern, $countMatcher, $group=0)

If $group is zero, compare to return value, otherwise compare to

    count($matches[$group])

e.g.

    assertThat('foobarfoo', matchesPatternCount('/foo/', atLeast(2)));

Actually, will an individual group ever match a different number of times than 
the whole pattern? I don't think that's possible.

Original issue reported on code.google.com by dharkn...@gmail.com on 29 Jul 2010 at 8:12

GoogleCodeExporter commented 8 years ago
It may be fine to simply add $countMatcher as an optional second argument to 
matchesPattern(). It reads clearly enough IMHO.

    assertThat('foobarfoo', matchesPattern('/foo/', atLeast(2));

As well, it should be wrapped with equalTo() if it's not a matcher.

Original comment by dharkn...@gmail.com on 4 Aug 2010 at 7:44

GoogleCodeExporter commented 8 years ago

Original comment by dharkn...@gmail.com on 28 Apr 2011 at 12:03