|
| 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; |
| 15 | + |
| 16 | +use CodeIgniter\Database\BaseConnection; |
| 17 | +use CodeIgniter\Database\Forge; |
| 18 | +use CodeIgniter\Test\CIUnitTestCase; |
| 19 | +use Config\Database; |
| 20 | + |
| 21 | +abstract class AbstractGetFieldDataTest extends CIUnitTestCase |
| 22 | +{ |
| 23 | + /** |
| 24 | + * @var BaseConnection |
| 25 | + */ |
| 26 | + protected $db; |
| 27 | + |
| 28 | + protected Forge $forge; |
| 29 | + |
| 30 | + protected function setUp(): void |
| 31 | + { |
| 32 | + parent::setUp(); |
| 33 | + |
| 34 | + $this->db = Database::connect($this->DBGroup); |
| 35 | + |
| 36 | + $this->createForge(); |
| 37 | + $this->createTable(); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Make sure that $db and $forge are instantiated. |
| 42 | + */ |
| 43 | + abstract protected function createForge(): void; |
| 44 | + |
| 45 | + protected function tearDown(): void |
| 46 | + { |
| 47 | + parent::tearDown(); |
| 48 | + |
| 49 | + $this->forge->dropTable('test1', true); |
| 50 | + } |
| 51 | + |
| 52 | + protected function createTable() |
| 53 | + { |
| 54 | + $this->forge->dropTable('test1', true); |
| 55 | + |
| 56 | + $this->forge->addField([ |
| 57 | + 'id' => [ |
| 58 | + 'type' => 'INT', |
| 59 | + 'auto_increment' => true, |
| 60 | + ], |
| 61 | + 'text_not_null' => [ |
| 62 | + 'type' => 'VARCHAR', |
| 63 | + 'constraint' => 64, |
| 64 | + ], |
| 65 | + 'text_null' => [ |
| 66 | + 'type' => 'VARCHAR', |
| 67 | + 'constraint' => 64, |
| 68 | + 'null' => true, |
| 69 | + ], |
| 70 | + 'int_default_0' => [ |
| 71 | + 'type' => 'INT', |
| 72 | + 'default' => 0, |
| 73 | + ], |
| 74 | + 'text_default_null' => [ |
| 75 | + 'type' => 'VARCHAR', |
| 76 | + 'constraint' => 64, |
| 77 | + 'default' => null, |
| 78 | + ], |
| 79 | + 'text_default_text_null' => [ |
| 80 | + 'type' => 'VARCHAR', |
| 81 | + 'constraint' => 64, |
| 82 | + 'default' => 'null', |
| 83 | + ], |
| 84 | + 'text_default_abc' => [ |
| 85 | + 'type' => 'VARCHAR', |
| 86 | + 'constraint' => 64, |
| 87 | + 'default' => 'abc', |
| 88 | + ], |
| 89 | + ]); |
| 90 | + $this->forge->addKey('id', true); |
| 91 | + $this->forge->createTable('test1'); |
| 92 | + } |
| 93 | + |
| 94 | + abstract public function testGetFieldData(): void; |
| 95 | +} |
0 commit comments