diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..a48abe7 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,10 @@ + + + + + ./tests + + + diff --git a/tests/HasTasksTest.php b/tests/HasTasksTest.php new file mode 100644 index 0000000..e4f1901 --- /dev/null +++ b/tests/HasTasksTest.php @@ -0,0 +1,23 @@ + 'Test User']); + + $task = $user->addTask(['name' => 'Test Task']); + + $this->assertInstanceOf(Task::class, $task); + $this->assertEquals($user->id, $task->owner_id); + $this->assertEquals(User::class, $task->owner_class); + + $this->assertCount(1, $user->tasks); + $this->assertTrue($user->tasks->first()->is($task)); + $this->assertCount(1, $user->pendingTasks()); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..b8d0ed3 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,42 @@ +id(); + $table->string('name')->nullable(); + $table->timestamps(); + }); + + // run package migrations + $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); + } + + protected function getPackageProviders($app) + { + return [ + TasksServiceProvider::class, + ]; + } + + protected function getEnvironmentSetUp($app) + { + $app['config']->set('database.default', 'testing'); + $app['config']->set('database.connections.testing', [ + 'driver' => 'sqlite', + 'database' => ':memory:', + 'prefix' => '', + ]); + } +} diff --git a/tests/User.php b/tests/User.php new file mode 100644 index 0000000..362a03d --- /dev/null +++ b/tests/User.php @@ -0,0 +1,15 @@ +