/
githubmirror
/
framework
Обзор
Документация
Войти
/
githubmirror
/
framework
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
13.x
tests/Integration/Database/MariaDb/DatabaseEloquentMariaDbIntegrationTest.php
84 строки
3 KB
Jonas Staudenmeir
Add MariaDB driver (#50146)
19 фев 2024, 17:30
Не верифицирован
19 фев 2024, 17:30
61db497
Код
Авторство
О чём код?
<?php namespace Illuminate\Tests\Integration\Database\MariaDb; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; class DatabaseEloquentMariaDbIntegrationTest extends MariaDbTestCase { protected function afterRefreshingDatabase() { if (! Schema::hasTable('database_eloquent_mariadb_integration_users')) { Schema::create('database_eloquent_mariadb_integration_users', function (Blueprint $table) { $table->id(); $table->string('name')->nullable(); $table->string('email')->unique(); $table->timestamps(); }); } } protected function destroyDatabaseMigrations() { Schema::drop('database_eloquent_mariadb_integration_users'); } public function testCreateOrFirst() { $user1 = DatabaseEloquentMariaDbIntegrationUser::createOrFirst(['email' => 'taylorotwell@gmail.com']); $this->assertSame('taylorotwell@gmail.com', $user1->email); $this->assertNull($user1->name); $user2 = DatabaseEloquentMariaDbIntegrationUser::createOrFirst( ['email' => 'taylorotwell@gmail.com'], ['name' => 'Taylor Otwell'] ); $this->assertEquals($user1->id, $user2->id); $this->assertSame('taylorotwell@gmail.com', $user2->email); $this->assertNull($user2->name); $user3 = DatabaseEloquentMariaDbIntegrationUser::createOrFirst( ['email' => 'abigailotwell@gmail.com'], ['name' => 'Abigail Otwell'] ); $this->assertNotEquals($user3->id, $user1->id); $this->assertSame('abigailotwell@gmail.com', $user3->email); $this->assertSame('Abigail Otwell', $user3->name); $user4 = DatabaseEloquentMariaDbIntegrationUser::createOrFirst( ['name' => 'Dries Vints'], ['name' => 'Nuno Maduro', 'email' => 'nuno@laravel.com'] ); $this->assertSame('Nuno Maduro', $user4->name); } public function testCreateOrFirstWithinTransaction() { $user1 = DatabaseEloquentMariaDbIntegrationUser::createOrFirst(['email' => 'taylor@laravel.com']); DB::transaction(function () use ($user1) { $user2 = DatabaseEloquentMariaDbIntegrationUser::createOrFirst( ['email' => 'taylor@laravel.com'], ['name' => 'Taylor Otwell'] ); $this->assertEquals($user1->id, $user2->id); $this->assertSame('taylor@laravel.com', $user2->email); $this->assertNull($user2->name); }); } } class DatabaseEloquentMariaDbIntegrationUser extends Model { protected $table = 'database_eloquent_mariadb_integration_users'; protected $guarded = []; }