title: How to make a PHPUnit test that depends on ~real~ POST/GET data?
body: <p>I've created a PHP class that envelopes filter_input functions to make our developer's life easier.<br>
  To validate an HTML form with <code>url</code>, <code>name</code> and <code>age</code> fields, the code would be like that:</p>
  
  <pre><code>$post = Filter::POST();
  if ($post-&gt;validate_string('name') &amp;&amp; $post-&gt;validate_integer('age')) {
      $url = $post-&gt;sanitize_url('url');
  }
  </code></pre>
  
  <p>It would be the same as:</p>
  
  <pre><code>if (filter_input(INPUT_POST,'name',FILTER_UNSAFE_RAW) &amp;&amp; filter_input(INPUT_POST,'age',FILTER_VALIDATE_INTEGER)) {
      $url = filter_input(INPUT_POST,'url',FILTER_SANITIZE_URL);
  }
  </code></pre>
  
  <p>Well, I think the code is done and now I would like to create a PHPUnit test for it.</p>
  
  <p>The problem is that I have no idea on how to fake GET/POST data on a PHPUnit method, not for this case.<br>
  I don't need to insert values in <code>$_POST</code>, I need "real" data on it, because <code>filter_input</code> works with the data the script received, not with the actual <code>$_POST</code> superglobal.</p>
  
  <p>I've tried using the following PHPT test and PHPUnit method to achieve this, with no success at all:</p>
  
  <pre><code>--TEST--
  Generates POST and GET data to be used in FilterTest.php
  --POST--
  name=Igor&amp;age=20
  --GET--
  name=Igor&amp;age=19
  --FILE--
  &lt;?php
  echo $_POST['nome'].' = '.$_POST['idade'];
  ?&gt;
  --EXPECT--
  Igor = 20
  </code></pre>
  
  <hr>
  
  <pre><code>public function testPhpt() {
   $phpt = new PHPUnit_Extensions_PhptTestCase('FilterTest_data.phpt', array('cgi' =&gt; 'php-cgi'));
   $result = $phpt-&gt;run();
   $this-&gt;assertTrue($result-&gt;wasSuccessful());
  }
  </code></pre>
  
  <h2>EDIT</h2>
  
  <p><strong>Original code</strong>: <a href="http://pastebin.com/fpw2fpxM" rel="noreferrer">http://pastebin.com/fpw2fpxM</a><br>
  <strong>Code used for initial testing</strong>: <a href="http://pastebin.com/vzxsBQWm" rel="noreferrer">http://pastebin.com/vzxsBQWm</a><br>
  (sorry for the portuguese, I know it would be better to code in english, but it's how things work here where I work. If you <em>really</em> think it's really needed, I can translate the code).</p>
  
  <p>Any idea on what can I do to test this class?</p>