2014-11-13 11:44:30 -08:00
< ? php
2017-01-17 14:30:19 +00:00
namespace Illuminate\Tests\Database ;
2018-10-03 22:05:43 +02:00
use Illuminate\Database\Query\Processors\PostgresProcessor ;
2019-09-10 17:16:05 +02:00
use PHPUnit\Framework\TestCase ;
2016-12-30 21:31:11 +01:00
class DatabasePostgresProcessorTest extends TestCase
2015-06-01 16:26:53 +01:00
{
2023-10-26 21:50:57 +03:30
public function testProcessColumns ()
2015-06-01 15:56:31 +01:00
{
2018-10-03 22:05:43 +02:00
$processor = new PostgresProcessor ;
2014-11-13 11:44:30 -08:00
2023-10-26 21:50:57 +03:30
$listing = [
2024-05-11 03:24:21 +08:00
[ 'name' => 'id' , 'type_name' => 'int4' , 'type' => 'integer' , 'collation' => '' , 'nullable' => true , 'default' => " nextval('employee_id_seq'::regclass) " , 'comment' => '' , 'generated' => false ],
[ 'name' => 'name' , 'type_name' => 'varchar' , 'type' => 'character varying(100)' , 'collation' => 'collate' , 'nullable' => false , 'default' => '' , 'comment' => 'foo' , 'generated' => false ],
[ 'name' => 'balance' , 'type_name' => 'numeric' , 'type' => 'numeric(8,2)' , 'collation' => '' , 'nullable' => true , 'default' => '4' , 'comment' => 'NULL' , 'generated' => false ],
[ 'name' => 'birth_date' , 'type_name' => 'timestamp' , 'type' => 'timestamp(6) without time zone' , 'collation' => '' , 'nullable' => false , 'default' => '' , 'comment' => '' , 'generated' => false ],
2023-10-26 21:50:57 +03:30
];
$expected = [
2024-03-04 18:43:36 +03:30
[ 'name' => 'id' , 'type_name' => 'int4' , 'type' => 'integer' , 'collation' => '' , 'nullable' => true , 'default' => " nextval('employee_id_seq'::regclass) " , 'auto_increment' => true , 'comment' => '' , 'generation' => null ],
[ 'name' => 'name' , 'type_name' => 'varchar' , 'type' => 'character varying(100)' , 'collation' => 'collate' , 'nullable' => false , 'default' => '' , 'auto_increment' => false , 'comment' => 'foo' , 'generation' => null ],
[ 'name' => 'balance' , 'type_name' => 'numeric' , 'type' => 'numeric(8,2)' , 'collation' => '' , 'nullable' => true , 'default' => '4' , 'auto_increment' => false , 'comment' => 'NULL' , 'generation' => null ],
[ 'name' => 'birth_date' , 'type_name' => 'timestamp' , 'type' => 'timestamp(6) without time zone' , 'collation' => '' , 'nullable' => false , 'default' => '' , 'auto_increment' => false , 'comment' => '' , 'generation' => null ],
2023-10-26 21:50:57 +03:30
];
2014-11-13 11:44:30 -08:00
2023-10-26 21:50:57 +03:30
$this -> assertEquals ( $expected , $processor -> processColumns ( $listing ));
2014-12-18 09:28:55 +00:00
2015-06-01 15:56:31 +01:00
// convert listing to objects to simulate PDO::FETCH_CLASS
2015-06-01 16:26:53 +01:00
foreach ( $listing as & $row ) {
2015-06-01 15:56:31 +01:00
$row = ( object ) $row ;
}
2014-12-18 09:28:55 +00:00
2023-10-26 21:50:57 +03:30
$this -> assertEquals ( $expected , $processor -> processColumns ( $listing ));
2015-06-01 15:56:31 +01:00
}
2014-11-13 11:44:30 -08:00
}