TDD on Laravel? Here’s a Tip to Make Jeffrey Way’s “Factory” Play Nice with UUIDs

Jeffrey Way’s Test Helpers Package.

Problem: the Factory class does not support UUID/GUID generation, and will mess with your tests by filling your foreign and primary keys with what it considers “strings”, stuff like “abcdef-1” or “ouibuh-3”.

public function getDataType($col)<br>
{<br>
    return $col-&gt;getType()-&gt;getName();<br>
}

Here’s the modified version:

public function getDataType($col) {<br>
    $type = $col-&gt;getType()-&gt;getName();<br>
    if ($type === 'string' &amp;&amp; $col-&gt;getLength() === 36) {<br>
        return 'uuid';<br>
    }<br>
    return $type;<br>
}