This file is indexed.

/usr/share/doc/php-mockery/html/reference/argument_validation.html is in php-mockery-doc 0.9.4-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Argument Validation &mdash; Mockery Docs 0.9 documentation</title>
  

  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  

  

  
    <link rel="top" title="Mockery Docs 0.9 documentation" href="../index.html"/>
        <link rel="up" title="Reference" href="index.html"/>
        <link rel="next" title="Creating Partial Mocks" href="partial_mocks.html"/>
        <link rel="prev" title="Expectation Declarations" href="expectations.html"/> 

  
  <script src="../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../index.html" class="icon icon-home"> Mockery Docs
          

          
          </a>

          
            
            
              <div class="version">
                0.9
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
                <ul>
<li class="toctree-l1"><a class="reference internal" href="../getting_started/index.html">Getting Started</a></li>
</ul>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Reference</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="startup_methods.html">Quick Reference</a></li>
<li class="toctree-l2"><a class="reference internal" href="expectations.html">Expectation Declarations</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="">Argument Validation</a></li>
<li class="toctree-l2"><a class="reference internal" href="partial_mocks.html">Creating Partial Mocks</a></li>
<li class="toctree-l2"><a class="reference internal" href="public_properties.html">Mocking Public Properties</a></li>
<li class="toctree-l2"><a class="reference internal" href="public_static_properties.html">Mocking Public Static Methods</a></li>
<li class="toctree-l2"><a class="reference internal" href="pass_by_reference_behaviours.html">Preserving Pass-By-Reference Method Parameter Behaviour</a></li>
<li class="toctree-l2"><a class="reference internal" href="demeter_chains.html">Mocking Demeter Chains And Fluent Interfaces</a></li>
<li class="toctree-l2"><a class="reference internal" href="object_recording.html">Mock Object Recording</a></li>
<li class="toctree-l2"><a class="reference internal" href="final_methods_classes.html">Dealing with Final Classes/Methods</a></li>
<li class="toctree-l2"><a class="reference internal" href="magic_methods.html">PHP Magic Methods</a></li>
<li class="toctree-l2"><a class="reference internal" href="mockery/index.html">Mockery</a></li>
<li class="toctree-l2"><a class="reference internal" href="index.html#mockery-reference">Mockery Reference</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../cookbook/index.html">Cookbook</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="../index.html">Mockery Docs</a>
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          

 



