Skip to content

Commit

Permalink
Create tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dsbilling committed Mar 25, 2022
1 parent 52cdf0c commit ef4a225
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 8 deletions.
45 changes: 45 additions & 0 deletions tests/HasUserGuestLikeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php


namespace Kilobyteno\LaravelUserGuestLike\Tests;

use Kilobyteno\LaravelUserGuestLike\Tests\Models\TestAuthorModel;
use Kilobyteno\LaravelUserGuestLike\Tests\Models\TestModel;

class HasUserGuestLikeTest extends TestCase
{
/** @var TestModel */
protected TestModel $testModel;
protected TestAuthorModel $author;

public function setUp(): void
{
parent::setUp();

$this->testModel = TestModel::create([
'name' => 'Test Model',
]);

$this->author = TestAuthorModel::create([
'name' => 'Test Author',
]);
}

/** @test */
public function it_can_be_liked_by_a_user()
{
$this->testModel->like($this->author);

$this->assertEquals(1, $this->testModel->likes()->count());
}

/** @test */
public function it_can_be_unliked_by_a_user()
{
$this->testModel->like($this->author);
$this->testModel->dislike($this->author);

$this->assertEquals(0, $this->testModel->likes()->count());
}

}
11 changes: 11 additions & 0 deletions tests/Models/TestAuthorModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Kilobyteno\LaravelUserGuestLike\Tests\Models;

use Illuminate\Database\Eloquent\Model;

class TestAuthorModel extends Model
{
protected $table = 'users';
protected $guarded = [];
}
13 changes: 13 additions & 0 deletions tests/Models/TestModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Kilobyteno\LaravelUserGuestLike\Tests\Models;

use Illuminate\Database\Eloquent\Model;
use Kilobyteno\LaravelUserGuestLike\Traits\HasUserGuestLike;

class TestModel extends Model
{
use HasUserGuestLike;
protected $table = 'posts';
protected $guarded = [];
}
35 changes: 27 additions & 8 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

namespace Kilobyteno\LaravelUserGuestLike\Tests;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Schema;
use Orchestra\Testbench\TestCase as Orchestra;
use Kilobyteno\LaravelUserGuestLike\LaravelUserGuestLikeServiceProvider;

class TestCase extends Orchestra
{
use RefreshDatabase;

protected function setUp(): void
{
parent::setUp();

Factory::guessFactoryNamesUsing(
fn (string $modelName) => 'Kilobyteno\\LaravelUserGuestLike\\Database\\Factories\\'.class_basename($modelName).'Factory'
);
}

protected function getPackageProviders($app)
Expand All @@ -28,9 +28,28 @@ public function getEnvironmentSetUp($app)
{
config()->set('database.default', 'testing');

/*
$migration = include __DIR__.'/../database/migrations/create_laravel-user-guest-like_table.php.stub';
$app['config']->set('database.connections.testing', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);

Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->timestamps();
$table->softDeletes();
});

Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->timestamps();
$table->softDeletes();
});

$migration = include __DIR__.'/../database/migrations/create_user_guest_like_table.php.stub';
$migration->up();
*/

}
}

0 comments on commit ef4a225

Please sign in to comment.