-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.x] Accept enums for insert update and where (#39492)
* accept enums for insert update and where * fix style * Update tests/Integration/Database/QueryingWithEnumsTest.php Co-authored-by: Dries Vints <[email protected]> * Update tests/Integration/Database/QueryingWithEnumsTest.php Co-authored-by: Dries Vints <[email protected]> Co-authored-by: Taylor Otwell <[email protected]> Co-authored-by: Dries Vints <[email protected]>
- Loading branch information
1 parent
cb46639
commit 1c834e4
Showing
3 changed files
with
131 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Database; | ||
|
||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
if (PHP_VERSION_ID >= 80100) { | ||
include_once 'Enums.php'; | ||
} | ||
|
||
/** | ||
* @requires PHP >= 8.1 | ||
*/ | ||
class QueryingWithEnumsTest extends DatabaseTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
Schema::create('enum_casts', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->string('string_status', 100)->nullable(); | ||
$table->integer('integer_status')->nullable(); | ||
}); | ||
} | ||
|
||
public function testCanQueryWithEnums() | ||
{ | ||
DB::table('enum_casts')->insert([ | ||
'string_status' => 'pending', | ||
'integer_status' => 1, | ||
]); | ||
|
||
$record = DB::table('enum_casts')->where('string_status', StringStatus::pending)->first(); | ||
$record2 = DB::table('enum_casts')->where('integer_status', IntegerStatus::pending)->first(); | ||
$record3 = DB::table('enum_casts')->whereIn('integer_status', [IntegerStatus::pending])->first(); | ||
|
||
$this->assertNotNull($record); | ||
$this->assertNotNull($record2); | ||
$this->assertNotNull($record3); | ||
$this->assertEquals('pending', $record->string_status); | ||
$this->assertEquals(1, $record2->integer_status); | ||
} | ||
|
||
public function testCanInsertWithEnums() | ||
{ | ||
DB::table('enum_casts')->insert([ | ||
'string_status' => StringStatus::pending, | ||
'integer_status' => IntegerStatus::pending, | ||
]); | ||
|
||
$record = DB::table('enum_casts')->where('string_status', StringStatus::pending)->first(); | ||
|
||
$this->assertNotNull($record); | ||
$this->assertEquals('pending', $record->string_status); | ||
$this->assertEquals(1, $record->integer_status); | ||
} | ||
} |