{"id":358,"date":"2014-08-07T20:28:34","date_gmt":"2014-08-07T20:28:34","guid":{"rendered":"http:\/\/thomasgr.im\/shares\/?p=358"},"modified":"2018-05-06T14:30:22","modified_gmt":"2018-05-06T13:30:22","slug":"tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids","status":"publish","type":"post","link":"https:\/\/thomasgr.im\/shares\/2014\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\/","title":{"rendered":"TDD on Laravel? Here&#8217;s a Tip to Make Jeffrey Way&#8217;s &#8220;Factory&#8221; Play Nice with UUIDs"},"content":{"rendered":"<p>Jeffrey Way&#8217;s <a href=\"https:\/\/github.com\/JeffreyWay\/Laravel-Test-Helpers\" title=\"Laravel Test Helpers\">Test Helpers Package<\/a>.<\/p>\n<p>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 &#8220;strings&#8221;, stuff like &#8220;abcdef-1&#8221; or &#8220;ouibuh-3&#8221;. <\/p>\n<p><pre class=\"brush: php; title: ; notranslate\" title=\"\">public function getDataType($col)&lt;br&gt;\n{&lt;br&gt;\n    return $col-&amp;gt;getType()-&amp;gt;getName();&lt;br&gt;\n}<\/pre>\n<\/p>\n<p>Here&#8217;s the modified version:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">public function getDataType($col) {&lt;br&gt;\n    $type = $col-&amp;gt;getType()-&amp;gt;getName();&lt;br&gt;\n    if ($type === 'string' &amp;amp;&amp;amp; $col-&amp;gt;getLength() === 36) {&lt;br&gt;\n        return 'uuid';&lt;br&gt;\n    }&lt;br&gt;\n    return $type;&lt;br&gt;\n}<\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Jeffrey Way&#8217;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 &#8220;strings&#8221;, stuff like &#8220;abcdef-1&#8221; or &#8220;ouibuh-3&#8221;. public function getDataType($col)&lt;br&gt; {&lt;br&gt; return $col-&amp;gt;getType()-&amp;gt;getName();&lt;br&gt; } Here&#8217;s the modified version: public function getDataType($col) {&lt;br&gt; $type = $col-&amp;gt;getType()-&amp;gt;getName();&lt;br&gt; &#8230;<a class=\"post-readmore\" href=\"https:\/\/thomasgr.im\/shares\/2014\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\/\">read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-358","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>TDD on Laravel? Here&#039;s a Tip to Make Jeffrey Way&#039;s &quot;Factory&quot; Play Nice with UUIDs - ThomasGR.IM<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/thomasgr.im\/shares\/2014\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"TDD on Laravel? Here&#039;s a Tip to Make Jeffrey Way&#039;s &quot;Factory&quot; Play Nice with UUIDs - ThomasGR.IM\" \/>\n<meta property=\"og:description\" content=\"Jeffrey Way&#8217;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 &#8220;strings&#8221;, stuff like &#8220;abcdef-1&#8221; or &#8220;ouibuh-3&#8221;. public function getDataType($col)&lt;br&gt; {&lt;br&gt; return $col-&amp;gt;getType()-&amp;gt;getName();&lt;br&gt; } Here&#8217;s the modified version: public function getDataType($col) {&lt;br&gt; $type = $col-&amp;gt;getType()-&amp;gt;getName();&lt;br&gt; ...read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/thomasgr.im\/shares\/2014\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\/\" \/>\n<meta property=\"og:site_name\" content=\"ThomasGR.IM\" \/>\n<meta property=\"article:published_time\" content=\"2014-08-07T20:28:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-05-06T13:30:22+00:00\" \/>\n<meta name=\"author\" content=\"Thomas\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/thomasgr.im\\\/shares\\\/2014\\\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thomasgr.im\\\/shares\\\/2014\\\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\\\/\"},\"author\":{\"name\":\"Thomas\",\"@id\":\"https:\\\/\\\/thomasgr.im\\\/shares\\\/#\\\/schema\\\/person\\\/a9f452898a055ceb0f17967802c852da\"},\"headline\":\"TDD on Laravel? Here&#8217;s a Tip to Make Jeffrey Way&#8217;s &#8220;Factory&#8221; Play Nice with UUIDs\",\"datePublished\":\"2014-08-07T20:28:34+00:00\",\"dateModified\":\"2018-05-06T13:30:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/thomasgr.im\\\/shares\\\/2014\\\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\\\/\"},\"wordCount\":133,\"commentCount\":0,\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/thomasgr.im\\\/shares\\\/2014\\\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/thomasgr.im\\\/shares\\\/2014\\\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\\\/\",\"url\":\"https:\\\/\\\/thomasgr.im\\\/shares\\\/2014\\\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\\\/\",\"name\":\"TDD on Laravel? Here's a Tip to Make Jeffrey Way's \\\"Factory\\\" Play Nice with UUIDs - ThomasGR.IM\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thomasgr.im\\\/shares\\\/#website\"},\"datePublished\":\"2014-08-07T20:28:34+00:00\",\"dateModified\":\"2018-05-06T13:30:22+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/thomasgr.im\\\/shares\\\/#\\\/schema\\\/person\\\/a9f452898a055ceb0f17967802c852da\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/thomasgr.im\\\/shares\\\/2014\\\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/thomasgr.im\\\/shares\\\/2014\\\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/thomasgr.im\\\/shares\\\/2014\\\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/thomasgr.im\\\/shares\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"TDD on Laravel? Here&#8217;s a Tip to Make Jeffrey Way&#8217;s &#8220;Factory&#8221; Play Nice with UUIDs\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/thomasgr.im\\\/shares\\\/#website\",\"url\":\"https:\\\/\\\/thomasgr.im\\\/shares\\\/\",\"name\":\"ThomasGR.IM\",\"description\":\"Geeky Musing\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/thomasgr.im\\\/shares\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/thomasgr.im\\\/shares\\\/#\\\/schema\\\/person\\\/a9f452898a055ceb0f17967802c852da\",\"name\":\"Thomas\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/24002a8c89532079ac75ffa31bf174b5f4b88ef34601417767fd11b3d48436b7?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/24002a8c89532079ac75ffa31bf174b5f4b88ef34601417767fd11b3d48436b7?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/24002a8c89532079ac75ffa31bf174b5f4b88ef34601417767fd11b3d48436b7?s=96&d=mm&r=g\",\"caption\":\"Thomas\"},\"sameAs\":[\"https:\\\/\\\/thomasgr.im\\\/\"],\"url\":\"https:\\\/\\\/thomasgr.im\\\/shares\\\/author\\\/thomadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"TDD on Laravel? Here's a Tip to Make Jeffrey Way's \"Factory\" Play Nice with UUIDs - ThomasGR.IM","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/thomasgr.im\/shares\/2014\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\/","og_locale":"en_US","og_type":"article","og_title":"TDD on Laravel? Here's a Tip to Make Jeffrey Way's \"Factory\" Play Nice with UUIDs - ThomasGR.IM","og_description":"Jeffrey Way&#8217;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 &#8220;strings&#8221;, stuff like &#8220;abcdef-1&#8221; or &#8220;ouibuh-3&#8221;. public function getDataType($col)&lt;br&gt; {&lt;br&gt; return $col-&amp;gt;getType()-&amp;gt;getName();&lt;br&gt; } Here&#8217;s the modified version: public function getDataType($col) {&lt;br&gt; $type = $col-&amp;gt;getType()-&amp;gt;getName();&lt;br&gt; ...read more","og_url":"https:\/\/thomasgr.im\/shares\/2014\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\/","og_site_name":"ThomasGR.IM","article_published_time":"2014-08-07T20:28:34+00:00","article_modified_time":"2018-05-06T13:30:22+00:00","author":"Thomas","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/thomasgr.im\/shares\/2014\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\/#article","isPartOf":{"@id":"https:\/\/thomasgr.im\/shares\/2014\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\/"},"author":{"name":"Thomas","@id":"https:\/\/thomasgr.im\/shares\/#\/schema\/person\/a9f452898a055ceb0f17967802c852da"},"headline":"TDD on Laravel? Here&#8217;s a Tip to Make Jeffrey Way&#8217;s &#8220;Factory&#8221; Play Nice with UUIDs","datePublished":"2014-08-07T20:28:34+00:00","dateModified":"2018-05-06T13:30:22+00:00","mainEntityOfPage":{"@id":"https:\/\/thomasgr.im\/shares\/2014\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\/"},"wordCount":133,"commentCount":0,"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/thomasgr.im\/shares\/2014\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/thomasgr.im\/shares\/2014\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\/","url":"https:\/\/thomasgr.im\/shares\/2014\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\/","name":"TDD on Laravel? Here's a Tip to Make Jeffrey Way's \"Factory\" Play Nice with UUIDs - ThomasGR.IM","isPartOf":{"@id":"https:\/\/thomasgr.im\/shares\/#website"},"datePublished":"2014-08-07T20:28:34+00:00","dateModified":"2018-05-06T13:30:22+00:00","author":{"@id":"https:\/\/thomasgr.im\/shares\/#\/schema\/person\/a9f452898a055ceb0f17967802c852da"},"breadcrumb":{"@id":"https:\/\/thomasgr.im\/shares\/2014\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/thomasgr.im\/shares\/2014\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/thomasgr.im\/shares\/2014\/tdd-on-laravel-heres-a-tip-to-make-jeffrey-ways-factory-play-nice-with-uuids\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/thomasgr.im\/shares\/"},{"@type":"ListItem","position":2,"name":"TDD on Laravel? Here&#8217;s a Tip to Make Jeffrey Way&#8217;s &#8220;Factory&#8221; Play Nice with UUIDs"}]},{"@type":"WebSite","@id":"https:\/\/thomasgr.im\/shares\/#website","url":"https:\/\/thomasgr.im\/shares\/","name":"ThomasGR.IM","description":"Geeky Musing","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/thomasgr.im\/shares\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/thomasgr.im\/shares\/#\/schema\/person\/a9f452898a055ceb0f17967802c852da","name":"Thomas","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/24002a8c89532079ac75ffa31bf174b5f4b88ef34601417767fd11b3d48436b7?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/24002a8c89532079ac75ffa31bf174b5f4b88ef34601417767fd11b3d48436b7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/24002a8c89532079ac75ffa31bf174b5f4b88ef34601417767fd11b3d48436b7?s=96&d=mm&r=g","caption":"Thomas"},"sameAs":["https:\/\/thomasgr.im\/"],"url":"https:\/\/thomasgr.im\/shares\/author\/thomadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/thomasgr.im\/shares\/wp-json\/wp\/v2\/posts\/358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thomasgr.im\/shares\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thomasgr.im\/shares\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thomasgr.im\/shares\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thomasgr.im\/shares\/wp-json\/wp\/v2\/comments?post=358"}],"version-history":[{"count":0,"href":"https:\/\/thomasgr.im\/shares\/wp-json\/wp\/v2\/posts\/358\/revisions"}],"wp:attachment":[{"href":"https:\/\/thomasgr.im\/shares\/wp-json\/wp\/v2\/media?parent=358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thomasgr.im\/shares\/wp-json\/wp\/v2\/categories?post=358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thomasgr.im\/shares\/wp-json\/wp\/v2\/tags?post=358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}