|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace CodeIgniter\Database\Live\Postgre; |
| 4 | + |
| 5 | +use CodeIgniter\Test\CIUnitTestCase; |
| 6 | +use CodeIgniter\Test\DatabaseTestTrait; |
| 7 | +use PHPUnit\Framework\Attributes\Group; |
| 8 | +use Tests\Support\Database\Seeds\CITestSeeder; |
| 9 | + |
| 10 | +#[Group('DatabaseLive')] |
| 11 | +class IncrementTest extends CIUnitTestCase |
| 12 | +{ |
| 13 | + use DatabaseTestTrait; |
| 14 | + |
| 15 | + protected $refresh = true; |
| 16 | + protected $seed = CITestSeeder::class; |
| 17 | + |
| 18 | + protected function setUp(): void |
| 19 | + { |
| 20 | + parent::setUp(); |
| 21 | + |
| 22 | + if ($this->db->DBDriver !== 'Postgre') { |
| 23 | + $this->markTestSkipped('This test is only for Postgre.'); |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + public function testIncrementWithNumericColumns(): void |
| 28 | + { |
| 29 | + $this->hasInDatabase('job', ['name' => 'incremental', 'created_at' => 6]); |
| 30 | + |
| 31 | + $this->db->table('job') |
| 32 | + ->where('name', 'incremental') |
| 33 | + ->increment('created_at'); |
| 34 | + |
| 35 | + $this->seeInDatabase('job', ['name' => 'incremental', 'created_at' => 7]); |
| 36 | + } |
| 37 | + |
| 38 | + public function testIncrementWithNumericColumnsAndValue(): void |
| 39 | + { |
| 40 | + $this->hasInDatabase('job', ['name' => 'incremental', 'created_at' => 6]); |
| 41 | + |
| 42 | + $this->db->table('job') |
| 43 | + ->where('name', 'incremental') |
| 44 | + ->increment('created_at', 2); |
| 45 | + |
| 46 | + $this->seeInDatabase('job', ['name' => 'incremental', 'created_at' => 8]); |
| 47 | + } |
| 48 | + |
| 49 | + public function testDecrementWithNumericColumns(): void |
| 50 | + { |
| 51 | + $this->hasInDatabase('job', ['name' => 'incremental', 'created_at' => 6]); |
| 52 | + |
| 53 | + $this->db->table('job') |
| 54 | + ->where('name', 'incremental') |
| 55 | + ->decrement('created_at'); |
| 56 | + |
| 57 | + $this->seeInDatabase('job', ['name' => 'incremental', 'created_at' => 5]); |
| 58 | + } |
| 59 | + |
| 60 | + public function testDecrementWithNumericColumnsAndValue(): void |
| 61 | + { |
| 62 | + $this->hasInDatabase('job', ['name' => 'incremental', 'created_at' => 6]); |
| 63 | + |
| 64 | + $this->db->table('job') |
| 65 | + ->where('name', 'incremental') |
| 66 | + ->decrement('created_at', 2); |
| 67 | + |
| 68 | + $this->seeInDatabase('job', ['name' => 'incremental', 'created_at' => 4]); |
| 69 | + } |
| 70 | +} |
0 commit comments