diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 983c8c93c3..10a3225bc8 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -43,7 +43,7 @@ parameters: - '~^Access to an undefined property Atk4\\Data\\Persistence::\$connection\.$~' - '~^Call to an undefined method Atk4\\Data\\Persistence::dsql\(\)\.$~' # for src/Field/SqlExpressionField.php - - '~^Call to an undefined method Atk4\\Data\\Model::expr\(\)\.$~' + - '~^Call to an undefined method Atk4\\Data\\Model2?::expr\(\)\.$~' # for src/Model.php - '~^Call to an undefined method Atk4\\Data\\Persistence::update\(\)\.$~' - '~^Call to an undefined method Atk4\\Data\\Persistence::insert\(\)\.$~' @@ -60,7 +60,7 @@ parameters: - '~^Call to an undefined method Atk4\\Data\\Persistence::initQuery\(\)\.$~' - '~^Call to an undefined method Atk4\\Data\\Persistence::lastInsertId\(\)\.$~' # for src/Reference/HasMany.php - - '~^Call to an undefined method Atk4\\Data\\Model::dsql\(\)\.$~' + - '~^Call to an undefined method Atk4\\Data\\Model2?::dsql\(\)\.$~' # for tests/FieldTest.php - '~^Call to an undefined method Atk4\\Data\\Reference\\HasOne::addTitle\(\)\.$~' # for tests/JoinSqlTest.php diff --git a/src/Field.php b/src/Field.php index 19d17465e3..38512059bd 100644 --- a/src/Field.php +++ b/src/Field.php @@ -421,7 +421,7 @@ public function getQueryArguments($operator, $value): array Scope\Condition::OPERATOR_NOT_REGEXP, ], true)) { $typecastField = new self(['type' => 'string']); - $typecastField->setOwner(new Model($this->getOwner()->persistence, ['table' => false])); + $typecastField->setOwner(new Model2($this->getOwner()->persistence, ['table' => false])); $typecastField->short_name = $this->short_name; $allowArray = false; } diff --git a/src/Model2.php b/src/Model2.php new file mode 100644 index 0000000000..af8be07340 --- /dev/null +++ b/src/Model2.php @@ -0,0 +1,9 @@ +foreign_table; }, null, Array_\Join::class)(); if (isset($this->seedData[$joinTableName])) { - $dummyJoinModel = new Model($this, ['table' => $joinTableName]); + $dummyJoinModel = new Model2($this, ['table' => $joinTableName]); $this->add($dummyJoinModel); } } diff --git a/src/Persistence/Sql/Join.php b/src/Persistence/Sql/Join.php index cf41e22bcb..b43a99dfb5 100644 --- a/src/Persistence/Sql/Join.php +++ b/src/Persistence/Sql/Join.php @@ -5,6 +5,7 @@ namespace Atk4\Data\Persistence\Sql; use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Persistence; /** @@ -147,7 +148,7 @@ public function beforeInsert(Model $entity, array &$data): void $query->setMulti($model->persistence->typecastSaveRow($model, $this->getAndUnsetSaveBuffer($entity))); // $query->set($this->foreign_field, null); $query->insert(); - $this->setId($entity, $model->persistence->lastInsertId(new Model($model->persistence, ['table' => $this->foreign_table]))); + $this->setId($entity, $model->persistence->lastInsertId(new Model2($model->persistence, ['table' => $this->foreign_table]))); if ($this->hasJoin()) { $this->getJoin()->setSaveBufferValue($entity, $this->master_field, $this->getId($entity)); diff --git a/tests/BusinessModelTest.php b/tests/BusinessModelTest.php index fc0507b458..9b7b74db11 100644 --- a/tests/BusinessModelTest.php +++ b/tests/BusinessModelTest.php @@ -7,7 +7,7 @@ use Atk4\Core\Phpunit\TestCase; use Atk4\Data\Exception; use Atk4\Data\Field; -use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Persistence; use Atk4\Data\Tests\Model\Client; use Atk4\Data\Tests\Model\User; @@ -16,7 +16,7 @@ class BusinessModelTest extends TestCase { public function testConstructFields(): void { - $m = new Model(); + $m = new Model2(); $m->addField('name'); $f = $m->getField('name'); @@ -29,7 +29,7 @@ public function testConstructFields(): void public function testFieldAccess(): void { - $m = new Model(); + $m = new Model2(); $m->addField('name'); $m->addField('surname'); $m = $m->createEntity(); @@ -46,7 +46,7 @@ public function testFieldAccess(): void public function testNoFieldException(): void { - $m = new Model(); + $m = new Model2(); $m = $m->createEntity(); $this->expectException(Exception::class); $m->set('name', 5); @@ -54,7 +54,7 @@ public function testNoFieldException(): void public function testDirty(): void { - $m = new Model(); + $m = new Model2(); $m->addField('name'); $m = $m->createEntity(); $dataRef = &$m->getDataRef(); @@ -107,7 +107,7 @@ public function testDirty(): void $this->assertSame([], $m->getDirtyRef()); // now with defaults - $m = new Model(); + $m = new Model2(); $f = $m->addField('name', ['default' => 'John']); $m = $m->createEntity(); $this->assertSame('John', $f->default); @@ -126,7 +126,7 @@ public function testDirty(): void public function testDefaultInit(): void { $p = new Persistence\Array_(); - $m = new Model($p); + $m = new Model2($p); $m = $m->createEntity(); $this->assertNotNull($m->getField('id')); @@ -137,7 +137,7 @@ public function testDefaultInit(): void public function testException1(): void { - $m = new Model(); + $m = new Model2(); $m->addField('name'); $m->addField('surname'); $m->setOnlyFields(['surname']); @@ -149,7 +149,7 @@ public function testException1(): void public function testException1Fixed(): void { - $m = new Model(); + $m = new Model2(); $m->addField('name'); $m->addField('surname'); $m->setOnlyFields(['surname']); @@ -163,7 +163,7 @@ public function testException1Fixed(): void public function testSetTitle(): void { - $m = new Model(); + $m = new Model2(); $m->addField('name'); $m = $m->createEntity(); $m->set('name', 'foo'); @@ -178,7 +178,7 @@ public function testSetTitle(): void */ public function testException2(): void { - $m = new Model(); + $m = new Model2(); $m = $m->createEntity(); $this->expectException(\Error::class); $m->set(0, 'foo'); // @phpstan-ignore-line @@ -186,7 +186,7 @@ public function testException2(): void public function testException2a(): void { - $m = new Model(); + $m = new Model2(); $m = $m->createEntity(); $this->expectException(Exception::class); $m->set('3', 'foo'); @@ -194,7 +194,7 @@ public function testException2a(): void public function testException2b(): void { - $m = new Model(); + $m = new Model2(); $m = $m->createEntity(); $this->expectException(Exception::class); $m->set('3b', 'foo'); @@ -202,7 +202,7 @@ public function testException2b(): void public function testException2c(): void { - $m = new Model(); + $m = new Model2(); $m = $m->createEntity(); $this->expectException(Exception::class); $m->set('', 'foo'); @@ -218,7 +218,7 @@ public function testClass1(): void public function testNormalize(): void { - $m = new Model(); + $m = new Model2(); $m->addField('name', ['type' => 'string']); $m->addField('age', ['type' => 'integer']); $m->addField('data'); diff --git a/tests/ConditionSqlTest.php b/tests/ConditionSqlTest.php index 885db78bce..32058b9679 100644 --- a/tests/ConditionSqlTest.php +++ b/tests/ConditionSqlTest.php @@ -5,6 +5,7 @@ namespace Atk4\Data\Tests; use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Schema\TestCase; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Platforms\SqlitePlatform; @@ -20,7 +21,7 @@ public function testBasic(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addFields(['name', 'gender']); $mm = $m->tryLoad(1); @@ -52,7 +53,7 @@ public function testBasic(): void public function testEntityNoScopeCloning(): void { - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $scope = $m->scope(); $this->assertSame($scope, $m->createEntity()->getModel()->scope()); $this->expectException(\Atk4\Data\Exception::class); @@ -68,13 +69,13 @@ public function testEntityReloadWithDifferentIdException(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addFields(['name', 'gender']); $m = $m->tryLoad(1); $this->assertSame('John', $m->get('name')); \Closure::bind(function () use ($m) { - $m->_entityId = 2; + $m->_entityId = null ?? 2; // @phpstan-ignore-line https://github.com/phpstan/phpstan-src/pull/706 }, null, Model::class)(); $this->expectException(\Atk4\Data\Exception::class); $this->expectExceptionMessageMatches('~entity.+different~'); @@ -92,7 +93,7 @@ public function testNull(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addFields(['name', 'gender']); $m->addCondition('gender', null); @@ -117,7 +118,7 @@ public function testOperations(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addFields(['name', 'gender']); $mm = $m->tryLoad(1); @@ -163,7 +164,7 @@ public function testExpressions1(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addFields(['name', 'gender']); $mm = $m->tryLoad(1); @@ -195,7 +196,7 @@ public function testExpressions2(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addFields(['name', 'gender', 'surname']); $mm = $m->tryLoad(1); @@ -245,7 +246,7 @@ public function testExpressionJoin(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addFields(['name', 'gender', 'surname']); $m->join('contact')->addField('contact_phone'); @@ -293,22 +294,22 @@ public function testArrayCondition(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addField('name'); $m->addCondition('name', ['John', 'Doe']); $this->assertCount(1, $m->export()); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addField('name'); $m->addCondition('name', 'in', ['Johhny', 'Doe', 'Mary']); $this->assertCount(2, $m->export()); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addField('name'); $m->addCondition('name', []); // this should not fail, always should be false $this->assertCount(0, $m->export()); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addField('name'); $m->addCondition('name', 'not in', []); // this should not fail, always should be true $this->assertCount(3, $m->export()); @@ -323,7 +324,7 @@ public function testDateCondition(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addField('name'); $m->addField('date', ['type' => 'date']); @@ -340,7 +341,7 @@ public function testDateCondition2(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addField('name'); $m->addField('date', ['type' => 'date']); @@ -358,7 +359,7 @@ public function testDateConditionFailure(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addField('name'); $m->addField('date', ['type' => 'date']); @@ -376,7 +377,7 @@ public function testOrConditions(): void ], ]); - $u = (new Model($this->db, ['table' => 'user']))->addFields(['name']); + $u = (new Model2($this->db, ['table' => 'user']))->addFields(['name']); $u->addCondition(Model\Scope::createOr( ['name', 'John'], @@ -406,7 +407,7 @@ public function testLoadBy(): void ], ]); - $u = (new Model($this->db, ['table' => 'user']))->addFields(['name']); + $u = (new Model2($this->db, ['table' => 'user']))->addFields(['name']); $u2 = $u->loadBy('name', 'John'); $this->assertSame(['id' => 1, 'name' => 'John'], $u2->get()); @@ -438,7 +439,7 @@ public function testLikeCondition(): void ], ]); - $u = new Model($this->db, ['table' => 'user']); + $u = new Model2($this->db, ['table' => 'user']); $u->addField('name', ['type' => 'string']); $u->addField('active', ['type' => 'boolean']); $u->addField('created', ['type' => 'datetime']); diff --git a/tests/ConditionTest.php b/tests/ConditionTest.php index bcadb2fee9..b901caff14 100644 --- a/tests/ConditionTest.php +++ b/tests/ConditionTest.php @@ -5,14 +5,14 @@ namespace Atk4\Data\Tests; use Atk4\Core\Phpunit\TestCase; -use Atk4\Data\Model; +use Atk4\Data\Model2; class ConditionTest extends TestCase { public function testException1(): void { // not existing field in condition - $m = new Model(); + $m = new Model2(); $m->addField('name'); $this->expectException(\Atk4\Core\Exception::class); @@ -21,7 +21,7 @@ public function testException1(): void public function testBasicDiscrimination(): void { - $m = new Model(); + $m = new Model2(); $m->addField('name'); $m->addField('gender', ['enum' => ['M', 'F']]); @@ -38,7 +38,7 @@ public function testBasicDiscrimination(): void public function testEditableAfterCondition(): void { - $m = new Model(); + $m = new Model2(); $m->addField('name'); $m->addField('gender'); @@ -50,10 +50,10 @@ public function testEditableAfterCondition(): void public function testEditableHasOne(): void { - $gender = new Model(); + $gender = new Model2(); $gender->addField('name'); - $m = new Model(); + $m = new Model2(); $m->addField('name'); $m->hasOne('gender_id', ['model' => $gender]); diff --git a/tests/ContainsMany/Discount.php b/tests/ContainsMany/Discount.php index 31469eb56f..5eaac08859 100644 --- a/tests/ContainsMany/Discount.php +++ b/tests/ContainsMany/Discount.php @@ -4,7 +4,7 @@ namespace Atk4\Data\Tests\ContainsMany; -use Atk4\Data\Model; +use Atk4\Data\Model2; /** * Each line can have multiple discounts. @@ -12,7 +12,7 @@ * @property int $percent @Atk4\Field() * @property \DateTime $valid_till @Atk4\Field() */ -class Discount extends Model +class Discount extends Model2 { protected function init(): void { diff --git a/tests/ContainsMany/Invoice.php b/tests/ContainsMany/Invoice.php index b029597905..12b8232adb 100644 --- a/tests/ContainsMany/Invoice.php +++ b/tests/ContainsMany/Invoice.php @@ -5,6 +5,7 @@ namespace Atk4\Data\Tests\ContainsMany; use Atk4\Data\Model; +use Atk4\Data\Model2; /** * Invoice model. @@ -15,7 +16,7 @@ * @property string $total_gross @Atk4\Field() * @property float $discounts_total_sum @Atk4\Field() */ -class Invoice extends Model +class Invoice extends Model2 { public $table = 'invoice'; diff --git a/tests/ContainsMany/Line.php b/tests/ContainsMany/Line.php index 7af084a297..4009d5c406 100644 --- a/tests/ContainsMany/Line.php +++ b/tests/ContainsMany/Line.php @@ -5,6 +5,7 @@ namespace Atk4\Data\Tests\ContainsMany; use Atk4\Data\Model; +use Atk4\Data\Model2; /** * Invoice lines model. @@ -17,7 +18,7 @@ * @property Discount $discounts @Atk4\RefMany() * @property float $discounts_percent @Atk4\Field() */ -class Line extends Model +class Line extends Model2 { protected function init(): void { diff --git a/tests/ContainsMany/VatRate.php b/tests/ContainsMany/VatRate.php index 239ed89efd..51a85d7954 100644 --- a/tests/ContainsMany/VatRate.php +++ b/tests/ContainsMany/VatRate.php @@ -5,6 +5,7 @@ namespace Atk4\Data\Tests\ContainsMany; use Atk4\Data\Model; +use Atk4\Data\Model2; /** * VAT rate model. @@ -12,7 +13,7 @@ * @property string $name @Atk4\Field() * @property int $rate @Atk4\Field() */ -class VatRate extends Model +class VatRate extends Model2 { public $table = 'vat_rate'; diff --git a/tests/ContainsOne/Address.php b/tests/ContainsOne/Address.php index 459ce42bc3..dde58fac97 100644 --- a/tests/ContainsOne/Address.php +++ b/tests/ContainsOne/Address.php @@ -5,6 +5,7 @@ namespace Atk4\Data\Tests\ContainsOne; use Atk4\Data\Model; +use Atk4\Data\Model2; /** * Address model. @@ -15,7 +16,7 @@ * @property string[] $tags @Atk4\Field() * @property DoorCode $door_code @Atk4\RefOne() */ -class Address extends Model +class Address extends Model2 { protected function init(): void { diff --git a/tests/ContainsOne/Country.php b/tests/ContainsOne/Country.php index b1b9db2eb7..29564abdf5 100644 --- a/tests/ContainsOne/Country.php +++ b/tests/ContainsOne/Country.php @@ -5,13 +5,14 @@ namespace Atk4\Data\Tests\ContainsOne; use Atk4\Data\Model; +use Atk4\Data\Model2; /** * Country model. * * @property string $name @Atk4\Field() */ -class Country extends Model +class Country extends Model2 { public $table = 'country'; diff --git a/tests/ContainsOne/DoorCode.php b/tests/ContainsOne/DoorCode.php index 5946c3b5c7..9bf99ca742 100644 --- a/tests/ContainsOne/DoorCode.php +++ b/tests/ContainsOne/DoorCode.php @@ -5,6 +5,7 @@ namespace Atk4\Data\Tests\ContainsOne; use Atk4\Data\Model; +use Atk4\Data\Model2; /** * DoorCode model. @@ -12,7 +13,7 @@ * @property string $code @Atk4\Field() * @property \DateTime $valid_till @Atk4\Field() */ -class DoorCode extends Model +class DoorCode extends Model2 { protected function init(): void { diff --git a/tests/ContainsOne/Invoice.php b/tests/ContainsOne/Invoice.php index c0b654cd4d..bccadb6c02 100644 --- a/tests/ContainsOne/Invoice.php +++ b/tests/ContainsOne/Invoice.php @@ -5,6 +5,7 @@ namespace Atk4\Data\Tests\ContainsOne; use Atk4\Data\Model; +use Atk4\Data\Model2; /** * Invoice model. @@ -12,7 +13,7 @@ * @property string $ref_no @Atk4\Field() * @property Address $addr @Atk4\RefOne() */ -class Invoice extends Model +class Invoice extends Model2 { public $table = 'invoice'; diff --git a/tests/DefaultTest.php b/tests/DefaultTest.php index 2fa1ab2df8..86b0bc2d7a 100644 --- a/tests/DefaultTest.php +++ b/tests/DefaultTest.php @@ -4,14 +4,14 @@ namespace Atk4\Data\Tests; -use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Schema\TestCase; class DefaultTest extends TestCase { public function testDefaultValue(): void { - $m = new Model(); + $m = new Model2(); $m->addField('nodefault'); $m->addField('withdefault', ['default' => 'abc']); $m = $m->createEntity(); diff --git a/tests/ExpressionSqlTest.php b/tests/ExpressionSqlTest.php index 95b02ff34c..0575500c6d 100644 --- a/tests/ExpressionSqlTest.php +++ b/tests/ExpressionSqlTest.php @@ -4,7 +4,7 @@ namespace Atk4\Data\Tests; -use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Schema\TestCase; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Platforms\SqlitePlatform; @@ -14,7 +14,7 @@ class ExpressionSqlTest extends TestCase { public function testNakedExpression(): void { - $m = new Model($this->db, ['table' => false]); + $m = new Model2($this->db, ['table' => false]); $m->addExpression('x', '2+3'); $m = $m->loadOne(); $this->assertEquals(5, $m->get('x')); @@ -29,7 +29,7 @@ public function testBasic(): void ], ]); - $i = (new Model($this->db, ['table' => 'invoice']))->addFields(['total_net', 'total_vat']); + $i = (new Model2($this->db, ['table' => 'invoice']))->addFields(['total_net', 'total_vat']); $i->addExpression('total_gross', '[total_net]+[total_vat]'); if ($this->getDatabasePlatform() instanceof SqlitePlatform) { @@ -69,7 +69,7 @@ public function testBasicCallback(): void ], ]); - $i = (new Model($this->db, ['table' => 'invoice']))->addFields(['total_net', 'total_vat']); + $i = (new Model2($this->db, ['table' => 'invoice']))->addFields(['total_net', 'total_vat']); $i->addExpression('total_gross', function ($i, $q) { return '[total_net]+[total_vat]'; }); @@ -99,7 +99,7 @@ public function testQuery(): void ], ]); - $i = (new Model($this->db, ['table' => 'invoice']))->addFields(['total_net', 'total_vat']); + $i = (new Model2($this->db, ['table' => 'invoice']))->addFields(['total_net', 'total_vat']); $i->addExpression('sum_net', $i->action('fx', ['sum', 'total_net'])); if ($this->getDatabasePlatform() instanceof SqlitePlatform) { @@ -131,7 +131,7 @@ public function testExpressions(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addFields(['name', 'surname', 'cached_name']); if ($this->getDatabasePlatform() instanceof SqlitePlatform) { @@ -169,7 +169,7 @@ public function testReloading(): void ], ]); - $m = new Model($this->db, ['table' => 'math']); + $m = new Model2($this->db, ['table' => 'math']); $m->addFields(['a', 'b']); $m->addExpression('sum', '[a] + [b]'); @@ -183,7 +183,7 @@ public function testReloading(): void $this->assertEquals(9, $m->createEntity()->save(['a' => 4, 'b' => 5])->get('sum')); $this->setDb($dbData); - $m = new Model($this->db, ['table' => 'math', 'reload_after_save' => false]); + $m = new Model2($this->db, ['table' => 'math', 'reload_after_save' => false]); $m->addFields(['a', 'b']); $m->addExpression('sum', '[a] + [b]'); @@ -199,7 +199,7 @@ public function testReloading(): void public function testExpressionActionAlias(): void { - $m = new Model($this->db, ['table' => false]); + $m = new Model2($this->db, ['table' => false]); $m->addExpression('x', '2+3'); // use alias as array key if it is set @@ -232,7 +232,7 @@ public function testNeverSaveNeverPersist(): void ], ]); - $i = new Model($this->db, ['table' => 'invoice']); + $i = new Model2($this->db, ['table' => 'invoice']); $i->addExpression('zero_basic', [$i->expr('0'), 'type' => 'integer', 'system' => true]); $i->addExpression('zero_never_save', [$i->expr('0'), 'type' => 'integer', 'system' => true, 'never_save' => true]); diff --git a/tests/Field/EmailFieldTest.php b/tests/Field/EmailFieldTest.php index afe4fed6d6..3b85a962f7 100644 --- a/tests/Field/EmailFieldTest.php +++ b/tests/Field/EmailFieldTest.php @@ -5,7 +5,7 @@ namespace Atk4\Data\Tests\Field; use Atk4\Data\Field\EmailField; -use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Schema\TestCase; use Atk4\Data\ValidationException; @@ -13,7 +13,7 @@ class EmailFieldTest extends TestCase { public function testEmailFieldBasic(): void { - $m = new Model(); + $m = new Model2(); $m->addField('email', [EmailField::class]); $entity = $m->createEntity(); @@ -39,7 +39,7 @@ public function testEmailFieldBasic(): void public function testEmailValidateDns(): void { - $m = new Model(); + $m = new Model2(); $m->addField('email', [EmailField::class, 'dns_check' => true]); $m->addField('email_idn', [EmailField::class, 'dns_check' => true]); $entity = $m->createEntity(); @@ -56,7 +56,7 @@ public function testEmailValidateDns(): void public function testEmailWithName(): void { - $m = new Model(); + $m = new Model2(); $m->addField('email', [EmailField::class]); $m->addField('email_name', [EmailField::class, 'allow_name' => true]); $entity = $m->createEntity(); @@ -71,7 +71,7 @@ public function testEmailWithName(): void public function testEmailMultipleException(): void { - $m = new Model(); + $m = new Model2(); $m->addField('email', [EmailField::class]); $entity = $m->createEntity(); diff --git a/tests/Field/PasswordFieldTest.php b/tests/Field/PasswordFieldTest.php index 1531ebb4f2..a7e276c4fb 100644 --- a/tests/Field/PasswordFieldTest.php +++ b/tests/Field/PasswordFieldTest.php @@ -6,14 +6,14 @@ use Atk4\Data\Exception; use Atk4\Data\Field\PasswordField; -use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Schema\TestCase; class PasswordFieldTest extends TestCase { public function testPasswordFieldBasic(): void { - $m = new Model(); + $m = new Model2(); $m->addField('p', [PasswordField::class]); $field = PasswordField::assertInstanceOf($m->getField('p')); $entity = $m->createEntity(); @@ -82,7 +82,7 @@ public function testInvalidPasswordCntrlChar(): void public function testSetUnhashedException(): void { - $m = new Model(); + $m = new Model2(); $m->addField('p', [PasswordField::class]); $field = PasswordField::assertInstanceOf($m->getField('p')); $entity = $m->createEntity(); @@ -93,7 +93,7 @@ public function testSetUnhashedException(): void public function testEmptyCompareException(): void { - $m = new Model(); + $m = new Model2(); $m->addField('p', [PasswordField::class]); $field = PasswordField::assertInstanceOf($m->getField('p')); $entity = $m->createEntity(); diff --git a/tests/FieldTest.php b/tests/FieldTest.php index 83bf076594..5fe92b29cb 100644 --- a/tests/FieldTest.php +++ b/tests/FieldTest.php @@ -7,6 +7,7 @@ use Atk4\Data\Exception; use Atk4\Data\Field; use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Schema\TestCase; use Atk4\Data\ValidationException; @@ -14,7 +15,7 @@ class FieldTest extends TestCase { public function testDirty1(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['default' => 'abc']); $m = $m->createEntity(); @@ -45,7 +46,7 @@ public function testDirty1(): void public function testCompare(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['default' => 'abc']); $m = $m->createEntity(); @@ -58,7 +59,7 @@ public function testCompare(): void public function testMandatory1(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['mandatory' => true]); $m = $m->createEntity(); $m->set('foo', 'abc'); @@ -70,7 +71,7 @@ public function testMandatory1(): void public function testRequired1(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['required' => true]); $m = $m->createEntity(); @@ -80,7 +81,7 @@ public function testRequired1(): void public function testRequired11(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['required' => true]); $m = $m->createEntity(); @@ -96,7 +97,7 @@ public function testMandatory2(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addField('name', ['mandatory' => true]); $m->addField('surname'); $this->expectException(Exception::class); @@ -111,7 +112,7 @@ public function testRequired2(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addField('name', ['required' => true]); $m->addField('surname'); $this->expectException(Exception::class); @@ -126,7 +127,7 @@ public function testMandatory3(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addField('name', ['mandatory' => true]); $m->addField('surname'); $m = $m->load(1); @@ -142,7 +143,7 @@ public function testMandatory4(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addField('name', ['mandatory' => true, 'default' => 'NoName']); $m->addField('surname'); $m->insert(['surname' => 'qq']); @@ -156,7 +157,7 @@ public function testMandatory4(): void public function testCaption(): void { - $m = new Model(); + $m = new Model2(); $f = $m->addField('foo'); $this->assertSame('Foo', $f->getCaption()); @@ -181,7 +182,7 @@ public function testCaption(): void public function testReadOnly1(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['read_only' => true]); $m = $m->createEntity(); $this->expectException(Exception::class); @@ -190,7 +191,7 @@ public function testReadOnly1(): void public function testReadOnly2(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['read_only' => true, 'default' => 'abc']); $m = $m->createEntity(); $m->set('foo', 'abc'); @@ -199,7 +200,7 @@ public function testReadOnly2(): void public function testEnum1(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['enum' => ['foo', 'bar']]); $m = $m->createEntity(); $this->expectException(Exception::class); @@ -208,7 +209,7 @@ public function testEnum1(): void public function testEnum2(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['enum' => ['1', 'bar']]); $m = $m->createEntity(); $m->set('foo', '1'); @@ -221,7 +222,7 @@ public function testEnum2(): void public function testEnum2b(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['type' => 'integer', 'enum' => [1, 2]]); $m = $m->createEntity(); $m->set('foo', 1); @@ -234,7 +235,7 @@ public function testEnum2b(): void public function testEnum3(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['enum' => [1, 'bar']]); $m = $m->createEntity(); $this->expectException(Exception::class); @@ -246,7 +247,7 @@ public function testEnum4(): void // PHP type control is really crappy... // This test has no purpose but it stands testament // to a weird behaviours of PHP - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['enum' => [1, 'bar'], 'default' => 1]); $m = $m->createEntity(); $m->setNull('foo'); @@ -256,7 +257,7 @@ public function testEnum4(): void public function testValues1(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['values' => ['foo', 'bar']]); $m = $m->createEntity(); $this->expectException(Exception::class); @@ -265,7 +266,7 @@ public function testValues1(): void public function testValues2(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['type' => 'integer', 'values' => [3 => 'bar']]); $m = $m->createEntity(); $m->set('foo', 3); @@ -278,7 +279,7 @@ public function testValues2(): void public function testValues3(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['values' => [1 => 'bar']]); $m = $m->createEntity(); $this->expectException(Exception::class); @@ -290,7 +291,7 @@ public function testValues4(): void // PHP type control is really crappy... // This test has no purpose but it stands testament // to a weird behaviours of PHP - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['values' => ['1a' => 'bar']]); $m = $m->createEntity(); $m->set('foo', '1a'); @@ -305,7 +306,7 @@ public function testNeverPersist(): void ], ]); - $m = new Model($this->db, ['table' => 'item']); + $m = new Model2($this->db, ['table' => 'item']); $m->addField('name', ['never_persist' => true]); $m->addField('surname', ['never_save' => true]); $m = $m->load(1); @@ -366,10 +367,10 @@ public function testTitle(): void ], ]); - $c = new Model($this->db, ['table' => 'category']); + $c = new Model2($this->db, ['table' => 'category']); $c->addField('name'); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addField('name'); $m->hasOne('category_id', ['model' => $c]) ->addTitle(); @@ -396,7 +397,7 @@ public function testTitle(): void public function testNonExisitngField(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo'); $m = $m->createEntity(); $this->expectException(Exception::class); @@ -411,7 +412,7 @@ public function testActual(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addField('first_name', ['actual' => 'name']); $m->addField('surname'); $m->insert(['first_name' => 'Peter', 'surname' => 'qq']); @@ -448,7 +449,7 @@ public function testCalculatedField(): void ], ]); - $m = new Model($this->db, ['table' => 'invoice']); + $m = new Model2($this->db, ['table' => 'invoice']); $m->addField('net', ['type' => 'atk4_money']); $m->addField('vat', ['type' => 'atk4_money']); $m->addCalculatedField('total', function ($m) { @@ -467,7 +468,7 @@ public function testCalculatedField(): void public function testSystem1(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['system' => true]); $m->addField('bar'); $this->assertFalse($m->getField('foo')->isEditable()); @@ -483,7 +484,7 @@ public function testNormalize(): void $this->assertSame('test', (new Field(['type' => 'string']))->normalize('test')); $this->assertSame('test', (new Field(['type' => 'string']))->normalize('test ')); - $m = new Model(); + $m = new Model2(); $m->addField('string', ['type' => 'string']); $m->addField('text', ['type' => 'text']); @@ -537,7 +538,7 @@ public function testNormalize(): void public function testNormalizeException1(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['type' => 'string']); $m = $m->createEntity(); $this->expectException(ValidationException::class); @@ -546,7 +547,7 @@ public function testNormalizeException1(): void public function testNormalizeException2(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['type' => 'text']); $m = $m->createEntity(); $this->expectException(ValidationException::class); @@ -555,7 +556,7 @@ public function testNormalizeException2(): void public function testNormalizeException3(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['type' => 'integer']); $m = $m->createEntity(); $this->expectException(ValidationException::class); @@ -564,7 +565,7 @@ public function testNormalizeException3(): void public function testNormalizeException4(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['type' => 'atk4_money']); $m = $m->createEntity(); $this->expectException(ValidationException::class); @@ -573,7 +574,7 @@ public function testNormalizeException4(): void public function testNormalizeException5(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['type' => 'float']); $m = $m->createEntity(); $this->expectException(ValidationException::class); @@ -582,7 +583,7 @@ public function testNormalizeException5(): void public function testNormalizeException6(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['type' => 'date']); $m = $m->createEntity(); $this->expectException(ValidationException::class); @@ -591,7 +592,7 @@ public function testNormalizeException6(): void public function testNormalizeException7(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['type' => 'datetime']); $m = $m->createEntity(); $this->expectException(ValidationException::class); @@ -600,7 +601,7 @@ public function testNormalizeException7(): void public function testNormalizeException8(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['type' => 'time']); $m = $m->createEntity(); $this->expectException(ValidationException::class); @@ -609,7 +610,7 @@ public function testNormalizeException8(): void public function testNormalizeException9(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['type' => 'integer']); $m = $m->createEntity(); $this->expectException(ValidationException::class); @@ -618,7 +619,7 @@ public function testNormalizeException9(): void public function testNormalizeException10(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['type' => 'atk4_money']); $m = $m->createEntity(); $this->expectException(ValidationException::class); @@ -627,7 +628,7 @@ public function testNormalizeException10(): void public function testNormalizeException11(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['type' => 'float']); $m = $m->createEntity(); $this->expectException(ValidationException::class); @@ -636,7 +637,7 @@ public function testNormalizeException11(): void public function testNormalizeException12(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['type' => 'json']); $m = $m->createEntity(); $this->expectException(ValidationException::class); @@ -645,7 +646,7 @@ public function testNormalizeException12(): void public function testNormalizeException13(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['type' => 'object']); $m = $m->createEntity(); $this->expectException(ValidationException::class); @@ -654,7 +655,7 @@ public function testNormalizeException13(): void public function testNormalizeException14(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo', ['type' => 'boolean']); $m = $m->createEntity(); $this->expectException(ValidationException::class); @@ -663,7 +664,7 @@ public function testNormalizeException14(): void public function testToString(): void { - $m = new Model(); + $m = new Model2(); $m->addField('string', ['type' => 'string']); $m->addField('text', ['type' => 'text']); @@ -695,13 +696,13 @@ public function testToString(): void public function testAddFieldDirectly(): void { $this->expectException(Exception::class); - $model = new Model(); + $model = new Model2(); $model->add(new Field(), ['test']); } public function testGetFields(): void { - $model = new Model(); + $model = new Model2(); $model->addField('system', ['system' => true]); $model->addField('editable', ['ui' => ['editable' => true]]); $model->addField('editable_system', ['ui' => ['editable' => true], 'system' => true]); @@ -731,7 +732,7 @@ public function testGetFields(): void public function testDateTimeFieldsToString(): void { - $model = new Model(); + $model = new Model2(); $model->addField('date', ['type' => 'date']); $model->addField('time', ['type' => 'time']); $model->addField('datetime', ['type' => 'datetime']); @@ -764,7 +765,7 @@ public function testDateTimeFieldsToString(): void public function testSetNull(): void { - $m = new Model(); + $m = new Model2(); $m->addField('a'); $m->addField('b', ['mandatory' => true]); $m->addField('c', ['required' => true]); @@ -799,7 +800,7 @@ public function testSetNull(): void public function testEntityFieldPair(): void { - $m = new Model(); + $m = new Model2(); $m->addField('foo'); $m->addField('bar', ['mandatory' => true]); @@ -832,7 +833,7 @@ public function testEntityFieldPair(): void public function testBoolean(): void { - $m = new Model(); + $m = new Model2(); $m->addField('is_vip', ['type' => 'boolean']); $m = $m->createEntity(); diff --git a/tests/FolderTest.php b/tests/FolderTest.php index ae6652ced4..a1a1973df3 100644 --- a/tests/FolderTest.php +++ b/tests/FolderTest.php @@ -4,10 +4,10 @@ namespace Atk4\Data\Tests; -use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Schema\TestCase; -class Folder extends Model +class Folder extends Model2 { public $table = 'folder'; diff --git a/tests/IteratorTest.php b/tests/IteratorTest.php index 13a69d80f2..1b5b74dba4 100644 --- a/tests/IteratorTest.php +++ b/tests/IteratorTest.php @@ -6,6 +6,7 @@ use Atk4\Data\Exception; use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Schema\TestCase; class IteratorTest extends TestCase @@ -15,7 +16,7 @@ class IteratorTest extends TestCase */ public function testException1(): void { - $m = new Model(); + $m = new Model2(); $m->addFields(['name', 'salary']); $this->expectException(Exception::class); $m->setOrder(['name', 'salary'], 'desc'); @@ -26,7 +27,7 @@ public function testException1(): void */ public function testException2(): void { - $m = new Model(); + $m = new Model2(); $this->expectException(Exception::class); $m = $m->tryLoad(1); } @@ -36,7 +37,7 @@ public function testException2(): void */ public function testException3(): void { - $m = new Model(); + $m = new Model2(); $this->expectException(Exception::class); $m = $m->tryLoadAny(); } @@ -46,7 +47,7 @@ public function testException3(): void */ public function testException4(): void { - $m = new Model(); + $m = new Model2(); $this->expectException(Exception::class); $m = $m->load(1); } @@ -56,7 +57,7 @@ public function testException4(): void */ public function testException5(): void { - $m = new Model(); + $m = new Model2(); $this->expectException(Exception::class); $m = $m->loadAny(); } @@ -66,7 +67,7 @@ public function testException5(): void */ public function testException6(): void { - $m = new Model(); + $m = new Model2(); $this->expectException(Exception::class); $m->save(); } @@ -76,7 +77,7 @@ public function testException6(): void */ public function testException7(): void { - $m = new Model(); + $m = new Model2(); $this->expectException(Exception::class); $m->action('insert'); } @@ -91,7 +92,7 @@ public function testBasic(): void ], ]); - $i = (new Model($this->db, ['table' => 'invoice']))->addFields(['total_net', 'total_vat']); + $i = (new Model2($this->db, ['table' => 'invoice']))->addFields(['total_net', 'total_vat']); $i->addExpression('total_gross', '[total_net]+[total_vat]'); $i->setOrder('total_net'); @@ -134,7 +135,7 @@ public function testRawIterator(): void ], ]); - $i = (new Model($this->db, ['table' => 'invoice']))->addFields(['total_net', 'total_vat']); + $i = (new Model2($this->db, ['table' => 'invoice']))->addFields(['total_net', 'total_vat']); $i->addExpression('total_gross', '[total_net]+[total_vat]'); $i->setOrder('total_net'); @@ -177,7 +178,7 @@ public function testBasicId(): void ], ]); - $i = (new Model($this->db, ['table' => 'invoice']))->addFields(['total_net', 'total_vat']); + $i = (new Model2($this->db, ['table' => 'invoice']))->addFields(['total_net', 'total_vat']); $i->addExpression('total_gross', '[total_net]+[total_vat]'); $i->setOrder('total_net'); diff --git a/tests/JoinArrayTest.php b/tests/JoinArrayTest.php index bf8ef27c2a..3aa3410b22 100644 --- a/tests/JoinArrayTest.php +++ b/tests/JoinArrayTest.php @@ -6,7 +6,7 @@ use Atk4\Core\Phpunit\TestCase; use Atk4\Data\Exception; -use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Persistence; class JoinArrayTest extends TestCase @@ -30,7 +30,7 @@ private function getInternalPersistenceData(Persistence\Array_ $db): array public function testDirection(): void { $db = new Persistence\Array_(['user' => [], 'contact' => []]); - $m = new Model($db, ['table' => 'user']); + $m = new Model2($db, ['table' => 'user']); $j = $m->join('contact'); $this->assertFalse($this->getProtected($j, 'reverse')); @@ -57,7 +57,7 @@ public function testDirection(): void public function testJoinException(): void { $db = new Persistence\Array_(['user' => [], 'contact' => []]); - $m = new Model($db, ['table' => 'user']); + $m = new Model2($db, ['table' => 'user']); $this->expectException(Exception::class); $j = $m->join('contact.foo_id', ['master_field' => 'test_id']); @@ -66,7 +66,7 @@ public function testJoinException(): void public function testJoinSaving1(): void { $db = new Persistence\Array_(['user' => [], 'contact' => []]); - $m_u = new Model($db, ['table' => 'user']); + $m_u = new Model2($db, ['table' => 'user']); $m_u->addField('contact_id', ['type' => 'integer']); $m_u->addField('name'); $j = $m_u->join('contact'); @@ -118,7 +118,7 @@ public function testJoinSaving1(): void public function testJoinSaving2(): void { $db = new Persistence\Array_(['user' => [], 'contact' => []]); - $m_u = new Model($db, ['table' => 'user']); + $m_u = new Model2($db, ['table' => 'user']); $m_u->addField('name'); $j = $m_u->join('contact.test_id'); $j->addField('contact_phone'); @@ -148,7 +148,7 @@ public function testJoinSaving2(): void ], ], $this->getInternalPersistenceData($db)); - $m_c = new Model($db, ['table' => 'contact']); + $m_c = new Model2($db, ['table' => 'contact']); $m_c = $m_c->load(2); $m_c->delete(); @@ -172,7 +172,7 @@ public function testJoinSaving2(): void public function testJoinSaving3(): void { $db = new Persistence\Array_(['user' => [], 'contact' => []]); - $m_u = new Model($db, ['table' => 'user']); + $m_u = new Model2($db, ['table' => 'user']); $m_u->addField('name'); $m_u->addField('test_id', ['type' => 'integer']); $j = $m_u->join('contact', ['master_field' => 'test_id']); @@ -193,7 +193,7 @@ public function testJoinSaving3(): void /*public function testJoinSaving4(): void { $db = new Persistence\Array_(['user' => [], 'contact' => []]); - $m_u = new Model($db, ['table' => 'user']); + $m_u = new Model2($db, ['table' => 'user']); $m_u->addField('name'); $m_u->addField('code'); $j = $m_u->join('contact.code', ['master_field' => 'code']); @@ -224,7 +224,7 @@ public function testJoinLoading(): void 2 => ['contact_phone' => '+321'], ], ]); - $m_u = new Model($db, ['table' => 'user']); + $m_u = new Model2($db, ['table' => 'user']); $m_u->addField('contact_id', ['type' => 'integer']); $m_u->addField('name'); $j = $m_u->join('contact'); @@ -258,7 +258,7 @@ public function testJoinUpdate(): void 2 => ['contact_phone' => '+321'], ], ]); - $m_u = new Model($db, ['table' => 'user']); + $m_u = new Model2($db, ['table' => 'user']); $m_u->addField('contact_id', ['type' => 'integer']); $m_u->addField('name'); $j = $m_u->join('contact'); @@ -329,7 +329,7 @@ public function testJoinDelete(): void 3 => ['contact_phone' => '+777'], ], ]); - $m_u = new Model($db, ['table' => 'user']); + $m_u = new Model2($db, ['table' => 'user']); $m_u->addField('contact_id', ['type' => 'integer']); $m_u->addField('name'); $j = $m_u->join('contact'); @@ -362,7 +362,7 @@ public function testLoadMissing(): void 3 => ['contact_phone' => '+777'], ], ]); - $m_u = new Model($db, ['table' => 'user']); + $m_u = new Model2($db, ['table' => 'user']); $m_u->addField('contact_id', ['type' => 'integer']); $m_u->addField('name'); $j = $m_u->join('contact'); @@ -375,7 +375,7 @@ public function testLoadMissing(): void public function testTrickyCases(): void { $db = new Persistence\Array_(); - $m = new Model($db); + $m = new Model2($db); // tricky cases to testt // diff --git a/tests/JoinSqlTest.php b/tests/JoinSqlTest.php index 8e57db711f..561a4e5b5f 100644 --- a/tests/JoinSqlTest.php +++ b/tests/JoinSqlTest.php @@ -6,13 +6,14 @@ use Atk4\Data\Exception; use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Schema\TestCase; class JoinSqlTest extends TestCase { public function testDirection(): void { - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $j = $m->join('contact'); $this->assertFalse($this->getProtected($j, 'reverse')); @@ -38,7 +39,7 @@ public function testDirection(): void public function testDirectionException(): void { - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $this->expectException(Exception::class); $j = $m->join('contact.foo_id', ['master_field' => 'test_id']); @@ -46,7 +47,7 @@ public function testDirectionException(): void public function testJoinSaving1(): void { - $m_u = new Model($this->db, ['table' => 'user']); + $m_u = new Model2($this->db, ['table' => 'user']); $this->setDb([ 'user' => [ '_' => ['id' => 1, 'name' => 'John', 'contact_id' => 1], @@ -89,7 +90,7 @@ public function testJoinSaving1(): void public function testJoinSaving2(): void { - $m_u = new Model($this->db, ['table' => 'user']); + $m_u = new Model2($this->db, ['table' => 'user']); $this->setDb([ 'user' => [ '_' => ['id' => 1, 'name' => 'John'], @@ -146,7 +147,7 @@ public function testJoinSaving2(): void public function testJoinSaving3(): void { - $m_u = new Model($this->db, ['table' => 'user']); + $m_u = new Model2($this->db, ['table' => 'user']); $this->setDb([ 'user' => [ '_' => ['id' => 1, 'name' => 'John', 'test_id' => 0], @@ -184,7 +185,7 @@ public function testJoinLoading(): void ], ]); - $m_u = new Model($this->db, ['table' => 'user']); + $m_u = new Model2($this->db, ['table' => 'user']); $m_u->addField('name'); $j = $m_u->join('contact'); $j->addField('contact_phone'); @@ -218,7 +219,7 @@ public function testJoinUpdate(): void ], ]); - $m_u = new Model($this->db, ['table' => 'user']); + $m_u = new Model2($this->db, ['table' => 'user']); $m_u->addField('contact_id'); $m_u->addField('name'); $j = $m_u->join('contact'); @@ -318,7 +319,7 @@ public function testJoinDelete(): void ], ]); - $m_u = new Model($this->db, ['table' => 'user']); + $m_u = new Model2($this->db, ['table' => 'user']); $m_u->addField('contact_id'); $m_u->addField('name'); $j = $m_u->join('contact'); @@ -344,7 +345,7 @@ public function testJoinDelete(): void public function testDoubleSaveHook(): void { - $m_u = new Model($this->db, ['table' => 'user']); + $m_u = new Model2($this->db, ['table' => 'user']); $this->setDb([ 'user' => [ '_' => ['id' => 1, 'name' => 'John'], @@ -391,7 +392,7 @@ public function testDoubleJoin(): void ], ]); - $m_u = new Model($this->db, ['table' => 'user']); + $m_u = new Model2($this->db, ['table' => 'user']); $m_u->addField('contact_id'); $m_u->addField('name'); $j_contact = $m_u->join('contact'); @@ -454,7 +455,7 @@ public function testDoubleReverseJoin(): void ], ]); - $m_u = new Model($this->db, ['table' => 'user']); + $m_u = new Model2($this->db, ['table' => 'user']); $m_u->addField('contact_id'); $m_u->addField('name'); $j = $m_u->join('contact'); @@ -513,7 +514,7 @@ public function testJoinHasOneHasMany(): void ]); // main user model joined to contact table - $m_u = new Model($this->db, ['table' => 'user']); + $m_u = new Model2($this->db, ['table' => 'user']); $m_u->addField('contact_id'); $m_u->addField('name'); $j = $m_u->join('contact'); @@ -524,7 +525,7 @@ public function testJoinHasOneHasMany(): void ], $m_u2->get()); // hasOne phone model - $m_p = new Model($this->db, ['table' => 'phone']); + $m_p = new Model2($this->db, ['table' => 'phone']); $m_p->addField('number'); $ref_one = $j->hasOne('phone_id', ['model' => $m_p]); // hasOne on JOIN $ref_one->addField('number'); @@ -535,7 +536,7 @@ public function testJoinHasOneHasMany(): void ], $m_u2->get()); // hasMany token model (uses default our_field, their_field) - $m_t = new Model($this->db, ['table' => 'token']); + $m_t = new Model2($this->db, ['table' => 'token']); $m_t->addField('user_id'); $m_t->addField('token'); $ref_many = $j->hasMany('Token', ['model' => $m_t]); // hasMany on JOIN (use default our_field, their_field) @@ -547,7 +548,7 @@ public function testJoinHasOneHasMany(): void ], $m_u2->ref('Token')->export()); // hasMany email model (uses custom our_field, their_field) - $m_e = new Model($this->db, ['table' => 'email']); + $m_e = new Model2($this->db, ['table' => 'email']); $m_e->addField('contact_id'); $m_e->addField('address'); $ref_many = $j->hasMany('Email', ['model' => $m_e, 'our_field' => 'contact_id', 'their_field' => 'contact_id']); // hasMany on JOIN (use custom our_field, their_field) @@ -571,7 +572,7 @@ public function testJoinReverseOneOnOne(): void ], ]); - $m_user = new Model($this->db, ['table' => 'user']); + $m_user = new Model2($this->db, ['table' => 'user']); $m_user->addField('name'); $j = $m_user->join('detail.my_user_id', [ //'reverse' => true, // this will be reverse join by default @@ -599,7 +600,7 @@ public function testJoinReverseOneOnOne(): void $this->assertEquals(['id' => 21, 'name' => 'Emily', 'notes' => '3rd note'], $m->get()); // now test reverse join defined differently - $m_user = new Model($this->db, ['table' => 'user']); + $m_user = new Model2($this->db, ['table' => 'user']); $m_user->addField('name'); $j = $m_user->join('detail', [ // here we just set foreign table name without dot and foreign_field 'reverse' => true, // and set it as revers join @@ -614,7 +615,7 @@ public function testJoinReverseOneOnOne(): void $this->assertEquals(['id' => 22, 'name' => 'Olaf', 'notes' => '4th note'], $m->get()); // now test reverse join with table_alias and foreign_alias - $m_user = new Model($this->db, ['table' => 'user', 'table_alias' => 'u']); + $m_user = new Model2($this->db, ['table' => 'user', 'table_alias' => 'u']); $m_user->addField('name'); $j = $m_user->join('detail', [ 'reverse' => true, @@ -646,7 +647,7 @@ public function testJoinActualFieldNamesAndPrefix(): void ], ]); - $m_u = new Model($this->db, ['table' => 'user']); + $m_u = new Model2($this->db, ['table' => 'user']); $m_u->addField('contact_id', ['actual' => 'cid']); $m_u->addField('name', ['actual' => 'first_name']); // normal join diff --git a/tests/LimitOrderTest.php b/tests/LimitOrderTest.php index 53db343054..0168d522a8 100644 --- a/tests/LimitOrderTest.php +++ b/tests/LimitOrderTest.php @@ -6,6 +6,7 @@ use Atk4\Data\Exception; use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Schema\TestCase; class LimitOrderTest extends TestCase @@ -20,7 +21,7 @@ public function testBasic(): void ], ]); - $i = (new Model($this->db, ['table' => 'invoice']))->addFields(['total_net', 'total_vat']); + $i = (new Model2($this->db, ['table' => 'invoice']))->addFields(['total_net', 'total_vat']); $i->addExpression('total_gross', '[total_net]+[total_vat]'); $i->getField($i->id_field)->system = false; $i->id_field = null; @@ -44,7 +45,7 @@ public function testReverse(): void ], ]); - $ii = (new Model($this->db, ['table' => 'invoice']))->addFields(['total_net', 'total_vat']); + $ii = (new Model2($this->db, ['table' => 'invoice']))->addFields(['total_net', 'total_vat']); $ii->addExpression('total_gross', '[total_net]+[total_vat]'); $ii->getField($ii->id_field)->system = false; $ii->id_field = null; @@ -96,7 +97,7 @@ public function testArrayParameters(): void ], ]); - $ii = (new Model($this->db, ['table' => 'invoice']))->addFields(['net', 'vat']); + $ii = (new Model2($this->db, ['table' => 'invoice']))->addFields(['net', 'vat']); $ii->getField($ii->id_field)->system = false; $ii->id_field = null; @@ -142,7 +143,7 @@ public function testOrderByExpressions(): void ]); // order by expression field - $i = (new Model($this->db, ['table' => 'invoice']))->addFields(['code', 'net', 'vat']); + $i = (new Model2($this->db, ['table' => 'invoice']))->addFields(['code', 'net', 'vat']); $i->addExpression('gross', '[net]+[vat]'); $i->getField($i->id_field)->system = false; $i->id_field = null; @@ -207,7 +208,7 @@ public function testExceptionUnsupportedOrderParam(): void ], ]); - $i = (new Model($this->db, ['table' => 'invoice']))->addFields(['net']); + $i = (new Model2($this->db, ['table' => 'invoice']))->addFields(['net']); $i->setOrder(new \DateTime()); // @phpstan-ignore-line $this->expectException(Exception::class); $i->export(); // executes query and throws exception because of DateTime object @@ -223,7 +224,7 @@ public function testLimit(): void ], ]); - $i = (new Model($this->db, ['table' => 'invoice']))->addFields(['total_net', 'total_vat']); + $i = (new Model2($this->db, ['table' => 'invoice']))->addFields(['total_net', 'total_vat']); $i->addExpression('total_gross', '[total_net]+[total_vat]'); $i->getField($i->id_field)->system = false; $i->id_field = null; diff --git a/tests/LookupSqlTest.php b/tests/LookupSqlTest.php index db168676e2..d395eafb3a 100644 --- a/tests/LookupSqlTest.php +++ b/tests/LookupSqlTest.php @@ -5,6 +5,7 @@ namespace Atk4\Data\Tests; use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Schema\TestCase; /** @@ -20,7 +21,7 @@ * We also introduced 'user_names' field, which will concatenate all user names for said country. It can also be * used when importing, simply provide a comma-separated string of user names and they will be CREATED for you. */ -class LCountry extends Model +class LCountry extends Model2 { public $table = 'country'; @@ -56,7 +57,7 @@ protected function init(): void * * Like before Friends can also be specified as an array. */ -class LUser extends Model +class LUser extends Model2 { public $table = 'user'; @@ -88,7 +89,7 @@ protected function init(): void * The challenge here is to make sure that those handlers are executed automatically * while importing User and Friends. */ -class LFriend extends Model +class LFriend extends Model2 { public $table = 'friend'; public $title_field = 'friend_name'; diff --git a/tests/Model/Person.php b/tests/Model/Person.php index 8a52331220..139831b0c2 100644 --- a/tests/Model/Person.php +++ b/tests/Model/Person.php @@ -4,9 +4,9 @@ namespace Atk4\Data\Tests\Model; -use Atk4\Data\Model; +use Atk4\Data\Model2; -class Person extends Model +class Person extends Model2 { public $table = 'person'; diff --git a/tests/Model/Smbo/Account.php b/tests/Model/Smbo/Account.php index 22300e26d9..970d3faa8f 100644 --- a/tests/Model/Smbo/Account.php +++ b/tests/Model/Smbo/Account.php @@ -5,8 +5,9 @@ namespace Atk4\Data\Tests\Model\Smbo; use Atk4\Data\Model; +use Atk4\Data\Model2; -class Account extends Model +class Account extends Model2 { public $table = 'account'; diff --git a/tests/Model/Smbo/Company.php b/tests/Model/Smbo/Company.php index 329c7b36a6..4222b22d9a 100644 --- a/tests/Model/Smbo/Company.php +++ b/tests/Model/Smbo/Company.php @@ -4,9 +4,9 @@ namespace Atk4\Data\Tests\Model\Smbo; -use Atk4\Data\Model; +use Atk4\Data\Model2; -class Company extends Model +class Company extends Model2 { public $table = 'system'; diff --git a/tests/Model/Smbo/Contact.php b/tests/Model/Smbo/Contact.php index de94aa8eeb..9e4a97ebe9 100644 --- a/tests/Model/Smbo/Contact.php +++ b/tests/Model/Smbo/Contact.php @@ -4,9 +4,9 @@ namespace Atk4\Data\Tests\Model\Smbo; -use Atk4\Data\Model; +use Atk4\Data\Model2; -class Contact extends Model +class Contact extends Model2 { public $table = 'contact'; diff --git a/tests/Model/Smbo/Document.php b/tests/Model/Smbo/Document.php index 4679887978..2775286249 100644 --- a/tests/Model/Smbo/Document.php +++ b/tests/Model/Smbo/Document.php @@ -4,9 +4,9 @@ namespace Atk4\Data\Tests\Model\Smbo; -use Atk4\Data\Model; +use Atk4\Data\Model2; -class Document extends Model +class Document extends Model2 { public $table = 'document'; diff --git a/tests/Model/User.php b/tests/Model/User.php index 33fc847fb2..edf049aca4 100644 --- a/tests/Model/User.php +++ b/tests/Model/User.php @@ -4,9 +4,9 @@ namespace Atk4\Data\Tests\Model; -use Atk4\Data\Model; +use Atk4\Data\Model2; -class User extends Model +class User extends Model2 { protected function init(): void { diff --git a/tests/ModelWithoutIdTest.php b/tests/ModelWithoutIdTest.php index 21b043affb..1cedc0c669 100644 --- a/tests/ModelWithoutIdTest.php +++ b/tests/ModelWithoutIdTest.php @@ -6,6 +6,7 @@ use Atk4\Data\Exception; use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Schema\TestCase; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; @@ -28,7 +29,7 @@ protected function setUp(): void ], ]); - $this->m = new Model($this->db, ['table' => 'user', 'id_field' => false]); + $this->m = new Model2($this->db, ['table' => 'user', 'id_field' => false]); $this->m->addFields(['name', 'gender']); } diff --git a/tests/Persistence/ArrayTest.php b/tests/Persistence/ArrayTest.php index 3080fa344f..4870e4cf8f 100644 --- a/tests/Persistence/ArrayTest.php +++ b/tests/Persistence/ArrayTest.php @@ -7,6 +7,7 @@ use Atk4\Core\Phpunit\TestCase; use Atk4\Data\Exception; use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Persistence; use Atk4\Data\Tests\Model\Female as Female; use Atk4\Data\Tests\Model\Male as Male; @@ -37,7 +38,7 @@ public function testLoadArray(): void 2 => ['name' => 'Sarah', 'surname' => 'Jones'], ], ]); - $m = new Model($p, ['table' => 'user']); + $m = new Model2($p, ['table' => 'user']); $m->addField('name'); $m->addField('surname'); @@ -98,7 +99,7 @@ public function testUpdateArray(): void 2 => ['name' => 'Sarah', 'surname' => 'Jones'], ], ]); - $m = new Model($p, ['table' => 'user']); + $m = new Model2($p, ['table' => 'user']); $m->addField('name'); $m->addField('surname'); @@ -140,7 +141,7 @@ public function testInsert(): void 2 => ['name' => 'Sarah', 'surname' => 'Jones'], ], ]); - $m = new Model($p, ['table' => 'user']); + $m = new Model2($p, ['table' => 'user']); $m->addField('name'); $m->addField('surname'); @@ -165,7 +166,7 @@ public function testIterator(): void 2 => ['name' => 'Sarah', 'surname' => 'Jones'], ], ]); - $m = new Model($p, ['table' => 'user']); + $m = new Model2($p, ['table' => 'user']); $m->addField('name'); $m->addField('surname'); @@ -187,7 +188,7 @@ public function testShortFormat(): void 1 => ['name' => 'John', 'surname' => 'Smith'], 2 => ['name' => 'Sarah', 'surname' => 'Jones'], ]); - $m = new Model($p); + $m = new Model2($p); $m->addField('name'); $m->addField('surname'); @@ -215,7 +216,7 @@ public function testExport(): void 1 => ['name' => 'John', 'surname' => 'Smith'], 2 => ['name' => 'Sarah', 'surname' => 'Jones'], ]); - $m = new Model($p); + $m = new Model2($p); $m->addField('name'); $m->addField('surname'); @@ -239,7 +240,7 @@ public function testActionCount(): void 1 => ['name' => 'John', 'surname' => 'Smith'], 2 => ['name' => 'Sarah', 'surname' => 'Jones'], ]); - $m = new Model($p); + $m = new Model2($p); $m->addField('name'); $m->addField('surname'); @@ -255,7 +256,7 @@ public function testActionField(): void 1 => ['name' => 'John', 'surname' => 'Smith'], 2 => ['name' => 'Sarah', 'surname' => 'Jones'], ]); - $m = new Model($p); + $m = new Model2($p); $m->addField('name'); $m->addField('surname'); @@ -300,7 +301,7 @@ public function testLike(): void } $p = new Persistence\Array_($dbData); - $m = new Model($p, ['table' => 'countries']); + $m = new Model2($p, ['table' => 'countries']); $m->addField('code', ['type' => 'integer']); $m->addField('country'); $m->addField('active', ['type' => 'boolean']); @@ -410,7 +411,7 @@ public function testConditions(): void } $p = new Persistence\Array_($dbData); - $m = new Model($p, ['table' => 'countries']); + $m = new Model2($p, ['table' => 'countries']); $m->addField('code', ['type' => 'integer']); $m->addField('country'); $m->addField('active', ['type' => 'boolean']); @@ -509,7 +510,7 @@ public function testAggregates(): void 10 => ['items' => 0, 'active' => 1], 11 => ['items' => null, 'active' => 1], ]]); - $m = new Model($p, ['table' => 'invoices']); + $m = new Model2($p, ['table' => 'invoices']); $m->addField('items', ['type' => 'integer']); $this->assertSame(13.5, $m->action('fx', ['avg', 'items'])->getOne()); @@ -524,7 +525,7 @@ public function testExists(): void $p = new Persistence\Array_(['invoices' => [ 1 => ['number' => 'ABC9', 'items' => 11, 'active' => 1], ]]); - $m = new Model($p, ['table' => 'invoices']); + $m = new Model2($p, ['table' => 'invoices']); $m->addField('items', ['type' => 'integer']); $this->assertSame(1, $m->action('exists')->getOne()); @@ -565,7 +566,7 @@ public function testOrder(): void // order by one field ascending $p = new Persistence\Array_($dbData); - $m = new Model($p); + $m = new Model2($p); $m->addField('f1'); $m->addField('f2'); $m->addField('f3'); @@ -583,7 +584,7 @@ public function testOrder(): void // order by one field descending $p = new Persistence\Array_($dbData); - $m = new Model($p); + $m = new Model2($p); $m->getField('id')->actual = 'myid'; $m->addField('f1'); $m->addField('f2'); @@ -602,7 +603,7 @@ public function testOrder(): void // order by two fields ascending $p = new Persistence\Array_($dbData); - $m = new Model($p); + $m = new Model2($p); $m->addField('f1'); $m->addField('f2'); $m->addField('f3'); @@ -627,13 +628,13 @@ public function testNoKeyException(): void ['id' => 3, 'f1' => 'A'], ]); $this->expectException(Exception::class); - $m = new Model($p); + $m = new Model2($p); } public function testImportAndAutoincrement(): void { $p = new Persistence\Array_([]); - $m = new Model($p); + $m = new Model2($p); $m->addField('f1'); $m->import([ @@ -705,7 +706,7 @@ public function testLimit(): void 3 => ['f1' => 'E'], 4 => ['f1' => 'C'], ]); - $m = new Model($p); + $m = new Model2($p); $m->addField('f1'); $this->assertSame(4, $m->action('count')->getOne()); @@ -742,7 +743,7 @@ public function testCondition(): void 3 => ['name' => 'Sarah', 'surname' => 'XX'], 4 => ['name' => 'Sarah', 'surname' => 'Smith'], ]); - $m = new Model($p); + $m = new Model2($p); $m->addField('name'); $m->addField('surname'); @@ -764,7 +765,7 @@ public function testCondition(): void public function testUnsupportedAction(): void { $p = new Persistence\Array_([1 => ['name' => 'John']]); - $m = new Model($p); + $m = new Model2($p); $m->addField('name'); $this->expectException(Exception::class); $m->action('foo'); @@ -773,7 +774,7 @@ public function testUnsupportedAction(): void public function testUnsupportedAggregate(): void { $p = new Persistence\Array_([1 => ['name' => 'John']]); - $m = new Model($p); + $m = new Model2($p); $m->addField('name'); $this->expectException(Exception::class); @@ -783,7 +784,7 @@ public function testUnsupportedAggregate(): void public function testUnsupportedCondition1(): void { $p = new Persistence\Array_([1 => ['name' => 'John']]); - $m = new Model($p); + $m = new Model2($p); $m->addField('name'); $this->expectException(Exception::class); $m->addCondition('name'); @@ -792,10 +793,10 @@ public function testUnsupportedCondition1(): void public function testUnsupportedCondition2(): void { $p = new Persistence\Array_([1 => ['name' => 'John']]); - $m = new Model($p); + $m = new Model2($p); $m->addField('name'); $this->expectException(Exception::class); - $m->addCondition(new Model(), 'like', '%o%'); + $m->addCondition(new Model2(), 'like', '%o%'); } /** @@ -814,11 +815,11 @@ public function testHasOne(): void ], ]); - $user = new Model($p, ['table' => 'user']); + $user = new Model2($p, ['table' => 'user']); $user->addField('name'); $user->addField('surname'); - $country = new Model(); + $country = new Model2(); $country->table = 'country'; $country->addField('name'); @@ -848,10 +849,10 @@ public function testHasMany(): void ], ]); - $country = new Model($p, ['table' => 'country']); + $country = new Model2($p, ['table' => 'country']); $country->addField('name'); - $user = new Model(); + $user = new Model2(); $user->table = 'user'; $user->addField('name'); $user->addField('surname'); @@ -869,7 +870,7 @@ public function testHasMany(): void public function testLoadAnyThrowsExceptionOnRecordNotFound(): void { $p = new Persistence\Array_(); - $m = new Model($p); + $m = new Model2($p); $m->addField('name'); $this->expectExceptionCode(404); $m = $m->loadAny(); @@ -878,7 +879,7 @@ public function testLoadAnyThrowsExceptionOnRecordNotFound(): void public function testTryLoadAnyNotThrowsExceptionOnRecordNotFound(): void { $p = new Persistence\Array_(); - $m = new Model($p); + $m = new Model2($p); $m->addField('name'); $m->addField('surname'); $m = $m->tryLoadAny(); @@ -893,7 +894,7 @@ public function testTryLoadAnyReturnsFirstRecord(): void ]; $p = new Persistence\Array_($a); - $m = new Model($p); + $m = new Model2($p); $m->addField('name'); $m->addField('surname'); $m = $m->tryLoadAny(); diff --git a/tests/Persistence/CsvTest.php b/tests/Persistence/CsvTest.php index 6fc46975c8..766f173dd3 100644 --- a/tests/Persistence/CsvTest.php +++ b/tests/Persistence/CsvTest.php @@ -6,7 +6,7 @@ use Atk4\Core\Phpunit\TestCase; use Atk4\Data\Exception; -use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Persistence; use Atk4\Data\Tests\Model\Person; @@ -114,7 +114,7 @@ public function testLoadAny(): void $this->setDb($data); $p = $this->makeCsvPersistence($this->file); - $m = new Model($p); + $m = new Model2($p); $m->addField('name'); $m->addField('surname'); $m = $m->loadAny(); @@ -133,7 +133,7 @@ public function testLoadAnyException(): void $this->setDb($data); $p = $this->makeCsvPersistence($this->file); - $m = new Model($p); + $m = new Model2($p); $m->addField('name'); $m->addField('surname'); @@ -157,7 +157,7 @@ public function testLoadByIdNotSupportedException(): void $this->setDb($data); $p = $this->makeCsvPersistence($this->file); - $m = new Model($p); + $m = new Model2($p); $this->expectException(Exception::class); $m = $m->tryLoad(1); } @@ -206,7 +206,7 @@ public function testExport(): void $this->setDb($data); $p = $this->makeCsvPersistence($this->file); - $m = new Model($p); + $m = new Model2($p); $m->addField('name'); $m->addField('surname'); diff --git a/tests/Persistence/Sql/WithDb/SelectTest.php b/tests/Persistence/Sql/WithDb/SelectTest.php index 08e70214d0..ed6972ef92 100644 --- a/tests/Persistence/Sql/WithDb/SelectTest.php +++ b/tests/Persistence/Sql/WithDb/SelectTest.php @@ -4,7 +4,7 @@ namespace Atk4\Data\Tests\Persistence\Sql\WithDb; -use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Persistence\Sql\Connection; use Atk4\Data\Persistence\Sql\Exception; use Atk4\Data\Persistence\Sql\ExecuteException; @@ -27,7 +27,7 @@ protected function setUp(): void $this->c = $this->db->connection; - $model = new Model($this->db, ['table' => 'employee']); + $model = new Model2($this->db, ['table' => 'employee']); $model->addField('name'); $model->addField('surname'); $model->addField('retired', ['type' => 'boolean']); @@ -295,7 +295,7 @@ public function testUtf8mb4Support(): void public function testImportAndAutoincrement(): void { - $m = new Model($this->db, ['table' => 'test']); + $m = new Model2($this->db, ['table' => 'test']); $m->getField('id')->actual = 'myid'; $m->setOrder('id'); $m->addField('f1'); diff --git a/tests/Persistence/Sql/WithDb/TransactionTest.php b/tests/Persistence/Sql/WithDb/TransactionTest.php index fb52d3cd00..9137a06e81 100644 --- a/tests/Persistence/Sql/WithDb/TransactionTest.php +++ b/tests/Persistence/Sql/WithDb/TransactionTest.php @@ -4,7 +4,7 @@ namespace Atk4\Data\Tests\Persistence\Sql\WithDb; -use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Persistence\Sql\Connection; use Atk4\Data\Persistence\Sql\Exception; use Atk4\Data\Persistence\Sql\Expression; @@ -22,7 +22,7 @@ protected function setUp(): void $this->c = $this->db->connection; - $model = new Model($this->db, ['table' => 'employee']); + $model = new Model2($this->db, ['table' => 'employee']); $model->addField('name'); $model->addField('surname'); $model->addField('retired', ['type' => 'boolean']); diff --git a/tests/Persistence/SqlTest.php b/tests/Persistence/SqlTest.php index 582aef0306..6fb6b03439 100644 --- a/tests/Persistence/SqlTest.php +++ b/tests/Persistence/SqlTest.php @@ -6,6 +6,7 @@ use Atk4\Data\Exception; use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Schema\TestCase; class SqlTest extends TestCase @@ -19,7 +20,7 @@ public function testLoadArray(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addField('name'); $m->addField('surname'); @@ -47,7 +48,7 @@ public function testModelLoadOneAndAny(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addField('name'); $m->addField('surname'); @@ -85,7 +86,7 @@ public function testPersistenceInsert(): void $this->setDb($dbData); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addField('name'); $m->addField('surname'); @@ -119,7 +120,7 @@ public function testModelInsert(): void ]; $this->setDb($dbData); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addField('name'); $m->addField('surname'); @@ -142,7 +143,7 @@ public function testModelSaveNoReload(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addField('name'); $m->addField('surname'); @@ -167,7 +168,7 @@ public function testModelInsertRows(): void ]; $this->setDb($dbData, false); // create empty table - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addField('name'); $m->addField('surname'); @@ -190,7 +191,7 @@ public function testPersistenceDelete(): void ]; $this->setDb($dbData); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addField('name'); $m->addField('surname'); @@ -222,7 +223,7 @@ public function testExport(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addField('name'); $m->addField('surname'); diff --git a/tests/Persistence/StaticTest.php b/tests/Persistence/StaticTest.php index de3db6e317..5b8c73238a 100644 --- a/tests/Persistence/StaticTest.php +++ b/tests/Persistence/StaticTest.php @@ -5,7 +5,7 @@ namespace Atk4\Data\Tests\Persistence; use Atk4\Core\Phpunit\TestCase; -use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Persistence; class StaticTest extends TestCase @@ -15,12 +15,12 @@ public function testBasicStatic(): void $p = new Persistence\Static_([1 => 'hello', 'world']); // default title field - $m = new Model($p); + $m = new Model2($p); $m = $m->load(2); $this->assertSame('world', $m->get('name')); // custom title field and try loading from same static twice - $m = new Model($p); //, ['title_field' => 'foo']); + $m = new Model2($p); //, ['title_field' => 'foo']); $m = $m->load(2); $this->assertSame('world', $m->get('name')); // still 'name' here not 'foo' } @@ -28,7 +28,7 @@ public function testBasicStatic(): void public function testArrayOfArrays(): void { $p = new Persistence\Static_([1 => ['hello', 'xx', true], ['world', 'xy', false]]); - $m = new Model($p); + $m = new Model2($p); $m = $m->load(2); @@ -40,7 +40,7 @@ public function testArrayOfArrays(): void public function testArrayOfHashes(): void { $p = new Persistence\Static_([1 => ['foo' => 'hello'], ['foo' => 'world']]); - $m = new Model($p); + $m = new Model2($p); $m = $m->load(2); @@ -50,7 +50,7 @@ public function testArrayOfHashes(): void public function testIdArg(): void { $p = new Persistence\Static_([['id' => 20, 'foo' => 'hello'], ['id' => 21, 'foo' => 'world']]); - $m = new Model($p); + $m = new Model2($p); $m = $m->load(21); @@ -60,7 +60,7 @@ public function testIdArg(): void public function testIdKey(): void { $p = new Persistence\Static_([20 => ['foo' => 'hello'], 21 => ['foo' => 'world']]); - $m = new Model($p); + $m = new Model2($p); $m = $m->load(21); @@ -70,7 +70,7 @@ public function testIdKey(): void public function testZeroIdAllowed(): void { $p = new Persistence\Static_(['hello', 'world']); - $m = new class($p) extends Model { + $m = new class($p) extends Model2 { protected function init(): void { parent::init(); @@ -90,13 +90,13 @@ public function testZeroIdNotAllowed(): void $this->expectException(\Atk4\Data\Exception::class); $this->expectExceptionMessage('Must not be a zero'); - $m = new Model($p); + $m = new Model2($p); } public function testEmpty(): void { $p = new Persistence\Static_([]); - $m = new Model($p); + $m = new Model2($p); $m = $m->tryLoadAny(); @@ -118,15 +118,15 @@ public function testCustomField(): void public function testTitleOrName(): void { $p = new Persistence\Static_([1 => ['foo' => 'hello', 'bar' => 'world']]); - $m = new Model($p); + $m = new Model2($p); $this->assertSame('foo', $m->title_field); $p = new Persistence\Static_([1 => ['foo' => 'hello', 'name' => 'x']]); - $m = new Model($p); + $m = new Model2($p); $this->assertSame('name', $m->title_field); $p = new Persistence\Static_([1 => ['foo' => 'hello', 'title' => 'x']]); - $m = new Model($p); + $m = new Model2($p); $this->assertSame('title', $m->title_field); } @@ -143,7 +143,7 @@ public function testFieldTypes(): void 'test_str_2' => '123', 'test_str_3' => '123.45', ]]); - $m = new Model($p); + $m = new Model2($p); $this->assertSame('integer', $m->getField('id')->type); $this->assertSame('integer', $m->getField('test_int')->type); @@ -162,7 +162,7 @@ public function testFieldTypes(): void public function testFieldTypesBasicInteger(): void { $p = new Persistence\Static_([1 => 'hello', 'world']); - $m = new Model($p); + $m = new Model2($p); $this->assertSame('integer', $m->getField('id')->type); $this->assertSame('string', $m->getField('name')->type); @@ -171,14 +171,14 @@ public function testFieldTypesBasicInteger(): void public function testFieldTypesBasicString(): void { $p = new Persistence\Static_(['test' => 'hello', 10 => 'world']); - $m = new Model($p); + $m = new Model2($p); $this->assertSame('string', $m->getField('id')->type); $this->assertSame('string', $m->getField('name')->type); } } -class StaticTestModel extends Model +class StaticTestModel extends Model2 { public $title_field = 'foo'; diff --git a/tests/RandomTest.php b/tests/RandomTest.php index 610466237a..12cc4a6308 100644 --- a/tests/RandomTest.php +++ b/tests/RandomTest.php @@ -8,6 +8,7 @@ use Atk4\Data\Exception; use Atk4\Data\Field; use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Persistence; use Atk4\Data\Persistence\Sql\Connection; use Atk4\Data\Persistence\Sql\Expression; @@ -17,7 +18,7 @@ use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Platforms\SQLServerPlatform; -class Model_Rate extends Model +class Model_Rate extends Model2 { public $table = 'rate'; @@ -29,7 +30,7 @@ protected function init(): void $this->addField('ask', ['type' => 'float']); } } -class Model_Item extends Model +class Model_Item extends Model2 { public $table = 'item'; @@ -41,7 +42,7 @@ protected function init(): void ->addTitle(); } } -class Model_Item2 extends Model +class Model_Item2 extends Model2 { public $table = 'item'; @@ -54,7 +55,7 @@ protected function init(): void ->addTitle(); } } -class Model_Item3 extends Model +class Model_Item3 extends Model2 { public $table = 'item'; @@ -99,7 +100,7 @@ public function testTitleImport(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addFields(['name', 'salary' => ['default' => 10]]); $m->import([['name' => 'Peter'], ['name' => 'Steve', 'salary' => 30]]); @@ -124,7 +125,7 @@ public function testAddFields(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addFields(['name', 'login'], ['default' => 'unknown']); $m->insert(['name' => 'Peter']); @@ -147,7 +148,7 @@ public function testAddFields2(): void ], ]); - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addFields(['name'], ['default' => 'anonymous']); $m->addFields([ 'last_name', @@ -243,7 +244,7 @@ public function testDirty2(): void $p = new Persistence\Static_([1 => 'hello', 'world']); // default title field - $m = new Model($p); + $m = new Model2($p); $m->addExpression('caps', function ($m) { return strtoupper($m->get('name')); }); @@ -263,7 +264,7 @@ public function testUpdateCondition(): void ], ]); - $m = new Model($this->db, ['table' => 'item']); + $m = new Model2($this->db, ['table' => 'item']); $m->addField('name'); $m = $m->load(2); @@ -309,7 +310,7 @@ public function testHookBreakers(): void ], ]); - $m = new Model($this->db, ['table' => 'never_used']); + $m = new Model2($this->db, ['table' => 'never_used']); $m->addField('name'); $m->onHook(Model::HOOK_BEFORE_SAVE, static function (Model $m) { @@ -414,12 +415,12 @@ public function testExport(): void ]); // model without id field - $m1 = new Model($this->db, ['table' => 'user', 'id_field' => false]); + $m1 = new Model2($this->db, ['table' => 'user', 'id_field' => false]); $m1->addField('code'); $m1->addField('name'); // model with id field - $m2 = new Model($this->db, ['table' => 'user']); + $m2 = new Model2($this->db, ['table' => 'user']); $m2->addField('code'); $m2->addField('name'); @@ -529,10 +530,10 @@ public function testTableWithSchema(): void } } - $user = new Model($this->db, ['table' => $userSchema . '.user']); + $user = new Model2($this->db, ['table' => $userSchema . '.user']); $user->addField('name'); - $doc = new Model($this->db, ['table' => $docSchema . '.doc']); + $doc = new Model2($this->db, ['table' => $docSchema . '.doc']); $doc->addField('name'); $doc->hasOne('user_id', ['model' => $user])->addTitle(); $doc->addCondition('user', 'Sarah'); diff --git a/tests/ReadOnlyModeTest.php b/tests/ReadOnlyModeTest.php index 625bd70f68..5ae8c04dda 100644 --- a/tests/ReadOnlyModeTest.php +++ b/tests/ReadOnlyModeTest.php @@ -6,6 +6,7 @@ use Atk4\Data\Exception; use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Schema\TestCase; /** @@ -27,7 +28,7 @@ protected function setUp(): void ], ]); - $this->m = new Model($this->db, ['table' => 'user', 'read_only' => true]); + $this->m = new Model2($this->db, ['table' => 'user', 'read_only' => true]); $this->m->addFields(['name', 'gender']); } diff --git a/tests/ReferenceSqlTest.php b/tests/ReferenceSqlTest.php index 5e363a1920..7130cffb6f 100644 --- a/tests/ReferenceSqlTest.php +++ b/tests/ReferenceSqlTest.php @@ -5,6 +5,7 @@ namespace Atk4\Data\Tests; use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Schema\TestCase; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Platforms\SQLServerPlatform; @@ -32,8 +33,8 @@ public function testBasic(): void ], ]); - $u = (new Model($this->db, ['table' => 'user']))->addFields(['name']); - $o = (new Model($this->db, ['table' => 'order']))->addFields(['amount', 'user_id']); + $u = (new Model2($this->db, ['table' => 'user']))->addFields(['name']); + $o = (new Model2($this->db, ['table' => 'order']))->addFields(['amount', 'user_id']); $u->hasMany('Orders', ['model' => $o]); @@ -66,8 +67,8 @@ public function testBasic(): void */ public function testLink(): void { - $u = (new Model($this->db, ['table' => 'user']))->addFields(['name']); - $o = (new Model($this->db, ['table' => 'order']))->addFields(['amount', 'user_id']); + $u = (new Model2($this->db, ['table' => 'user']))->addFields(['name']); + $o = (new Model2($this->db, ['table' => 'order']))->addFields(['amount', 'user_id']); $u->hasMany('Orders', ['model' => $o]); @@ -91,8 +92,8 @@ public function testBasic2(): void ], ]); - $u = (new Model($this->db, ['table' => 'user']))->addFields(['name', 'currency']); - $c = (new Model($this->db, ['table' => 'currency']))->addFields(['currency', 'name']); + $u = (new Model2($this->db, ['table' => 'user']))->addFields(['name', 'currency']); + $c = (new Model2($this->db, ['table' => 'currency']))->addFields(['currency', 'name']); $u->hasMany('cur', ['model' => $c, 'our_field' => 'currency', 'their_field' => 'currency']); @@ -107,8 +108,8 @@ public function testBasic2(): void public function testLink2(): void { - $u = (new Model($this->db, ['table' => 'user']))->addFields(['name', 'currency_code']); - $c = (new Model($this->db, ['table' => 'currency']))->addFields(['code', 'name']); + $u = (new Model2($this->db, ['table' => 'user']))->addFields(['name', 'currency_code']); + $c = (new Model2($this->db, ['table' => 'currency']))->addFields(['code', 'name']); $u->hasMany('cur', ['model' => $c, 'our_field' => 'currency_code', 'their_field' => 'code']); @@ -138,8 +139,8 @@ public function testBasicOne(): void ], ]); - $u = (new Model($this->db, ['table' => 'user']))->addFields(['name']); - $o = (new Model($this->db, ['table' => 'order']))->addFields(['amount']); + $u = (new Model2($this->db, ['table' => 'user']))->addFields(['name']); + $o = (new Model2($this->db, ['table' => 'order']))->addFields(['amount']); $o->hasOne('user_id', ['model' => $u]); @@ -176,9 +177,9 @@ public function testAddOneField(): void ], ]); - $u = (new Model($this->db, ['table' => 'user']))->addFields(['name', 'date' => ['type' => 'date']]); + $u = (new Model2($this->db, ['table' => 'user']))->addFields(['name', 'date' => ['type' => 'date']]); - $o = (new Model($this->db, ['table' => 'order']))->addFields(['amount']); + $o = (new Model2($this->db, ['table' => 'order']))->addFields(['amount']); $o->hasOne('user_id', ['model' => $u])->addFields(['username' => 'name', ['date', 'type' => 'date']]); $this->assertSame('John', $o->load(1)->get('username')); @@ -189,12 +190,12 @@ public function testAddOneField(): void $this->assertSame('Joe', $o->load(5)->get('username')); // few more tests - $o = (new Model($this->db, ['table' => 'order']))->addFields(['amount']); + $o = (new Model2($this->db, ['table' => 'order']))->addFields(['amount']); $o->hasOne('user_id', ['model' => $u])->addFields(['username' => 'name', 'thedate' => ['date', 'type' => 'date']]); $this->assertSame('John', $o->load(1)->get('username')); $this->assertEquals(new \DateTime('2001-01-02'), $o->load(1)->get('thedate')); - $o = (new Model($this->db, ['table' => 'order']))->addFields(['amount']); + $o = (new Model2($this->db, ['table' => 'order']))->addFields(['amount']); $o->hasOne('user_id', ['model' => $u])->addFields(['date'], ['type' => 'date']); $this->assertEquals(new \DateTime('2001-01-02'), $o->load(1)->get('date')); } @@ -217,8 +218,8 @@ public function testRelatedExpression(): void ], ]); - $i = (new Model($this->db, ['table' => 'invoice']))->addFields(['ref_no']); - $l = (new Model($this->db, ['table' => 'invoice_line']))->addFields(['invoice_id', 'total_net', 'total_vat', 'total_gross']); + $i = (new Model2($this->db, ['table' => 'invoice']))->addFields(['ref_no']); + $l = (new Model2($this->db, ['table' => 'invoice_line']))->addFields(['invoice_id', 'total_net', 'total_vat', 'total_gross']); $i->hasMany('line', ['model' => $l]); $i->addExpression('total_net', $i->refLink('line')->action('fx', ['sum', 'total_net'])); @@ -247,8 +248,8 @@ public function testAggregateHasMany(): void ], ]); - $i = (new Model($this->db, ['table' => 'invoice']))->addFields(['ref_no']); - $l = (new Model($this->db, ['table' => 'invoice_line']))->addFields([ + $i = (new Model2($this->db, ['table' => 'invoice']))->addFields(['ref_no']); + $l = (new Model2($this->db, ['table' => 'invoice_line']))->addFields([ 'invoice_id', 'total_net' => ['type' => 'atk4_money'], 'total_vat' => ['type' => 'atk4_money'], @@ -323,8 +324,8 @@ public function testOtherAggregates(): void return 'SUM(' . $v . ')'; }; - $l = (new Model($this->db, ['table' => 'list']))->addFields(['name']); - $i = (new Model($this->db, ['table' => 'item']))->addFields(['list_id', 'name', 'code']); + $l = (new Model2($this->db, ['table' => 'list']))->addFields(['name']); + $i = (new Model2($this->db, ['table' => 'item']))->addFields(['list_id', 'name', 'code']); $l->hasMany('Items', ['model' => $i]) ->addFields([ 'items_name' => ['aggregate' => 'count', 'field' => 'name'], @@ -376,13 +377,13 @@ public function testReferenceHasOneTraversing(): void ], ]); - $user = (new Model($this->db, ['table' => 'user']))->addFields(['name', 'company_id']); + $user = (new Model2($this->db, ['table' => 'user']))->addFields(['name', 'company_id']); - $company = (new Model($this->db, ['table' => 'company']))->addFields(['name']); + $company = (new Model2($this->db, ['table' => 'company']))->addFields(['name']); $user->hasOne('Company', ['model' => $company, 'our_field' => 'company_id', 'their_field' => 'id']); - $order = new Model($this->db, ['table' => 'order']); + $order = new Model2($this->db, ['table' => 'order']); $order->addField('company_id'); $order->addField('description'); $order->addField('amount', ['default' => 20, 'type' => 'float']); @@ -427,8 +428,8 @@ public function testReferenceHook(): void ], ]); - $u = (new Model($this->db, ['table' => 'user']))->addFields(['name']); - $c = (new Model($this->db, ['table' => 'contact']))->addFields(['address']); + $u = (new Model2($this->db, ['table' => 'user']))->addFields(['name']); + $c = (new Model2($this->db, ['table' => 'contact']))->addFields(['address']); $u->hasOne('contact_id', ['model' => $c]) ->addField('address'); @@ -474,9 +475,9 @@ public function testIdFieldReferenceOurFieldCase(): void ], ]); - $p = (new Model($this->db, ['table' => 'player']))->addFields(['name']); + $p = (new Model2($this->db, ['table' => 'player']))->addFields(['name']); - $s = (new Model($this->db, ['table' => 'stadium'])); + $s = (new Model2($this->db, ['table' => 'stadium'])); $s->addFields(['name']); $s->hasOne('player_id', ['model' => $p]); @@ -490,8 +491,8 @@ public function testIdFieldReferenceOurFieldCase(): void public function testModelProperty(): void { - $user = new Model($this->db, ['table' => 'user']); - $user->hasMany('Orders', ['model' => [Model::class, 'table' => 'order'], 'their_field' => 'id']); + $user = new Model2($this->db, ['table' => 'user']); + $user->hasMany('Orders', ['model' => [Model2::class, 'table' => 'order'], 'their_field' => 'id']); $o = $user->ref('Orders'); $this->assertSame('order', $o->table); } @@ -510,8 +511,8 @@ public function testAddTitle(): void ], ]); - $u = (new Model($this->db, ['table' => 'user']))->addFields(['name']); - $o = (new Model($this->db, ['table' => 'order']))->addFields(['amount']); + $u = (new Model2($this->db, ['table' => 'user']))->addFields(['name']); + $o = (new Model2($this->db, ['table' => 'order']))->addFields(['amount']); // by default not set $o->hasOne('user_id', ['model' => $u]); @@ -523,7 +524,7 @@ public function testAddTitle(): void $this->assertSame($o->getField('user_id')->isVisible(), false); // if it is set manually then it will not be changed - $o = (new Model($this->db, ['table' => 'order']))->addFields(['amount']); + $o = (new Model2($this->db, ['table' => 'order']))->addFields(['amount']); $o->hasOne('user_id', ['model' => $u]); $o->getField('user_id')->ui['visible'] = true; $o->getRef('user_id')->addTitle(); @@ -553,8 +554,8 @@ public function testHasOneTitleSet(): void $this->setDb($dbData); // with default title_field='name' - $u = (new Model($this->db, ['table' => 'user']))->addFields(['name', 'last_name']); - $o = (new Model($this->db, ['table' => 'order'])); + $u = (new Model2($this->db, ['table' => 'user']))->addFields(['name', 'last_name']); + $o = (new Model2($this->db, ['table' => 'order'])); $o->hasOne('user_id', ['model' => $u])->addTitle(); // change order user by changing title_field value @@ -570,8 +571,8 @@ public function testHasOneTitleSet(): void $this->setDb($dbData); // with custom title_field='last_name' - $u = (new Model($this->db, ['table' => 'user', 'title_field' => 'last_name']))->addFields(['name', 'last_name']); - $o = (new Model($this->db, ['table' => 'order'])); + $u = (new Model2($this->db, ['table' => 'user', 'title_field' => 'last_name']))->addFields(['name', 'last_name']); + $o = (new Model2($this->db, ['table' => 'order'])); $o->hasOne('user_id', ['model' => $u])->addTitle(); // change order user by changing title_field value @@ -587,8 +588,8 @@ public function testHasOneTitleSet(): void $this->setDb($dbData); // with custom title_field='last_name' and custom link name - $u = (new Model($this->db, ['table' => 'user', 'title_field' => 'last_name']))->addFields(['name', 'last_name']); - $o = (new Model($this->db, ['table' => 'order'])); + $u = (new Model2($this->db, ['table' => 'user', 'title_field' => 'last_name']))->addFields(['name', 'last_name']); + $o = (new Model2($this->db, ['table' => 'order'])); $o->hasOne('my_user', ['model' => $u, 'our_field' => 'user_id'])->addTitle(); // change order user by changing ref field value @@ -604,8 +605,8 @@ public function testHasOneTitleSet(): void $this->setDb($dbData); // with custom title_field='last_name' and custom link name - $u = (new Model($this->db, ['table' => 'user', 'title_field' => 'last_name']))->addFields(['name', 'last_name']); - $o = (new Model($this->db, ['table' => 'order'])); + $u = (new Model2($this->db, ['table' => 'user', 'title_field' => 'last_name']))->addFields(['name', 'last_name']); + $o = (new Model2($this->db, ['table' => 'order'])); $o->hasOne('my_user', ['model' => $u, 'our_field' => 'user_id'])->addTitle(); // change order user by changing ref field value @@ -638,7 +639,7 @@ public function testHasOneReferenceCaption(): void 3 => ['id' => 3, 'user_id' => 1], ], ]); - $u = (new Model($this->db, ['table' => 'user', 'title_field' => 'last_name']))->addFields(['name', 'last_name']); + $u = (new Model2($this->db, ['table' => 'user', 'title_field' => 'last_name']))->addFields(['name', 'last_name']); // Test : Now the caption is null and is generated from field name $this->assertSame('Last Name', $u->getField('last_name')->getCaption()); @@ -648,7 +649,7 @@ public function testHasOneReferenceCaption(): void // Test : Now the caption is not null and the value is returned $this->assertSame('Surname', $u->getField('last_name')->getCaption()); - $o = (new Model($this->db, ['table' => 'order'])); + $o = (new Model2($this->db, ['table' => 'order'])); $order_user_ref = $o->hasOne('my_user', ['model' => $u, 'our_field' => 'user_id']); $order_user_ref->addField('user_last_name', 'last_name'); @@ -683,12 +684,12 @@ public function testHasOneReferenceType(): void ], ] ); - $user = (new Model($this->db, ['table' => 'user']))->addFields( + $user = (new Model2($this->db, ['table' => 'user']))->addFields( ['name', 'last_name', 'some_number', 'some_other_number'] ); $user->getField('some_number')->type = 'integer'; $user->getField('some_other_number')->type = 'integer'; - $order = (new Model($this->db, ['table' => 'order'])); + $order = (new Model2($this->db, ['table' => 'order'])); $order_UserRef = $order->hasOne('my_user', ['model' => $user, 'our_field' => 'user_id']); // no type set in defaults, should pull type integer from user model diff --git a/tests/ReferenceTest.php b/tests/ReferenceTest.php index a029c65426..34b074d493 100644 --- a/tests/ReferenceTest.php +++ b/tests/ReferenceTest.php @@ -6,19 +6,20 @@ use Atk4\Data\Exception; use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Schema\TestCase; class ReferenceTest extends TestCase { public function testBasicReferences(): void { - $user = new Model(null, ['table' => 'user']); + $user = new Model2(null, ['table' => 'user']); $user->addField('id', ['type' => 'integer']); $user->addField('name'); $user = $user->createEntity(); $user->setId(1); - $order = new Model(); + $order = new Model2(); $order->addField('id'); $order->addField('amount', ['default' => 20]); $order->addField('user_id', ['type' => 'integer']); @@ -30,7 +31,7 @@ public function testBasicReferences(): void $this->assertSame(1, $o->get('user_id')); $user->getModel()->hasMany('BigOrders', ['model' => function () { - $m = new Model(); + $m = new Model2(); $m->addField('amount', ['default' => 100]); $m->addField('user_id'); @@ -45,13 +46,13 @@ public function testBasicReferences(): void */ public function testModelCaption(): void { - $user = new Model(null, ['table' => 'user']); + $user = new Model2(null, ['table' => 'user']); $user->addField('id'); $user->addField('name'); $user = $user->createEntity(); $user->setId(1); - $order = new Model(); + $order = new Model2(); $order->addField('id'); $order->addField('amount', ['default' => 20]); $order->addField('user_id'); @@ -65,18 +66,18 @@ public function testModelCaption(): void public function testModelProperty(): void { - $user = new Model($this->db, ['table' => 'user']); + $user = new Model2($this->db, ['table' => 'user']); $user = $user->createEntity(); $user->setId(1); - $user->getModel()->hasOne('order_id', ['model' => [Model::class, 'table' => 'order']]); + $user->getModel()->hasOne('order_id', ['model' => [Model2::class, 'table' => 'order']]); $o = $user->ref('order_id'); $this->assertSame('order', $o->table); } public function testRefName1(): void { - $user = new Model(null, ['table' => 'user']); - $order = new Model(); + $user = new Model2(null, ['table' => 'user']); + $order = new Model2(); $order->addField('user_id'); $user->hasMany('Orders', ['model' => $order]); @@ -86,8 +87,8 @@ public function testRefName1(): void public function testRefName2(): void { - $order = new Model(null, ['table' => 'order']); - $user = new Model(null, ['table' => 'user']); + $order = new Model2(null, ['table' => 'order']); + $user = new Model2(null, ['table' => 'user']); $user->hasOne('user_id', ['model' => $user]); $this->expectException(Exception::class); @@ -96,7 +97,7 @@ public function testRefName2(): void public function testRefName3(): void { - $order = new Model($this->db, ['table' => 'order']); + $order = new Model2($this->db, ['table' => 'order']); $order->addRef('archive', ['model' => function ($m) { return new $m(null, ['table' => $m->table . '_archive']); }]); @@ -108,7 +109,7 @@ public function testRefName3(): void public function testCustomRef(): void { - $m = new Model($this->db, ['table' => 'user']); + $m = new Model2($this->db, ['table' => 'user']); $m->addRef('archive', ['model' => function ($m) { return new $m(null, ['table' => $m->table . '_archive']); }]); diff --git a/tests/Schema/ModelTest.php b/tests/Schema/ModelTest.php index 7f68d718e5..f587717906 100644 --- a/tests/Schema/ModelTest.php +++ b/tests/Schema/ModelTest.php @@ -6,6 +6,7 @@ use Atk4\Data\Field\PasswordField; use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Schema\TestCase; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Platforms\SQLServerPlatform; @@ -124,7 +125,7 @@ public function testCreateModel(): void */ public function testCharacterTypeFieldCaseSensitivity(string $type, bool $isBinary): void { - $model = new Model($this->db, ['table' => 'user']); + $model = new Model2($this->db, ['table' => 'user']); $model->addField('v', ['type' => $type]); $this->createMigrator($model)->create(); @@ -210,7 +211,7 @@ public function testCharacterTypeFieldLong(string $type, bool $isBinary, int $le $this->assertSame($lengthBytes - 1, strlen($str)); } - $model = new Model($this->db, ['table' => 'user']); + $model = new Model2($this->db, ['table' => 'user']); $model->addField('v', ['type' => $type]); $this->createMigrator($model)->create(); @@ -250,7 +251,7 @@ public function providerCharacterTypeFieldLongData(): array } } -class TestUser extends Model +class TestUser extends Model2 { public $table = 'user'; @@ -267,7 +268,7 @@ protected function init(): void } } -class TestRole extends Model +class TestRole extends Model2 { public $table = 'role'; diff --git a/tests/ScopeTest.php b/tests/ScopeTest.php index 1be153cbe3..da71d10555 100644 --- a/tests/ScopeTest.php +++ b/tests/ScopeTest.php @@ -8,11 +8,12 @@ use Atk4\Data\Model; use Atk4\Data\Model\Scope; use Atk4\Data\Model\Scope\Condition; +use Atk4\Data\Model2; use Atk4\Data\Persistence\Sql\Expression; use Atk4\Data\Schema\TestCase; use Doctrine\DBAL\Platforms\SqlitePlatform; -class SCountry extends Model +class SCountry extends Model2 { public $table = 'country'; public $caption = 'Country'; @@ -31,7 +32,7 @@ protected function init(): void } } -class SUser extends Model +class SUser extends Model2 { public $table = 'user'; public $caption = 'User'; @@ -52,7 +53,7 @@ protected function init(): void } } -class STicket extends Model +class STicket extends Model2 { public $table = 'ticket'; public $caption = 'Ticket'; diff --git a/tests/SerializeTest.php b/tests/SerializeTest.php index d40ab9ced4..edc5b17db4 100644 --- a/tests/SerializeTest.php +++ b/tests/SerializeTest.php @@ -5,14 +5,14 @@ namespace Atk4\Data\Tests; use Atk4\Data\Exception; -use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Schema\TestCase; class SerializeTest extends TestCase { public function testBasicSerialize(): void { - $m = new Model($this->db, ['table' => 'job']); + $m = new Model2($this->db, ['table' => 'job']); $f = $m->addField('data', ['type' => 'object']); @@ -50,7 +50,7 @@ public function testBasicSerialize(): void public function testSerializeErrorJson(): void { - $m = new Model($this->db, ['table' => 'job']); + $m = new Model2($this->db, ['table' => 'job']); $f = $m->addField('data', ['type' => 'json']); @@ -60,7 +60,7 @@ public function testSerializeErrorJson(): void public function testSerializeErrorJson2(): void { - $m = new Model($this->db, ['table' => 'job']); + $m = new Model2($this->db, ['table' => 'job']); $f = $m->addField('data', ['type' => 'json']); @@ -74,7 +74,7 @@ public function testSerializeErrorJson2(): void public function testSerializeErrorSerialize(): void { - $m = new Model($this->db, ['table' => 'job']); + $m = new Model2($this->db, ['table' => 'job']); $this->expectException(Exception::class); $f = $m->addField('data', ['type' => 'object']); diff --git a/tests/SubTypesTest.php b/tests/SubTypesTest.php index 0ca9a3e7a6..0f988f516c 100644 --- a/tests/SubTypesTest.php +++ b/tests/SubTypesTest.php @@ -5,10 +5,11 @@ namespace Atk4\Data\Tests; use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Persistence; use Atk4\Data\Schema\TestCase; -class StAccount extends Model +class StAccount extends Model2 { public $table = 'account'; @@ -70,7 +71,7 @@ public function transferTo(self $account, float $amount): array } } -class StGenericTransaction extends Model +class StGenericTransaction extends Model2 { public $table = 'transaction'; /** @var string */ diff --git a/tests/TransactionTest.php b/tests/TransactionTest.php index f881f348b6..a48786984b 100644 --- a/tests/TransactionTest.php +++ b/tests/TransactionTest.php @@ -5,6 +5,7 @@ namespace Atk4\Data\Tests; use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Schema\TestCase; class TransactionTest extends TestCase @@ -19,7 +20,7 @@ public function testAtomicOperations(): void ], ]); - $m = new Model($this->db, ['table' => 'item']); + $m = new Model2($this->db, ['table' => 'item']); $m->addField('name'); $m = $m->load(2); @@ -56,7 +57,7 @@ public function testBeforeSaveHook(): void ]); // test insert - $m = new Model($this->db, ['table' => 'item']); + $m = new Model2($this->db, ['table' => 'item']); $m->addField('name'); $testCase = $this; $m->onHookShort(Model::HOOK_BEFORE_SAVE, static function (bool $isUpdate) use ($testCase) { @@ -65,7 +66,7 @@ public function testBeforeSaveHook(): void $m->createEntity()->save(['name' => 'Foo']); // test update - $m = new Model($this->db, ['table' => 'item']); + $m = new Model2($this->db, ['table' => 'item']); $m->addField('name'); $m->onHookShort(Model::HOOK_AFTER_SAVE, static function (bool $isUpdate) use ($testCase) { $testCase->assertTrue($isUpdate); @@ -82,7 +83,7 @@ public function testAfterSaveHook(): void ]); // test insert - $m = new Model($this->db, ['table' => 'item']); + $m = new Model2($this->db, ['table' => 'item']); $m->addField('name'); $testCase = $this; $m->onHookShort(Model::HOOK_AFTER_SAVE, static function (bool $isUpdate) use ($testCase) { @@ -91,7 +92,7 @@ public function testAfterSaveHook(): void $m->createEntity()->save(['name' => 'Foo']); // test update - $m = new Model($this->db, ['table' => 'item']); + $m = new Model2($this->db, ['table' => 'item']); $m->addField('name'); $m->onHookShort(Model::HOOK_AFTER_SAVE, static function (bool $isUpdate) use ($testCase) { $testCase->assertTrue($isUpdate); @@ -108,7 +109,7 @@ public function testOnRollbackHook(): void ]); // test insert - $m = new Model($this->db, ['table' => 'item']); + $m = new Model2($this->db, ['table' => 'item']); $m->addField('name'); $m->addField('foo'); diff --git a/tests/TypecastingTest.php b/tests/TypecastingTest.php index 0e8783d3a3..22ff61dbd0 100644 --- a/tests/TypecastingTest.php +++ b/tests/TypecastingTest.php @@ -5,7 +5,7 @@ namespace Atk4\Data\Tests; use Atk4\Data\Exception; -use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Schema\TestCase; use Doctrine\DBAL\Platforms\OraclePlatform; @@ -49,7 +49,7 @@ public function testType(): void date_default_timezone_set('Asia/Seoul'); - $m = new Model($this->db, ['table' => 'types']); + $m = new Model2($this->db, ['table' => 'types']); $m->addField('string', ['type' => 'string']); $m->addField('date', ['type' => 'date']); $m->addField('datetime', ['type' => 'datetime']); @@ -139,7 +139,7 @@ public function testEmptyValues(): void date_default_timezone_set('Asia/Seoul'); - $m = new Model($this->db, ['table' => 'types']); + $m = new Model2($this->db, ['table' => 'types']); $m->addField('string', ['type' => 'string']); $m->addField('notype'); $m->addField('date', ['type' => 'date']); @@ -216,7 +216,7 @@ public function testTypecastNull(): void ]; $this->setDb($dbData); - $m = new Model($this->db, ['table' => 'test']); + $m = new Model2($this->db, ['table' => 'test']); $m->addField('a'); $m->addField('b'); $m->addField('c'); @@ -251,7 +251,7 @@ public function testTypeCustom1(): void date_default_timezone_set('Asia/Seoul'); - $m = new Model($this->db, ['table' => 'types']); + $m = new Model2($this->db, ['table' => 'types']); $m->addField('date', ['type' => 'date']); $m->addField('datetime', ['type' => 'datetime']); @@ -293,7 +293,7 @@ public function testTryLoad(): void ], ]); - $m = new Model($this->db, ['table' => 'types']); + $m = new Model2($this->db, ['table' => 'types']); $m->addField('date', ['type' => 'date']); @@ -312,7 +312,7 @@ public function testTryLoadAny(): void ], ]); - $m = new Model($this->db, ['table' => 'types']); + $m = new Model2($this->db, ['table' => 'types']); $m->addField('date', ['type' => 'date']); @@ -331,7 +331,7 @@ public function testTryLoadBy(): void ], ]); - $m = new Model($this->db, ['table' => 'types']); + $m = new Model2($this->db, ['table' => 'types']); $m->addField('date', ['type' => 'date']); @@ -350,7 +350,7 @@ public function testLoadBy(): void ], ]); - $m = new Model($this->db, ['table' => 'types']); + $m = new Model2($this->db, ['table' => 'types']); $m->addField('date', ['type' => 'date']); $m2 = $m->loadOne(); @@ -368,7 +368,7 @@ public function testLoadBy(): void public function testTypecastTimezone(): void { - $m = new Model($this->db, ['table' => 'event']); + $m = new Model2($this->db, ['table' => 'event']); $dt = $m->addField('dt', ['type' => 'datetime', 'persist_timezone' => 'EEST']); $d = $m->addField('d', ['type' => 'date', 'persist_timezone' => 'EEST']); $t = $m->addField('t', ['type' => 'time', 'persist_timezone' => 'EEST']); @@ -415,7 +415,7 @@ public function testTimestamp(): void ], ]); - $m = new Model($this->db, ['table' => 'types']); + $m = new Model2($this->db, ['table' => 'types']); $m->addField('ts', ['actual' => 'date', 'type' => 'datetime']); $m = $m->loadOne(); @@ -435,7 +435,7 @@ public function testBadTimestamp(): void ], ]); - $m = new Model($this->db, ['table' => 'types']); + $m = new Model2($this->db, ['table' => 'types']); $m->addField('ts', ['actual' => 'date', 'type' => 'datetime']); $this->expectException(Exception::class); $m = $m->loadOne(); @@ -453,7 +453,7 @@ public function testDirtyTimestamp(): void ], ]); - $m = new Model($this->db, ['table' => 'types']); + $m = new Model2($this->db, ['table' => 'types']); $m->addField('ts', ['actual' => 'date', 'type' => 'datetime']); $m = $m->loadOne(); $m->set('ts', clone $m->get('ts')); @@ -471,7 +471,7 @@ public function testTimestampSave(): void ], ]); - $m = new Model($this->db, ['table' => 'types']); + $m = new Model2($this->db, ['table' => 'types']); $m->addField('ts', ['actual' => 'date', 'type' => 'date']); $m = $m->loadOne(); $m->set('ts', new \DateTime('2012-02-30')); @@ -483,7 +483,7 @@ public function testTimestampSave(): void public function testIntegerSave(): void { - $m = new Model($this->db, ['table' => 'types']); + $m = new Model2($this->db, ['table' => 'types']); $m->addField('i', ['type' => 'integer']); $m = $m->createEntity(); @@ -500,7 +500,7 @@ public function testIntegerSave(): void $this->assertSame([], $m->getDirtyRef()); // same test without type integer - $m = new Model($this->db, ['table' => 'types']); + $m = new Model2($this->db, ['table' => 'types']); $m->addField('i'); $m = $m->createEntity(); @@ -533,7 +533,7 @@ public function testDirtyTime(): void ], ]); - $m = new Model($this->db, ['table' => 'types']); + $m = new Model2($this->db, ['table' => 'types']); $m->addField('ts', ['actual' => 'date', 'type' => 'time']); $m = $m->loadOne(); @@ -560,7 +560,7 @@ public function testDirtyTimeAfterSave(): void ], ]); - $m = new Model($this->db, ['table' => 'types']); + $m = new Model2($this->db, ['table' => 'types']); $m->addField('ts', ['actual' => 'date', 'type' => 'time']); $m = $m->loadOne(); diff --git a/tests/UserActionTest.php b/tests/UserActionTest.php index 7caacf7a30..7239177d48 100644 --- a/tests/UserActionTest.php +++ b/tests/UserActionTest.php @@ -5,6 +5,7 @@ namespace Atk4\Data\Tests; use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Persistence; use Atk4\Data\Schema\TestCase; @@ -23,7 +24,7 @@ public function backup_clients(): string } } -class UaClient extends Model +class UaClient extends Model2 { use UaReminder; diff --git a/tests/Util/DeepCopyTest.php b/tests/Util/DeepCopyTest.php index 007a705cd7..071a3e7cf5 100644 --- a/tests/Util/DeepCopyTest.php +++ b/tests/Util/DeepCopyTest.php @@ -4,13 +4,13 @@ namespace Atk4\Data\Tests\Util; -use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Schema\TestCase; use Atk4\Data\Util\DeepCopy; use Atk4\Data\Util\DeepCopyException; use Doctrine\DBAL\Platforms\SQLServerPlatform; -class DcClient extends Model +class DcClient extends Model2 { public $table = 'client'; @@ -26,7 +26,7 @@ protected function init(): void } } -class DcInvoice extends Model +class DcInvoice extends Model2 { public $table = 'invoice'; @@ -56,7 +56,7 @@ protected function init(): void } } -class DcQuote extends Model +class DcQuote extends Model2 { public $table = 'quote'; @@ -74,7 +74,7 @@ protected function init(): void } } -class DcInvoiceLine extends Model +class DcInvoiceLine extends Model2 { public $table = 'line'; @@ -97,7 +97,7 @@ protected function init(): void } } -class DcQuoteLine extends Model +class DcQuoteLine extends Model2 { public $table = 'line'; @@ -120,7 +120,7 @@ protected function init(): void } } -class DcPayment extends Model +class DcPayment extends Model2 { public $table = 'payment'; diff --git a/tests/ValidationTest.php b/tests/ValidationTest.php index 9a6deab1c2..80f93a175f 100644 --- a/tests/ValidationTest.php +++ b/tests/ValidationTest.php @@ -6,10 +6,11 @@ use Atk4\Core\Phpunit\TestCase; use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Persistence; use Atk4\Data\ValidationException; -class MyValidationModel extends Model +class MyValidationModel extends Model2 { protected function init(): void { @@ -33,7 +34,7 @@ public function validate(string $intent = null): array } } -class BadValidationModel extends Model +class BadValidationModel extends Model2 { protected function init(): void { diff --git a/tests/WithTest.php b/tests/WithTest.php index 3d88973624..266d22d34f 100644 --- a/tests/WithTest.php +++ b/tests/WithTest.php @@ -6,6 +6,7 @@ use Atk4\Data\Exception; use Atk4\Data\Model; +use Atk4\Data\Model2; use Atk4\Data\Schema\TestCase; class WithTest extends TestCase @@ -25,11 +26,11 @@ public function testWith(): void ]); // setup models - $m_user = new Model($this->db, ['table' => 'user']); + $m_user = new Model2($this->db, ['table' => 'user']); $m_user->addField('name'); $m_user->addField('salary', ['type' => 'integer']); - $m_invoice = new Model($this->db, ['table' => 'invoice']); + $m_invoice = new Model2($this->db, ['table' => 'invoice']); $m_invoice->addField('net', ['type' => 'integer']); $m_invoice->hasOne('user_id', ['model' => $m_user]); $m_invoice->addCondition('net', '>', 100); @@ -55,8 +56,8 @@ public function testWith(): void public function testUniqueAliasException(): void { - $m1 = new Model(); - $m2 = new Model(); + $m1 = new Model2(); + $m2 = new Model2(); $m1->addWith($m2, 't'); $this->expectException(Exception::class); $m1->addWith($m2, 't');