Skip to content

Commit 3b32ee8

Browse files
committed
Update tests and schemas
1 parent 51e263d commit 3b32ee8

21 files changed

+280
-86
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Tests\Fixtures\Record\Definition;
4+
5+
/**
6+
* Autogenerated. Do not modify. Modify SQL table, then generate with \PHPFUI\ORM\Tool\Generate\CRUD class.
7+
*
8+
* @property ?int $approved_by MySQL type int
9+
* @property ?string $approved_date MySQL type datetime
10+
* @property ?int $created_by MySQL type int
11+
* @property string $creation_date MySQL type datetime
12+
* @property ?string $expected_date MySQL type datetime
13+
* @property ?string $notes MySQL type longtext
14+
* @property ?float $payment_amount MySQL type decimal(19,4)
15+
* @property ?string $payment_date MySQL type datetime
16+
* @property ?string $payment_method MySQL type varchar(50)
17+
* @property int $purchase_order_id MySQL type int
18+
* @property ?int $purchase_order_status_id MySQL type int
19+
* @property float $shipping_fee MySQL type decimal(19,4)
20+
* @property ?int $submitted_by MySQL type int
21+
* @property ?string $submitted_date MySQL type datetime
22+
* @property ?int $supplier_id MySQL type int
23+
* @property float $taxes MySQL type decimal(19,4)
24+
*/
25+
abstract class PurchaseOrder extends \PHPFUI\ORM\Record
26+
{
27+
protected static bool $autoIncrement = true;
28+
29+
/** @var array<string, \PHPFUI\ORM\FieldDefinition> */
30+
protected static array $fields = [];
31+
32+
/** @var array<string> */
33+
protected static array $primaryKeys = ['purchase_order_id', ];
34+
35+
protected static string $table = 'purchase_order';
36+
37+
public function initFieldDefinitions() : static
38+
{
39+
if (! \count(static::$fields))
40+
{
41+
static::$fields = [
42+
'approved_by' => new \PHPFUI\ORM\FieldDefinition('int', 'int', 0, true, ),
43+
'approved_date' => new \PHPFUI\ORM\FieldDefinition('datetime', 'string', 20, true, ),
44+
'created_by' => new \PHPFUI\ORM\FieldDefinition('int', 'int', 0, true, ),
45+
'creation_date' => new \PHPFUI\ORM\FieldDefinition('datetime', 'string', 20, false, 'CURRENT_TIMESTAMP', ),
46+
'expected_date' => new \PHPFUI\ORM\FieldDefinition('datetime', 'string', 20, true, ),
47+
'notes' => new \PHPFUI\ORM\FieldDefinition('longtext', 'string', 4294967295, true, ),
48+
'payment_amount' => new \PHPFUI\ORM\FieldDefinition('decimal(19,4)', 'float', 20, true, 0.0000, ),
49+
'payment_date' => new \PHPFUI\ORM\FieldDefinition('datetime', 'string', 20, true, ),
50+
'payment_method' => new \PHPFUI\ORM\FieldDefinition('varchar(50)', 'string', 50, true, ),
51+
'purchase_order_id' => new \PHPFUI\ORM\FieldDefinition('int', 'int', 0, false, ),
52+
'purchase_order_status_id' => new \PHPFUI\ORM\FieldDefinition('int', 'int', 0, true, 0, ),
53+
'shipping_fee' => new \PHPFUI\ORM\FieldDefinition('decimal(19,4)', 'float', 20, false, 0.0000, ),
54+
'submitted_by' => new \PHPFUI\ORM\FieldDefinition('int', 'int', 0, true, ),
55+
'submitted_date' => new \PHPFUI\ORM\FieldDefinition('datetime', 'string', 20, true, ),
56+
'supplier_id' => new \PHPFUI\ORM\FieldDefinition('int', 'int', 0, true, ),
57+
'taxes' => new \PHPFUI\ORM\FieldDefinition('decimal(19,4)', 'float', 20, false, 0.0000, ),
58+
];
59+
}
60+
61+
return $this;
62+
}
63+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Tests\Fixtures\Record\Definition;
4+
5+
/**
6+
* Autogenerated. Do not modify. Modify SQL table, then generate with \PHPFUI\ORM\Tool\Generate\CRUD class.
7+
*
8+
* @property ?string $date_received MySQL type datetime
9+
* @property ?int $inventory_transaction_id MySQL type int
10+
* @property \Tests\App\Record\InventoryTransaction $inventory_transaction related record
11+
* @property int $posted_to_inventory MySQL type int
12+
* @property ?int $product_id MySQL type int
13+
* @property \Tests\App\Record\Product $product related record
14+
* @property int $purchase_order_detail_id MySQL type int
15+
* @property int $purchase_order_id MySQL type int
16+
* @property \Tests\App\Record\PurchaseOrder $purchase_order related record
17+
* @property float $quantity MySQL type decimal(18,4)
18+
* @property float $unit_cost MySQL type decimal(19,4)
19+
*/
20+
abstract class PurchaseOrderDetail extends \PHPFUI\ORM\Record
21+
{
22+
protected static bool $autoIncrement = true;
23+
24+
/** @var array<string, \PHPFUI\ORM\FieldDefinition> */
25+
protected static array $fields = [];
26+
27+
/** @var array<string> */
28+
protected static array $primaryKeys = ['purchase_order_detail_id', ];
29+
30+
protected static string $table = 'purchase_order_detail';
31+
32+
public function initFieldDefinitions() : static
33+
{
34+
if (! \count(static::$fields))
35+
{
36+
static::$fields = [
37+
'date_received' => new \PHPFUI\ORM\FieldDefinition('datetime', 'string', 20, true, ),
38+
'inventory_transaction_id' => new \PHPFUI\ORM\FieldDefinition('int', 'int', 0, true, ),
39+
'posted_to_inventory' => new \PHPFUI\ORM\FieldDefinition('int', 'int', 0, false, 0, ),
40+
'product_id' => new \PHPFUI\ORM\FieldDefinition('int', 'int', 0, true, ),
41+
'purchase_order_detail_id' => new \PHPFUI\ORM\FieldDefinition('int', 'int', 0, false, ),
42+
'purchase_order_id' => new \PHPFUI\ORM\FieldDefinition('int', 'int', 0, false, ),
43+
'quantity' => new \PHPFUI\ORM\FieldDefinition('decimal(18,4)', 'float', 19, false, ),
44+
'unit_cost' => new \PHPFUI\ORM\FieldDefinition('decimal(19,4)', 'float', 20, false, ),
45+
];
46+
}
47+
48+
return $this;
49+
}
50+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Tests\Fixtures\Record;
4+
5+
class PurchaseOrder extends \Tests\Fixtures\Record\Definition\PurchaseOrder
6+
{
7+
protected static array $virtualFields = [
8+
'purchaseOrderDetailChildren' => [\PHPFUI\ORM\Children::class, \Tests\Fixtures\Table\PurchaseOrderDetail::class, 'purchase_order_detail_id'],
9+
'submitted_date' => [\PHPFUI\ORM\Cast::class, \Carbon\Carbon::class],
10+
'creation_date' => [\PHPFUI\ORM\Cast::class, \Carbon\Carbon::class],
11+
'expected_date' => [\PHPFUI\ORM\Cast::class, \Carbon\Carbon::class],
12+
'payment_date' => [\PHPFUI\ORM\Cast::class, \Carbon\Carbon::class],
13+
'approved_date' => [\PHPFUI\ORM\Cast::class, \Carbon\Carbon::class],
14+
];
15+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Tests\Fixtures\Record;
4+
5+
class PurchaseOrderDetail extends \Tests\Fixtures\Record\Definition\PurchaseOrderDetail
6+
{
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Tests\Fixtures\Table;
4+
5+
class PurchaseOrder extends \PHPFUI\ORM\Table
6+
{
7+
protected static string $className = \Tests\Fixturesw\Record\PurchaseOrder::class;
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Tests\Fixtures\Table;
4+
5+
class PurchaseOrderDetail extends \PHPFUI\ORM\Table
6+
{
7+
protected static string $className = \Tests\Fixtures\Record\PurchaseOrderDetail::class;
8+
}

Tests/Unit/ChildrenTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ public function testChildren() : void
88
{
99
$order = new \Tests\Fixtures\Record\Order(44);
1010
$this->assertTrue($order->loaded());
11+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
1112
$orderDetails = $order->orderDetailChildren;
1213
$this->assertCount(3, $orderDetails);
14+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
1315
$this->assertEquals(25.0 * 18.0, $orderDetails->current()->gross);
1416
}
1517
}

Tests/Unit/ConstructTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ public function testArrayConstruct() : void
99
$sales_report = new \Tests\App\Record\SalesReport(['group_by' => 'Category', 'title' => 'Sales By Category']);
1010
$this->assertFalse($sales_report->empty());
1111
$this->assertTrue($sales_report->loaded());
12+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
1213
$this->assertEquals('SELECT DISTINCT [Category] FROM [products] ORDER BY [Category];', $sales_report->filter_row_source);
1314
}
1415

1516
public function testDataObjectConstruct() : void
1617
{
1718
$order = new \Tests\App\Record\Order(30);
19+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
1820
$this->assertFalse($order->empty());
1921
$this->assertTrue($order->loaded());
2022
$this->assertEquals('Karen Toh', $order->ship_name);
@@ -24,6 +26,7 @@ public function testDataObjectConstruct() : void
2426
$dataObject = new \PHPFUI\ORM\DataObject($data);
2527
$this->assertFalse($dataObject->empty());
2628
$clonedOrder = new \Tests\App\Record\Order($dataObject);
29+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
2730
$this->assertFalse($clonedOrder->empty());
2831
$this->assertFalse($clonedOrder->loaded());
2932
$this->assertEquals('Karen Toh', $clonedOrder->ship_name);
@@ -48,15 +51,14 @@ public function testIntConstruct() : void
4851
$this->assertFalse($order->empty());
4952
$this->assertTrue($order->loaded());
5053
$this->assertEquals('Karen Toh', $order->ship_name);
51-
//INSERT INTO 'order' ('order_id', 'employee_id', 'customer_id', 'order_date', 'shipped_date', 'shipper_id', 'ship_name', 'ship_address', 'ship_city', 'ship_state_province', 'ship_zip_postal_code', 'ship_country_region', 'shipping_fee', 'taxes', 'payment_type', 'paid_date', 'notes', 'tax_rate', 'order_tax_status_id', 'order_status_id') VALUES
52-
//(30, 9, 27, '2006-01-15 00:00:00', '2006-01-22 00:00:00', 2, 'Karen Toh', '789 27th Street', 'Las Vegas', 'NV', '99999', 'USA', 200, 0, 'Check', '2006-01-15 00:00:00', NULL, 0, NULL, 3);
5354
}
5455

5556
public function testRecordConstruct() : void
5657
{
5758
$order = new \Tests\App\Record\Order(30);
5859
$this->assertFalse($order->empty());
5960
$this->assertTrue($order->loaded());
61+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
6062
$this->assertEquals('Karen Toh', $order->ship_name);
6163
$clonedOrder = new \Tests\App\Record\Order($order);
6264
$this->assertFalse($clonedOrder->empty());
@@ -72,6 +74,7 @@ public function testStringConstruct() : void
7274
$order = new \Tests\App\Record\Order('30');
7375
$this->assertFalse($order->empty());
7476
$this->assertTrue($order->loaded());
77+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
7578
$this->assertEquals('Karen Toh', $order->ship_name);
7679
}
7780
}

Tests/Unit/DeleteTest.php

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,60 @@ class DeleteTest extends \PHPUnit\Framework\TestCase
66
{
77
public function testDeleteChildren() : void
88
{
9-
$order = new \Tests\Fixtures\Record\Order(31);
10-
$this->assertCount(3, $order->orderDetailChildren);
119
$transaction = new \PHPFUI\ORM\Transaction();
12-
$orderDetailTable = new \Tests\Fixtures\Table\OrderDetail();
13-
$orderDetailTable->setWhere(new \PHPFUI\ORM\Condition('order_id', 31));
14-
$this->assertCount(3, $orderDetailTable);
15-
$order->delete();
16-
$this->assertCount(0, $orderDetailTable);
10+
$purchaseOrder = new \Tests\Fixtures\Record\PurchaseOrder(93);
11+
$this->assertCount(3, $purchaseOrder->purchaseOrderDetailChildren);
12+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
13+
$purchaseOrderDetailTable = new \Tests\Fixtures\Table\PurchaseOrderDetail();
14+
$purchaseOrderDetailTable->setWhere(new \PHPFUI\ORM\Condition('purchase_order_id', 93));
15+
$this->assertCount(3, $purchaseOrderDetailTable);
16+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
17+
$purchaseOrder->delete();
18+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
19+
$this->assertCount(0, $purchaseOrderDetailTable);
20+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
1721
$this->assertTrue($transaction->rollBack());
18-
$order = new \Tests\Fixtures\Record\Order(31);
19-
$this->assertTrue($order->loaded(), 'Order 31 was not reloaded after rollback');
20-
$this->assertCount(3, $order->orderDetailChildren);
22+
$purchaseOrder = new \Tests\Fixtures\Record\PurchaseOrder(93);
23+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
24+
$this->assertTrue($purchaseOrder->loaded());
25+
$this->assertCount(3, $purchaseOrder->purchaseOrderDetailChildren);
26+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
2127
}
2228

2329
public function testRecordDelete() : void
2430
{
25-
$table = new \Tests\App\Table\Customer();
26-
$this->assertEquals(29, $table->count());
2731
$transaction = new \PHPFUI\ORM\Transaction();
28-
$customer = new \Tests\App\Record\Customer(9);
29-
$this->assertEquals('Company I', $customer->company);
30-
$customer->delete();
31-
$this->assertEquals(28, $table->count());
32-
$this->assertTrue($transaction->rollBack());
33-
$this->assertEquals(29, $table->count());
32+
$table = new \Tests\App\Table\PurchaseOrderDetail();
33+
$this->assertEquals(55, $table->count());
34+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
35+
$purchaseorderdetail = new \Tests\App\Record\PurchaseOrderDetail(245);
36+
$this->assertEquals('2006-01-22 00:00:00', $purchaseorderdetail->date_received);
37+
$purchaseorderdetail->delete();
38+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
39+
$this->assertEquals(54, $table->count());
40+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
41+
$this->assertTrue($transaction->rollback());
42+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
43+
$this->assertEquals(55, $table->count());
44+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
3445
}
3546

3647
public function testTableDelete() : void
3748
{
38-
$table = new \Tests\App\Table\Customer();
39-
$this->assertEquals(29, $table->count());
4049
$transaction = new \PHPFUI\ORM\Transaction();
41-
$table->setWhere(new \PHPFUI\ORM\Condition('customer_id', 9));
50+
$table = new \Tests\App\Table\PurchaseOrderDetail();
51+
$this->assertEquals(55, $table->count());
52+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
53+
$table->setWhere(new \PHPFUI\ORM\Condition('purchase_order_detail_id', 9));
4254
$table->delete();
55+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
4356
$this->assertEquals(0, $table->count());
44-
$table = new \Tests\App\Table\Customer();
45-
$this->assertEquals(28, $table->count());
57+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
58+
$table = new \Tests\App\Table\PurchaseOrderDetail();
59+
$this->assertEquals(55, $table->count());
60+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
4661
$this->assertTrue($transaction->rollBack());
47-
$this->assertEquals(29, $table->count());
62+
$this->assertEquals(55, $table->count());
63+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
4864
}
4965
}

Tests/Unit/ExplainTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public function testExplainGroupBy() : void
1313
$table->addGroupBy('category');
1414
$table->addOrderBy('count', 'desc');
1515
$this->assertGreaterThan(0, \count($table->getExplainRows()));
16+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
1617
}
1718

1819
public function testExplainIn() : void
@@ -21,9 +22,11 @@ public function testExplainIn() : void
2122
$orderDetailTable->setWhere(new \PHPFUI\ORM\Condition('quantity', 10));
2223
$orderDetailTable->addSelect('order_id');
2324
$this->assertGreaterThan(0, \count($orderDetailTable->getExplainRows()));
25+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
2426
$orderTable = new \Tests\App\Table\Order();
2527
$orderTable->setWhere(new \PHPFUI\ORM\Condition('order_id', $orderDetailTable, new \PHPFUI\ORM\Operator\In()));
2628
$this->assertGreaterThan(0, \count($orderTable->getExplainRows()));
29+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
2730
}
2831

