Note that there are some explanatory texts on larger screens.

plurals
  1. POLaravel 4, unit tests, extra data returned
    text
    copied!<p>bros. Got a strange behaviour. I'm writing tests for my Laravel 4 <a href="https://github.com/franzose/ClosureTable" rel="nofollow">ClosureTable</a> package.</p> <p>All tests create new <code>Entity</code> (or <code>Entitites</code>) for further use. For example, one of the first tests: <code>ClosureTableTestCase::testInsertSingle</code>. When I run it, I got this:</p> <p><code> Exception: SQLSTATE[HY000]: General error: 1 table pages_closure has no column named 0 (SQL: insert into "pages_closure" ("ancestor", "depth", "descendant", "0", "1", "2") values (?, ?, ?, ?, ?, ?)) (Bindings: array ( 0 =&gt; '1', 1 =&gt; '0', 2 =&gt; '1', 3 =&gt; '1', 4 =&gt; '1', 5 =&gt; '0', ))</code></p> <p>And <code>var_dump</code> says me the following:</p> <pre> array(1) { [0] => array(6) { 'ancestor' => string(1) "1" [0] => string(1) "1" 'descendant' => string(1) "1" [1] => string(1) "1" 'depth' => string(1) "0" [2] => string(1) "0" } } </pre> <p>However when I create an Entity via web interface, all's fine!</p> <p>Errors come from <code>DB::select($selectQuery);</code> call when I run tests via terminal. As you can see, I somehow got [0], [1], and [2] extra array keys. <strong>However when I create an Entity via web interface, all's fine!</strong></p> <p>Error is in this method that's run internally: </p> <pre><code>protected function performInsertNode($descendant, $ancestor) { $table = $this-&gt;closure; $ak = static::ANCESTOR; $dk = static::DESCENDANT; $dpk = static::DEPTH; DB::transaction(function() use($table, $ak, $dk, $dpk, $descendant, $ancestor){ $selectQuery = " SELECT tbl.{$ak} as {$ak}, {$descendant} as {$dk}, tbl.{$dpk}+1 as {$dpk} FROM {$table} AS tbl WHERE tbl.{$dk} = {$ancestor} UNION ALL SELECT {$descendant}, {$descendant}, 0 "; $results = DB::select($selectQuery); array_walk($results, function(&amp;$item){ $item = (array)$item; }); var_dump($results); DB::table($table)-&gt;insert($results); }); } </code></pre> <p>Do you can point me out a mistake?</p>
 

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