Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
175 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Umbrellio\Postgres\Tests\Functional\Connection; | ||
|
||
use Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase; | ||
use Illuminate\Foundation\Testing\DatabaseTransactions; | ||
use Illuminate\Support\Carbon; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Schema; | ||
use Umbrellio\Postgres\Schema\Blueprint; | ||
use Umbrellio\Postgres\Tests\FunctionalTestCase; | ||
|
||
class ConnectionTest extends FunctionalTestCase | ||
{ | ||
use DatabaseTransactions, InteractsWithDatabase; | ||
|
||
protected $emulatePrepares = true; | ||
|
||
/** | ||
* @test | ||
* @dataProvider boolDataProvider | ||
*/ | ||
public function boolTrueBindingsWorks($value) | ||
{ | ||
$table = 'test_table'; | ||
$data = ['field' => $value]; | ||
Schema::create($table, function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->boolean('field'); | ||
}); | ||
DB::table($table)->insert($data); | ||
$result = DB::table($table)->select($data); | ||
$this->assertSame(1, $result->count()); | ||
} | ||
|
||
/** | ||
* @test | ||
* @dataProvider intDataProvider | ||
*/ | ||
public function intBindingsWorks($value) | ||
{ | ||
$table = 'test_table'; | ||
$data = ['field' => $value]; | ||
Schema::create($table, function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->integer('field'); | ||
}); | ||
DB::table($table)->insert($data); | ||
$result = DB::table($table)->select($data); | ||
$this->assertSame(1, $result->count()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function stringBindingsWorks() | ||
{ | ||
$table = 'test_table'; | ||
$data = ['field' => 'string']; | ||
Schema::create($table, function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->string('field'); | ||
}); | ||
DB::table($table)->insert($data); | ||
$result = DB::table($table)->select($data); | ||
$this->assertSame(1, $result->count()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function nullBindingsWorks() | ||
{ | ||
$table = 'test_table'; | ||
$data = ['field' => null]; | ||
Schema::create($table, function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->string('field')->nullable(); | ||
}); | ||
DB::table($table)->insert($data); | ||
$result = DB::table($table)->whereNull('field')->get(); | ||
$this->assertSame(1, $result->count()); | ||
} | ||
|
||
/** | ||
* @test | ||
* @dataProvider dateDataProvider | ||
*/ | ||
public function dateTimeBindingsWorks($value) | ||
{ | ||
$table = 'test_table'; | ||
$data = ['field' => $value]; | ||
Schema::create($table, function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->dateTime('field'); | ||
}); | ||
DB::table($table)->insert($data); | ||
$result = DB::table($table)->select($data); | ||
$this->assertSame(1, $result->count()); | ||
} | ||
|
||
public function boolDataProvider() | ||
{ | ||
yield 'true' => [true]; | ||
yield 'false' => [false]; | ||
} | ||
|
||
public function intDataProvider() | ||
{ | ||
yield 'zero' => [0]; | ||
yield 'non-zero' => [10]; | ||
} | ||
|
||
public function dateDataProvider() | ||
{ | ||
yield 'as string' => ['2019-01-01 13:12:22']; | ||
yield 'as Carbon object' => [new Carbon('2019-01-01 13:12:22')]; | ||
} | ||
} |
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