Skip to content

Commit

Permalink
two test model created;
Browse files Browse the repository at this point in the history
  • Loading branch information
hans-thomas committed Aug 28, 2023
1 parent aca950b commit 002e372
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/Core/Models/Post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Hans\Lyra\Tests\Core\Models;

use Hans\Lyra\Models\Invoice;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphToMany;

class Post extends Model {

protected $fillable = [
'title',
'description',
];

public function invoices(): MorphToMany {
return $this->morphToMany( Invoice::class, 'invoicable' );
}
}
20 changes: 20 additions & 0 deletions tests/Core/Models/Product.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Hans\Lyra\Tests\Core\Models;

use Hans\Lyra\Models\Invoice;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphToMany;

class Product extends Model {

protected $fillable = [
'title',
'brand'
];

public function invoices(): MorphToMany {
return $this->morphToMany( Invoice::class, 'invoicable' );
}

}
31 changes: 31 additions & 0 deletions tests/Core/migrations/2023_08_25_100000_create_posts_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Hans\Lyra\Tests\Core\Models\Post;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up(): void {
Schema::create( ( new Post )->getTable(), function( Blueprint $table ) {
$table->id();
$table->string( 'title' );
$table->text( 'description' );
$table->timestamps();
} );
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void {
Schema::dropIfExists( ( new Post )->getTable() );
}
};
32 changes: 32 additions & 0 deletions tests/Core/migrations/2023_08_25_100001_create_products_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Hans\Lyra\Models\Invoice;
use Hans\Lyra\Tests\Core\Models\Product;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up(): void {
Schema::create( ( new Product )->getTable(), function( Blueprint $table ) {
$table->id();
$table->string( 'name' );
$table->string( 'brand' );
$table->timestamps();
} );
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void {
Schema::dropIfExists( ( new Product )->getTable() );
}
};
1 change: 1 addition & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class TestCase extends BaseTestCase
protected function setUp(): void
{
parent::setUp();
$this->loadMigrationsFrom(__DIR__.'/Core/migrations');

$this->client = new Client;
}
Expand Down

0 comments on commit 002e372

Please sign in to comment.