33namespace Tests ;
44
55use Gallib \ShortUrl \Parsers \UrlParser ;
6+ use Illuminate \Database \Schema \Blueprint ;
67use Orchestra \Testbench \TestCase as OrchestraTestCase ;
78
89abstract class TestCase extends OrchestraTestCase
@@ -13,6 +14,8 @@ abstract class TestCase extends OrchestraTestCase
1314 protected function setUp (): void
1415 {
1516 parent ::setUp ();
17+
18+ $ this ->setUpDatabase ($ this ->app );
1619 }
1720
1821 /**
@@ -35,6 +38,20 @@ protected function getEnvironmentSetUp($app)
3538 \ShortUrl::routes ();
3639 }
3740
41+ /**
42+ * Set up the database.
43+ *
44+ * @param \Illuminate\Foundation\Application $app
45+ */
46+ protected function setUpDatabase ($ app )
47+ {
48+ $ app ['db ' ]->connection ()->getSchemaBuilder ()->create ('users ' , function (Blueprint $ table ) {
49+ $ table ->increments ('id ' );
50+ $ table ->string ('name ' );
51+ $ table ->timestamps ();
52+ });
53+ }
54+
3855 /**
3956 * Get package providers. At a minimum this is the package being tested, but also
4057 * would include packages upon which our package depends, e.g. Cartalyst/Sentry
@@ -124,4 +141,19 @@ public function createUrl(array $parameters = [])
124141
125142 return $ this ->postJson (route ('shorturl.url.store ' ), $ parameters )->json ();
126143 }
144+
145+ /**
146+ * Create a user.
147+ *
148+ * @param array $parameters
149+ * @return User
150+ */
151+ public function createUser (array $ parameters = [])
152+ {
153+ $ provider = config ('auth.guards.api.provider ' );
154+ $ model = config ("auth.providers. {$ provider }.model " );
155+ $ parameters = array_merge (['name ' => 'Thibault Timeo ' ], $ parameters );
156+
157+ return $ model ::create (['name ' => 'Test ' ]);
158+ }
127159}
0 commit comments