mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 22:01:48 +00:00
feat: database support
This commit is contained in:
+44
-2
@@ -1,10 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Events\Dispatcher;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Capsule\Manager as DB;
|
||||
use PHPUnit\Framework\TestCase as BaseTestCase;
|
||||
|
||||
abstract class TestCase extends BaseTestCase
|
||||
class TestCase extends BaseTestCase
|
||||
{
|
||||
//
|
||||
protected DB $db;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
// Create a Laravel container
|
||||
$container = Container::getInstance();
|
||||
$dispatcher = new Dispatcher;
|
||||
|
||||
// Setup Capsule (Eloquent ORM)
|
||||
$this->db = new DB($container);
|
||||
$this->db->addConnection([
|
||||
'driver' => 'sqlite',
|
||||
'database' => ':memory:',
|
||||
'prefix' => '',
|
||||
]);
|
||||
$this->db->setAsGlobal();
|
||||
$this->db->bootEloquent();
|
||||
$this->db->getConnection()->setEventDispatcher($dispatcher);
|
||||
|
||||
// Run migrations (optional, for testing models)
|
||||
$this->migrateDatabase();
|
||||
}
|
||||
|
||||
protected function migrateDatabase()
|
||||
{
|
||||
$schema = $this->db->schema();
|
||||
|
||||
$schema->create('carts', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('session_id');
|
||||
$table->text('items');
|
||||
$table->text('conditions');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user