Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
colors="true"
verbose="true">
<testsuites>
<testsuite name="Package Tests">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
</phpunit>
23 changes: 23 additions & 0 deletions tests/HasTasksTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Michal78\Tasks\Tests;

use Michal78\Tasks\Models\Task;

class HasTasksTest extends TestCase
{
public function test_model_can_create_and_retrieve_tasks()
{
$user = User::create(['name' => '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());
}
}
42 changes: 42 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Michal78\Tasks\Tests;

use Orchestra\Testbench\TestCase as Orchestra;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Michal78\Tasks\TasksServiceProvider;

abstract class TestCase extends Orchestra
{
protected function setUp(): void
{
parent::setUp();

Schema::create('users', function (Blueprint $table) {
$table->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' => '',
]);
}
}
15 changes: 15 additions & 0 deletions tests/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Michal78\Tasks\Tests;

use Illuminate\Database\Eloquent\Model;
use Michal78\Tasks\Traits\HasTasks;

class User extends Model
{
use HasTasks;

protected $table = 'users';

protected $guarded = [];
}
Loading