{"action":"opened","issue":{"url":"https://api.github.com/repos/orchestral/testbench-dusk/issues/26","repository_url":"https://api.github.com/repos/orchestral/testbench-dusk","labels_url":"https://api.github.com/repos/orchestral/testbench-dusk/issues/26/labels{/name}","comments_url":"https://api.github.com/repos/orchestral/testbench-dusk/issues/26/comments","events_url":"https://api.github.com/repos/orchestral/testbench-dusk/issues/26/events","html_url":"https://github.com/orchestral/testbench-dusk/issues/26","id":309300563,"number":26,"title":"Two different migrations, both called CreateUsersTable, may appear within a test suite ","user":{"login":"bjuppa","id":5339269,"avatar_url":"https://avatars1.githubusercontent.com/u/5339269?v=4","gravatar_id":"","url":"https://api.github.com/users/bjuppa","html_url":"https://github.com/bjuppa","followers_url":"https://api.github.com/users/bjuppa/followers","following_url":"https://api.github.com/users/bjuppa/following{/other_user}","gists_url":"https://api.github.com/users/bjuppa/gists{/gist_id}","starred_url":"https://api.github.com/users/bjuppa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjuppa/subscriptions","organizations_url":"https://api.github.com/users/bjuppa/orgs","repos_url":"https://api.github.com/users/bjuppa/repos","events_url":"https://api.github.com/users/bjuppa/events{/privacy}","received_events_url":"https://api.github.com/users/bjuppa/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-28T10:04:43Z","updated_at":"2018-03-28T10:04:43Z","closed_at":null,"author_association":"NONE","body":"I really appreciate @crynobone's work in #6 that gives our Dusk tests the most likely Laravel skeleton for the task, as it matches the defaults of a fresh Laravel app, thanks a million!\r\n\r\nHowever... with that comes a problem if you use [`loadLaravelMigrations()`](https://github.com/orchestral/testbench-core/blob/master/src/Concerns/WithLaravelMigrations.php).\r\n\r\n### The problem\r\nIf your test suite includes some tests that extend the Dusk test class `\\Orchestra\\Testbench\\Dusk\\TestCase` and also some other tests that extend the \"normal\" test class `\\Orchestra\\Testbench\\TestCase`, there could be **migrations loaded from both skeletons during the same test run**.\r\n\r\nThe Laravel migration classes are not namespaced so this is the error you may see when running your test suite:\r\n\r\n`PHP Fatal error:  Cannot declare class CreateUsersTable, because the name is already in use in...`\r\n\r\n### A solution\r\nI solved this by making sure all integration tests in my test suite use the same Laravel skeleton (the one from `testbench-dusk`), regardless of the base class they extend. You can do that by overriding `getBasePath()` in your test class.\r\n\r\n```php\r\n/**\r\n* Make sure all integration tests use the Laravel files of the testbench-dusk package.\r\n*\r\n* This avoids duplicate classes in migrations.\r\n* Overrides \\Orchestra\\Testbench\\Dusk\\TestCase::getBasePath and\r\n* \\Orchestra\\Testbench\\Concerns\\CreatesApplication::getBasePath\r\n*\r\n* @return string\r\n*/\r\nprotected function getBasePath()\r\n{\r\n    return __DIR__.'/../vendor/orchestra/testbench-dusk/laravel';\r\n}\r\n```\r\n\r\nI actually did that override in my `IntegrationTestSetupTrait` that I use in both dusk tests and other integration tests. But as long as the override is placed somewhere in your test class hierarchy so that it covers all integration test it should be fine! You may need to adjust the path depending on how many directories deep your test class lies in your own package structure (mine goes straight in the `/tests` directory).\r\n\r\nHope this can help someone that encounters the same problem!\r\nI'm sorry I can't offer a suggestion as to how this could be solved in the testbench packages themselves though. Apart from namespacing the migrations in the skeletons, but that's probably not a good idea as it could have tons of other implications."}}
{"actor":{"display_login":"bjuppa"}}