{"id":5289,"date":"2017-12-14T15:03:30","date_gmt":"2017-12-14T06:03:30","guid":{"rendered":"https:\/\/www.lancard.com\/blog\/?p=5289"},"modified":"2025-03-12T11:26:06","modified_gmt":"2025-03-12T02:26:06","slug":"laravel%e3%81%ae%e3%83%86%e3%82%b9%e3%83%88%e7%94%a8%e4%be%bf%e5%88%a9%e3%83%88%e3%83%ac%e3%82%a4%e3%83%88%e3%81%ae%e5%8b%95%e4%bd%9c%e3%82%92%e5%a4%89%e3%81%88%e3%81%a6%e3%81%bf%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.lancard.com\/blog\/2017\/12\/14\/laravel%e3%81%ae%e3%83%86%e3%82%b9%e3%83%88%e7%94%a8%e4%be%bf%e5%88%a9%e3%83%88%e3%83%ac%e3%82%a4%e3%83%88%e3%81%ae%e5%8b%95%e4%bd%9c%e3%82%92%e5%a4%89%e3%81%88%e3%81%a6%e3%81%bf%e3%82%8b\/","title":{"rendered":"Laravel\u306e\u30c6\u30b9\u30c8\u7528\u4fbf\u5229\u30c8\u30ec\u30a4\u30c8\u306e\u52d5\u4f5c\u3092\u5909\u3048\u3066\u307f\u308b"},"content":{"rendered":"<p>Laravel 5.5 \u3067\u3059\u3002<\/p>\n<p>Laravel\u306b\u306funit test\u7b49\u306e\u969b\u306buse\u3059\u308b\u3068\u3088\u308d\u3057\u304f\u3084\u3063\u3066\u304f\u308c\u308b\u30c8\u30ec\u30a4\u30c8\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u6628\u65e5\u306e\u8a18\u4e8b\u306b\u51fa\u3066\u304d\u305fRefreshDatabase\u3084DatabaseMigrations\u3001\u4ed6\u306b\u306fDatabaseTransactions\u3001WithoutMiddleware\u3001WithoutEvents\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u672c\u5f53\u306b\u4fbf\u5229\u306a\u306e\u3067\u3059\u304c\u3001\u3059\u3053\u3057\u52d5\u4f5c\u3092\u8abf\u6574\u3057\u305f\u3044\u3053\u3068\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070DatabaseMigrations\u3067\u30de\u30b9\u30bf\u30fc\u306e\u6d41\u3057\u8fbc\u307f\u307e\u3067\u3084\u308a\u305f\u3044\u3068\u304b\u3002<br \/>\n<!--more--><br \/>\n\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u5185\u3092\u8abf\u3079\u308b\u3068setUpTraits()\u3067\u30c8\u30ec\u30a4\u30c8\u304cuse\u3055\u308c\u305f\u304b\u3092\u5224\u5b9a\u3057\u3001\u7279\u5b9a\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3076\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u3002<\/p>\n<pre><code>    protected function setUpTraits()\n    {\n        $uses = array_flip(class_uses_recursive(static::class));\n\n        if (isset($uses[RefreshDatabase::class])) {\n            $this-&gt;refreshDatabase();\n        }\n\n        if (isset($uses[DatabaseMigrations::class])) {\n            $this-&gt;runDatabaseMigrations();\n        }\n\n        if (isset($uses[DatabaseTransactions::class])) {\n            $this-&gt;beginDatabaseTransaction();\n        }\n\n        if (isset($uses[WithoutMiddleware::class])) {\n            $this-&gt;disableMiddlewareForAllTests();\n        }\n\n        if (isset($uses[WithoutEvents::class])) {\n            $this-&gt;disableEventsForAllTests();\n        }\n\n        return $uses;\n    }\n<\/code><\/pre>\n<p>\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u3092app\/tests\/TestCase.php\u3084DuskTestCase.php\u3067\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3057\u3066\u81ea\u5206\u304c\u4f5c\u3063\u305f\u30c8\u30ec\u30a4\u30c8\u3092\u5b9f\u884c\u3059\u308b\u3088\u3046\u306b\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u79c1\u306e\u5834\u5408\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30c0\u30f3\u30d7\u3092\u30ea\u30b9\u30c8\u30a2\u3059\u308bSnapshotLoad\u3068\u3044\u3046\u30c8\u30ec\u30a4\u30c8\u3092\u4f5c\u6210\u3057\u3066\u8ffd\u52a0\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre><code>    protected function setUpTraits()\n    {\n        $uses = array_flip(class_uses_recursive(static::class));\n        if (isset($uses[SnapshotLoad::class])) {\n            \/\/ DatabaseTransactions\u306e\u524d\u306b\u5b9f\u884c\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002\n            $this-&gt;runSnapshotLoad();\n        }\n        return parent::setUpTraits();\n    }\n<\/code><\/pre>\n<p>\u9591\u8a71\u4f11\u984c\u3001<a href=\"lancard.com\/blog\/?p=5283\" rel=\"noopener\" target=\"_blank\">\u524d\u56de\u8a18\u4e8b<\/a>\u306e\u6700\u5f8c\u306e\u30c6\u30b9\u30c8\u30b5\u30f3\u30d7\u30eb\u3067\u306eDatabaseMigrations\u306e\u52d5\u4f5c\u3092\u5909\u66f4\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u547c\u3073\u51fa\u3055\u308c\u308brunDatabaseMigrations\u30e1\u30bd\u30c3\u30c9\u3092\u5225\u540d\u306b\u5909\u66f4\u3057\u3001\u65b0\u305f\u306b\u5b9a\u7fa9\u3057\u307e\u3059\u3002<\/p>\n<pre><code>&lt;?php\nnamespace Tests\\Browser;\nuse Tests\\DuskTestCase;\nuse Laravel\\Dusk\\Browser;\nuse Illuminate\\Foundation\\Testing\\DatabaseMigrations;\nuse App\\User;\n\nclass LoginTest extends DuskTestCase\n{\n    use DatabaseMigrations \n    {\n        runDatabaseMigrations as runDatabaseMigrationsOrg; \/\/\u540d\u524d\u5909\u3048\u308b\n    }\n    \/\/DatabaseMigrations\u306e\u52d5\u4f5c\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\n    public function runDatabaseMigrations()\n    {\n        $this-&gt;runDatabaseMigrationsOrg();  \/\/\u5143\u3005\u306e\u51e6\u7406\u3092\u5b9f\u884c\n        \\Artisan::call('db:seed', ['--class' =&gt; 'MasterSeeder']);\n    }\n\n    public function testLogin()\n    {\n        $user = factory(User::class)-&gt;create();\n\n        $this-&gt;browse(function (Browser $browser) use ($user) {\n            $browser-&gt;visit('\/login')\n                    -&gt;type('email', $user-&gt;email)\n                    -&gt;type('password', 'secret')\n                    -&gt;press('\u30ed\u30b0\u30a4\u30f3')\n                    -&gt;assertPathIs('\/home');\n        });\n    }\n}\n<\/code><\/pre>\n<p>\u5143\u3005\u306eDatabaseMigrations\u306e\u51e6\u7406\u5f8c\u306b\u30de\u30b9\u30bf\u30fc\u8a2d\u5b9a\u7528\u306eMasterSeeder\u304c\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002<\/p>\n<a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-facebook nolightbox\" data-provider=\"facebook\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Facebook\" href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F5289&#038;t=Laravel%E3%81%AE%E3%83%86%E3%82%B9%E3%83%88%E7%94%A8%E4%BE%BF%E5%88%A9%E3%83%88%E3%83%AC%E3%82%A4%E3%83%88%E3%81%AE%E5%8B%95%E4%BD%9C%E3%82%92%E5%A4%89%E3%81%88%E3%81%A6%E3%81%BF%E3%82%8B&#038;s=100&#038;p&#091;url&#093;=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F5289&#038;p&#091;images&#093;&#091;0&#093;=&#038;p&#091;title&#093;=Laravel%E3%81%AE%E3%83%86%E3%82%B9%E3%83%88%E7%94%A8%E4%BE%BF%E5%88%A9%E3%83%88%E3%83%AC%E3%82%A4%E3%83%88%E3%81%AE%E5%8B%95%E4%BD%9C%E3%82%92%E5%A4%89%E3%81%88%E3%81%A6%E3%81%BF%E3%82%8B\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"Facebook\" title=\"Share on Facebook\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/facebook.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-twitter nolightbox\" data-provider=\"twitter\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Twitter\" href=\"http:\/\/twitter.com\/share?url=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F5289&#038;text=Laravel%E3%81%AE%E3%83%86%E3%82%B9%E3%83%88%E7%94%A8%E4%BE%BF%E5%88%A9%E3%83%88%E3%83%AC%E3%82%A4%E3%83%88%E3%81%AE%E5%8B%95%E4%BD%9C%E3%82%92%E5%A4%89%E3%81%88%E3%81%A6%E3%81%BF%E3%82%8B\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"twitter\" title=\"Share on Twitter\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/twitter.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-linkedin nolightbox\" data-provider=\"linkedin\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Linkedin\" href=\"https:\/\/www.linkedin.com\/shareArticle?mini=true&#038;url=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F5289&#038;title=Laravel%E3%81%AE%E3%83%86%E3%82%B9%E3%83%88%E7%94%A8%E4%BE%BF%E5%88%A9%E3%83%88%E3%83%AC%E3%82%A4%E3%83%88%E3%81%AE%E5%8B%95%E4%BD%9C%E3%82%92%E5%A4%89%E3%81%88%E3%81%A6%E3%81%BF%E3%82%8B\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"linkedin\" title=\"Share on Linkedin\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/linkedin.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-tumblr nolightbox\" data-provider=\"tumblr\" target=\"_blank\" rel=\"nofollow\" title=\"Share on tumblr\" href=\"https:\/\/tumblr.com\/share?s=&#038;v=3&#038;t=Laravel%E3%81%AE%E3%83%86%E3%82%B9%E3%83%88%E7%94%A8%E4%BE%BF%E5%88%A9%E3%83%88%E3%83%AC%E3%82%A4%E3%83%88%E3%81%AE%E5%8B%95%E4%BD%9C%E3%82%92%E5%A4%89%E3%81%88%E3%81%A6%E3%81%BF%E3%82%8B&#038;u=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F5289\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"tumblr\" title=\"Share on tumblr\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/tumblr.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-mail nolightbox\" data-provider=\"mail\" rel=\"nofollow\" title=\"Share by email\" href=\"mailto:?subject=Laravel%E3%81%AE%E3%83%86%E3%82%B9%E3%83%88%E7%94%A8%E4%BE%BF%E5%88%A9%E3%83%88%E3%83%AC%E3%82%A4%E3%83%88%E3%81%AE%E5%8B%95%E4%BD%9C%E3%82%92%E5%A4%89%E3%81%88%E3%81%A6%E3%81%BF%E3%82%8B&#038;body=%E3%82%B7%E3%82%A7%E3%82%A2%E3%81%99%E3%82%8B%EF%BC%9A:%20https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F5289\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"mail\" title=\"Share by email\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/mail.png\" \/><\/a>","protected":false},"excerpt":{"rendered":"<p>Laravel 5.5 \u3067\u3059\u3002 Laravel\u306b\u306funit test\u7b49\u306e\u969b\u306buse\u3059\u308b\u3068\u3088\u308d\u3057\u304f\u3084\u3063\u3066\u304f\u308c\u308b\u30c8\u30ec\u30a4\u30c8\u304c\u3042\u308a\u307e\u3059\u3002 \u6628\u65e5\u306e\u8a18\u4e8b\u306b\u51fa\u3066\u304d\u305fRefreshDatabase\u3084DatabaseMigrations\u3001 [&hellip;]<\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[130],"class_list":["post-5289","post","type-post","status-publish","format-standard","hentry","category-1","tag-laravel"],"_links":{"self":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/5289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/comments?post=5289"}],"version-history":[{"count":12,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/5289\/revisions"}],"predecessor-version":[{"id":5369,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/5289\/revisions\/5369"}],"wp:attachment":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/media?parent=5289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/categories?post=5289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/tags?post=5289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}