db(); $db->statement(' DECLARE GLOBAL TEMPORARY TABLE SESSION.DB2_LARAVEL_TEST_NULLS ( ID INTEGER NOT NULL, NULLABLE_TEXT VARCHAR(4096), NULLABLE_DATE DATE, NULLABLE_TIME TIME, NULLABLE_TIMESTAMP TIMESTAMP ) ON COMMIT PRESERVE ROWS NOT LOGGED '); $db->statement(' INSERT INTO SESSION.DB2_LARAVEL_TEST_NULLS (ID, NULLABLE_TEXT, NULLABLE_DATE, NULLABLE_TIME, NULLABLE_TIMESTAMP) VALUES (1, NULL, NULL, NULL, NULL) '); $db->statement(" INSERT INTO SESSION.DB2_LARAVEL_TEST_NULLS (ID, NULLABLE_TEXT, NULLABLE_DATE, NULLABLE_TIME, NULLABLE_TIMESTAMP) VALUES ( 2, '', DATE('2026-11-11'), TIME('10:15:30'), TIMESTAMP('2026-11-11 10:15:30') ) "); } protected function tearDown(): void { try { $this->db()->statement( 'DROP TABLE SESSION.DB2_LARAVEL_TEST_NULLS' ); } finally { parent::tearDown(); } } public function test_null_values_are_restored(): void { $row = $this->db()->table('SESSION.' . self::TABLE) ->where('ID', 1) ->first(); $this->assertNull($row->NULLABLE_TEXT); $this->assertNull($row->NULLABLE_DATE); $this->assertNull($row->NULLABLE_TIME); $this->assertNull($row->NULLABLE_TIMESTAMP); } public function test_empty_string_is_not_converted_to_null(): void { $row = $this->db()->table('SESSION.' . self::TABLE) ->where('ID', 2) ->first(); $this->assertSame('', $row->NULLABLE_TEXT); } public function test_non_null_temporal_values_survive(): void { $row = $this->db()->table('SESSION.' . self::TABLE) ->where('ID', 2) ->first(); $this->assertNotNull($row->NULLABLE_DATE); $this->assertNotNull($row->NULLABLE_TIME); $this->assertNotNull($row->NULLABLE_TIMESTAMP); } public function test_generated_indicators_are_hidden(): void { $row = $this->db()->table('SESSION.' . self::TABLE) ->where('ID', 1) ->first(); foreach (array_keys((array) $row) as $column) { $this->assertDoesNotMatchRegularExpression( '/^__db2_null_flag_\d+$/i', $column ); } } public function test_nullable_aliases_are_preserved(): void { $row = $this->db()->table('SESSION.' . self::TABLE) ->select('NULLABLE_TEXT as aliased_text') ->where('ID', 1) ->first(); $this->assertTrue( property_exists($row, 'aliased_text') ); $this->assertNull($row->aliased_text); } }