|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * This file is part of CodeIgniter 4 framework. |
| 7 | + * |
| 8 | + * (c) CodeIgniter Foundation <admin@codeigniter.com> |
| 9 | + * |
| 10 | + * For the full copyright and license information, please view |
| 11 | + * the LICENSE file that was distributed with this source code. |
| 12 | + */ |
| 13 | + |
| 14 | +namespace CodeIgniter\Database\Live\SQLSRV; |
| 15 | + |
| 16 | +use CodeIgniter\Database\SQLSRV\Builder; |
| 17 | +use CodeIgniter\Test\CIUnitTestCase; |
| 18 | +use CodeIgniter\Test\DatabaseTestTrait; |
| 19 | +use PHPUnit\Framework\Attributes\Group; |
| 20 | +use Tests\Support\Database\Seeds\CITestSeeder; |
| 21 | + |
| 22 | +/** |
| 23 | + * @internal |
| 24 | + */ |
| 25 | +#[Group('DatabaseLive')] |
| 26 | +final class IncrementTest extends CIUnitTestCase |
| 27 | +{ |
| 28 | + use DatabaseTestTrait; |
| 29 | + |
| 30 | + protected $refresh = true; |
| 31 | + protected $seed = CITestSeeder::class; |
| 32 | + |
| 33 | + protected function setUp(): void |
| 34 | + { |
| 35 | + parent::setUp(); |
| 36 | + |
| 37 | + if ($this->db->DBDriver !== 'SQLSRV') { |
| 38 | + $this->markTestSkipped('This test is only for SQLSRV.'); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + public function testIncrementWhenCastTextToIntFalse(): void |
| 43 | + { |
| 44 | + $this->hasInDatabase('job', ['name' => 'incremental', 'created_at' => 6]); |
| 45 | + |
| 46 | + $builder = $this->db->table('job'); |
| 47 | + |
| 48 | + $this->assertInstanceOf(Builder::class, $builder); |
| 49 | + |
| 50 | + $builder->castTextToInt = false; |
| 51 | + |
| 52 | + $builder->where('name', 'incremental') |
| 53 | + ->increment('created_at'); |
| 54 | + |
| 55 | + $this->seeInDatabase('job', ['name' => 'incremental', 'created_at' => 7]); |
| 56 | + } |
| 57 | + |
| 58 | + public function testDecrementWhenCastTextToIntFalse(): void |
| 59 | + { |
| 60 | + $this->hasInDatabase('job', ['name' => 'decremental', 'created_at' => 6]); |
| 61 | + |
| 62 | + $builder = $this->db->table('job'); |
| 63 | + |
| 64 | + $this->assertInstanceOf(Builder::class, $builder); |
| 65 | + |
| 66 | + $builder->castTextToInt = false; |
| 67 | + |
| 68 | + $builder->where('name', 'decremental') |
| 69 | + ->decrement('created_at'); |
| 70 | + |
| 71 | + $this->seeInDatabase('job', ['name' => 'decremental', 'created_at' => 5]); |
| 72 | + } |
| 73 | +} |
0 commit comments