<div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="../index.html">Docs</a> &raquo;</li>
      
          <li><a href="index.html">Reference</a> &raquo;</li>
      
    <li>Argument Validation</li>
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="../_sources/reference/argument_validation.txt" rel="nofollow"> View page source</a>
          
        
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="argument-validation">
<span id="index-0"></span><h1>Argument Validation<a class="headerlink" href="#argument-validation" title="Permalink to this headline"></a></h1>
<p>The arguments passed to the <code class="docutils literal"><span class="pre">with()</span></code> declaration when setting up an
expectation determine the criteria for matching method calls to expectations.
Thus, you can setup up many expectations for a single method, each
differentiated by the expected arguments. Such argument matching is done on a
&#8220;best fit&#8221; basis.  This ensures explicit matches take precedence over
generalised matches.</p>
<p>An explicit match is merely where the expected argument and the actual
argument are easily equated (i.e. using <code class="docutils literal"><span class="pre">===</span></code> or <code class="docutils literal"><span class="pre">==</span></code>). More generalised
matches are possible using regular expressions, class hinting and the
available generic matchers. The purpose of generalised matchers is to allow
arguments be defined in non-explicit terms, e.g. <code class="docutils literal"><span class="pre">Mockery::any()</span></code> passed to
<code class="docutils literal"><span class="pre">with()</span></code> will match <strong>any</strong> argument in that position.</p>
<p>Mockery&#8217;s generic matchers do not cover all possibilities but offers optional
support for the Hamcrest library of matchers. Hamcrest is a PHP port of the
similarly named Java library (which has been ported also to Python, Erlang,
etc).  I strongly recommend using Hamcrest since Mockery simply does not need
to duplicate Hamcrest&#8217;s already impressive utility which itself promotes a
natural English DSL.</p>
<p>The example below show Mockery matchers and their Hamcrest equivalent.
Hamcrest uses functions (no namespacing).</p>
<p>Here&#8217;s a sample of the possibilities.</p>
<div class="highlight-php"><div class="highlight"><pre><span class="x">with(1)</span>
</pre></div>
</div>
<p>Matches the integer <code class="docutils literal"><span class="pre">1</span></code>. This passes the <code class="docutils literal"><span class="pre">===</span></code> test (identical). It does
facilitate a less strict <code class="docutils literal"><span class="pre">==</span></code> check (equals) where the string <code class="docutils literal"><span class="pre">'1'</span></code> would
also match the
argument.</p>
<div class="highlight-php"><div class="highlight"><pre><span class="x">with(\Mockery::any()) OR with(anything())</span>
</pre></div>
</div>
<p>Matches any argument. Basically, anything and everything passed in this
argument slot is passed unconstrained.</p>
<div class="highlight-php"><div class="highlight"><pre><span class="x">with(\Mockery::type(&#39;resource&#39;)) OR with(resourceValue()) OR with(typeOf(&#39;resource&#39;))</span>
</pre></div>
</div>
<p>Matches any resource, i.e. returns true from an <code class="docutils literal"><span class="pre">is_resource()</span></code> call. The
Type matcher accepts any string which can be attached to <code class="docutils literal"><span class="pre">is_</span></code> to form a
valid type check. For example, <code class="docutils literal"><span class="pre">\Mockery::type('float')</span></code> or Hamcrest&#8217;s
<code class="docutils literal"><span class="pre">floatValue()</span></code> and <code class="docutils literal"><span class="pre">typeOf('float')</span></code> checks using <code class="docutils literal"><span class="pre">is_float()</span></code>, and
<code class="docutils literal"><span class="pre">\Mockery::type('callable')</span></code> or Hamcrest&#8217;s <code class="docutils literal"><span class="pre">callable()</span></code> uses
<code class="docutils literal"><span class="pre">is_callable()</span></code>.</p>
<p>The Type matcher also accepts a class or interface name to be used in an
<code class="docutils literal"><span class="pre">instanceof</span></code> evaluation of the actual argument (similarly Hamcrest uses
<code class="docutils literal"><span class="pre">anInstanceOf()</span></code>).</p>
<p>You may find a full list of the available type checkers at
<a class="reference external" href="http://www.php.net/manual/en/ref.var.php">php.net</a> or browse Hamcrest&#8217;s function
list in
<a class="reference external" href="http://code.google.com/p/hamcrest/source/browse/trunk/hamcrest-php/hamcrest/Hamcrest.php">the Hamcrest code</a>.</p>
<div class="highlight-php"><div class="highlight"><pre><span class="x">with(\Mockery::on(closure))</span>
</pre></div>
</div>
<p>The On matcher accepts a closure (anonymous function) to which the actual
argument will be passed. If the closure evaluates to (i.e. returns) boolean
<code class="docutils literal"><span class="pre">true</span></code> then the argument is assumed to have matched the expectation. This is
invaluable where your argument expectation is a bit too complex for or simply
not implemented in the current default matchers.</p>
<p>There is no Hamcrest version of this functionality.</p>
<div class="highlight-php"><div class="highlight"><pre><span class="x">with(&#39;/^foo/&#39;) OR with(matchesPattern(&#39;/^foo/&#39;))</span>
</pre></div>
</div>
<p>The argument declarator also assumes any given string may be a regular
expression to be used against actual arguments when matching. The regex option
is only used when a) there is no <code class="docutils literal"><span class="pre">===</span></code> or <code class="docutils literal"><span class="pre">==</span></code> match and b) when the regex
is verified to be a valid regex (i.e. does not return false from
<code class="docutils literal"><span class="pre">preg_match()</span></code>).  If the regex detection doesn&#8217;t suit your tastes, Hamcrest
offers the more explicit <code class="docutils literal"><span class="pre">matchesPattern()</span></code> function.</p>
<div class="highlight-php"><div class="highlight"><pre><span class="x">with(\Mockery::ducktype(&#39;foo&#39;, &#39;bar&#39;))</span>
</pre></div>
</div>
<p>The Ducktype matcher is an alternative to matching by class type. It simply
matches any argument which is an object containing the provided list of
methods to call.</p>
<p>There is no Hamcrest version of this functionality.</p>
<div class="highlight-php"><div class="highlight"><pre><span class="x">with(\Mockery::mustBe(2)) OR with(identicalTo(2))</span>
</pre></div>
</div>
<p>The MustBe matcher is more strict than the default argument matcher. The
default matcher allows for PHP type casting, but the MustBe matcher also
verifies that the argument must be of the same type as the expected value.
Thus by default, the argument <cite>&#8216;2&#8217;</cite> matches the actual argument 2 (integer)
but the MustBe matcher would fail in the same situation since the expected
argument was a string and instead we got an integer.</p>
<p>Note: Objects are not subject to an identical comparison using this matcher
since PHP would fail the comparison if both objects were not the exact same
instance. This is a hindrance when objects are generated prior to being
returned, since an identical match just would never be possible.</p>
<div class="highlight-php"><div class="highlight"><pre><span class="x">with(\Mockery::not(2)) OR with(not(2))</span>
</pre></div>
</div>
<p>The Not matcher matches any argument which is not equal or identical to the
matcher&#8217;s parameter.</p>
<div class="highlight-php"><div class="highlight"><pre><span class="x">with(\Mockery::anyOf(1, 2)) OR with(anyOf(1,2))</span>
</pre></div>
</div>
<p>Matches any argument which equals any one of the given parameters.</p>
<div class="highlight-php"><div class="highlight"><pre><span class="x">with(\Mockery::notAnyOf(1, 2))</span>
</pre></div>
</div>
<p>Matches any argument which is not equal or identical to any of the given
parameters.</p>
<p>There is no Hamcrest version of this functionality.</p>
<div class="highlight-php"><div class="highlight"><pre><span class="x">with(\Mockery::subset(array(0 =&gt; &#39;foo&#39;)))</span>
</pre></div>
</div>
<p>Matches any argument which is any array containing the given array subset.
This enforces both key naming and values, i.e. both the key and value of each
actual element is compared.</p>
<p>There is no Hamcrest version of this functionality, though Hamcrest can check
a single entry using <code class="docutils literal"><span class="pre">hasEntry()</span></code> or <code class="docutils literal"><span class="pre">hasKeyValuePair()</span></code>.</p>
<div class="highlight-php"><div class="highlight"><pre><span class="x">with(\Mockery::contains(value1, value2))</span>
</pre></div>
</div>
<p>Matches any argument which is an array containing the listed values. The
naming of keys is ignored.</p>
<div class="highlight-php"><div class="highlight"><pre><span class="x">with(\Mockery::hasKey(key));</span>
</pre></div>
</div>
<p>Matches any argument which is an array containing the given key name.</p>
<div class="highlight-php"><div class="highlight"><pre><span class="x">with(\Mockery::hasValue(value));</span>
</pre></div>
</div>
<p>Matches any argument which is an array containing the given value.</p>
</div>


           </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="partial_mocks.html" class="btn btn-neutral float-right" title="Creating Partial Mocks" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="expectations.html" class="btn btn-neutral" title="Expectation Declarations" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2014, Pádraic Brady, Dave Marshall, Wouter, Graham Campbell.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../',
            VERSION:'0.9',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true
        };
    </script>
      <script type="text/javascript" src="../_static/jquery.js"></script>
      <script type="text/javascript" src="../_static/underscore.js"></script>
      <script type="text/javascript" src="../_static/doctools.js"></script>

  

  
  
    <script type="text/javascript" src="../_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>