2932
public function testExplainJoin() : void
@@ -36,6 +39,7 @@ public function testExplainJoin() : void
3639

3740
$table->setLimit(10);
3841
$this->assertGreaterThan(0, \count($table->getExplainRows()));
42+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
3943
}
4044

4145
public function testExplainNotIn() : void
@@ -44,9 +48,11 @@ public function testExplainNotIn() : void
4448
$orderDetailTable->setWhere(new \PHPFUI\ORM\Condition('quantity', 10));
4549
$orderDetailTable->addSelect('order_id');
4650
$this->assertGreaterThan(0, \count($orderDetailTable->getExplainRows()));
51+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
4752
$orderTable = new \Tests\App\Table\Order();
4853
$orderTable->setWhere(new \PHPFUI\ORM\Condition('order_id', $orderDetailTable, new \PHPFUI\ORM\Operator\NotIn()));
4954
$this->assertGreaterThan(0, \count($orderTable->getExplainRows()));
55+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
5056
}
5157

5258
public function testExplainUnion() : void
@@ -60,28 +66,34 @@ public function testExplainUnion() : void
6066
$table->addUnion(new \Tests\App\Table\PurchaseOrderStatus());
6167
$table->addOrderBy('name');
6268
$this->assertGreaterThan(0, \count($table->getExplainRows()));
69+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
6370
}
6471

6572
public function testExplainWhere() : void
6673
{
6774
$table = new \Tests\App\Table\Customer();
6875
$table->setWhere(new \PHPFUI\ORM\Condition('job_title', 'Purchasing Manager'));
6976
$this->assertGreaterThan(0, \count($table->getExplainRows()));
77+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
7078

7179
$table->setWhere(new \PHPFUI\ORM\Condition('job_title', '%Purchasing%', new \PHPFUI\ORM\Operator\Like()));
7280
$this->assertGreaterThan(0, \count($table->getExplainRows()));
81+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
7382

7483
$table->setWhere(new \PHPFUI\ORM\Condition('job_title', '%Purchasing%', new \PHPFUI\ORM\Operator\NotLike()));
7584
$this->assertGreaterThan(0, \count($table->getExplainRows()));
85+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
7686

7787
$condition = new \PHPFUI\ORM\Condition('job_title', '%Purchasing%', new \PHPFUI\ORM\Operator\Like());
7888
$condition->and(new \PHPFUI\ORM\Condition('state_province', 'NY'));
7989
$table->setWhere($condition);
8090
$this->assertGreaterThan(0, \count($table->getExplainRows()));
91+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
8192

8293
$condition = new \PHPFUI\ORM\Condition('job_title', '%Purchasing%', new \PHPFUI\ORM\Operator\NotLike());
8394
$condition->or(new \PHPFUI\ORM\Condition('state_province', 'NY'));
8495
$table->setWhere($condition);
8596
$this->assertGreaterThan(0, \count($table->getExplainRows()));
97+
$this->assertEquals('', \PHPFUI\ORM::getLastError());
8698
}
8799
}

0 commit comments

Comments
 (0)