Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing YAML Files as data provider in PHPUnit (CIUnit)
    primarykey
    data
    text
    <p>I am writing an application using the PHP CodeIgniter Framework. I am trying to test the application using CI_Unit, by extension PHPUnit. To test a model, I am trying to load a YAML data provider as defined in the PHPUnit documentation, I receive an error. If I fudge the data provider object, I get another error. If I provide it a vanilla PHP array, it runs as expected. </p> <p>What am I doing wrong? What is the correct way to do this? Below are my results:</p> <p>If I return the object <code>PHPUnit_Extensions_Database_DataSet_YamlDataSet</code> of the Yaml file below, I get:</p> <blockquote> <p>Data set "Clients" is invalid.</p> </blockquote> <p>If I loop around the object returned by <code>PHPUnit_Extensions_Database_DataSet_YamlDataSet</code> and return that: I get this error:</p> <blockquote> <p>PHPUnit_Framework_Exception: Neither "models.php" nor "models.php" could be opened. in /Users/eric/pear/share/pear/PHPUnit/Util/Skeleton/Test.php on line 100</p> </blockquote> <p>If I provide it a vanilla PHP array, the tests run just fine. The command I use to run the tests is:</p> <blockquote> <p>phpunit models</p> </blockquote> <p>Below is an example of my YAML file.</p> <pre><code>Clients: 1: client_id: 1 client_information: "info number 1" client_key: 48fb10b15f3d44a09dc82d 2: client_id: 2 client_information: "info number 2" client_key: 48fb10b15f3d44addd </code></pre> <p>I am using PHP 5.3, PHPUnit 3.6.10, DBUnit 1.1.2, CodeIgniter 2.1.0, and CI_unit associated with CI 2.1.0.</p> <p>Edit: Attached is my models/Test.php file:</p> <pre><code>/** * test_add_client * @dataProvider add_client_provider */ public function test_add_client($client_id,$company_id,$software_id,$client_information,$client_key) { $data = array('software_id' =&gt; $software_id, 'client_information' =&gt; $client_information, 'client_key' =&gt; $client_key); try { $id = $this-&gt;_m-&gt;add_client($company_id,$data); $this-&gt;assertEquals(true, is_int($id)); } catch (Exception $e){ $this-&gt;assertEquals(true,false); } } public function add_client_provider() { $result = new PHPUnit_Extensions_Database_DataSet_YamlDataSet( dirname(__FILE__)."/../fixtures/Clients.yml"); // Case #1 returns this $result //return $result; foreach($result as $key =&gt; $value){ if($key == 'Clients'){ $substructure = $value; } } // Case #2 return the inner structure that is the table return $substructure; // Case #3 return an array of arrays $data = array( array(1,1,1,'test','text 2'), array(1,2,1,'test 3', 'test 3')); return $data; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload