Skip to content

Commit 0a38b16

Browse files
committed
Adding migration tests
1 parent e7a932d commit 0a38b16

File tree

13 files changed

+646
-156
lines changed

13 files changed

+646
-156
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
3+
namespace Tests\Fixtures;
4+
5+
class MigrationWrapper extends \PHPFUI\ORM\Migration
6+
{
7+
public function addColumnTest(string $table, string $field, string $parameters) : bool
8+
{
9+
return $this->addColumn($table, $field, $parameters);
10+
}
11+
12+
/**
13+
* @param array<string> $columns
14+
*/
15+
public function addForeignKeyTest(string $toTable, string $referenceTable, array $columns, string $onDelete = 'CASCADE', string $onUpdate = 'CASCADE') : bool
16+
{
17+
return $this->addForeignKey($toTable, $referenceTable, $columns, $onDelete, $onUpdate);
18+
}
19+
20+
/**
21+
* @param array<string>|string $fields
22+
*/
23+
public function addIndexTest(string $table, string | array $fields, string $indexType = '') : bool
24+
{
25+
return $this->addIndex($table, $fields, $indexType);
26+
}
27+
28+
public function addPrimaryKeyAutoIncrementTest(string $table, string $field = '', string $newFieldName = '') : bool
29+
{
30+
return $this->addPrimaryKeyAutoIncrement($table, $field, $newFieldName);
31+
}
32+
33+
/**
34+
* @param array<string> $fields
35+
*/
36+
public function addPrimaryKeyTest(string $table, array $fields) : bool
37+
{
38+
return $this->addPrimaryKey($table, $fields);
39+
}
40+
41+
public function alterColumnTest(string $table, string $field, string $parameters) : bool
42+
{
43+
return $this->alterColumn($table, $field, $parameters);
44+
}
45+
46+
public function renameColumnTest(string $table, string $field, string $newName) : bool
47+
{
48+
return $this->renameColumn($table, $field, $newName);
49+
}
50+
51+
/**
52+
* @param array<string> $keys
53+
*/
54+
public function deleteDuplicateRowsTest(string $table, array $keys) : bool
55+
{
56+
return $this->deleteDuplicateRows($table, $keys);
57+
}
58+
59+
public function down() : bool
60+
{
61+
return true;
62+
}
63+
64+
public function dropAllIndexesTest(string $table) : void
65+
{
66+
$this->dropAllIndexes($table);
67+
}
68+
69+
public function dropColumnTest(string $table, string $field) : bool
70+
{
71+
return $this->dropColumn($table, $field);
72+
}
73+
74+
/**
75+
* @param array<string> | string $columns
76+
*/
77+
public function dropForeignKeyTest(string $table, string | array $columns) : bool
78+
{
79+
return $this->dropForeignKey($table, $columns);
80+
}
81+
82+
/**
83+
* @param array<string>|string $fields
84+
*/
85+
public function dropIndexTest(string $table, string | array $fields) : bool
86+
{
87+
return $this->dropIndex($table, $fields);
88+
}
89+
90+
public function dropPrimaryKeyTest(string $table) : bool
91+
{
92+
return $this->dropPrimaryKey($table);
93+
}
94+
95+
/**
96+
* @param array<string> $tables
97+
*/
98+
public function dropTablesTest(array $tables) : void
99+
{
100+
$this->dropTables($tables);
101+
}
102+
103+
public function dropTableTest(string $table) : bool
104+
{
105+
return $this->dropTable($table);
106+
}
107+
108+
public function indexExistsTest(string $table, string $indexName) : bool
109+
{
110+
return $this->indexExists($table, $indexName);
111+
}
112+
113+
public function renameTableTest(string $oldName, string $newName) : bool
114+
{
115+
return $this->renameTable($oldName, $newName);
116+
}
117+
118+
public function up() : bool
119+
{
120+
return true;
121+
}
122+
}

Tests/Unit/InsertTest.php

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,84 @@ public function testDateRequiredInsert() : void
3636

3737
}
3838

39+
public function testInsertOrIgnore() : void
40+
{
41+
$transaction = new \PHPFUI\ORM\Transaction();
42+
$customerTable = new \Tests\App\Table\Customer();
43+
$this->assertEquals(29, $customerTable->count());
44+
45+
$customer = new \Tests\App\Record\Customer();
46+
$customer->address = '123 Broadway';
47+
$customer->business_phone = '212-987-6543';
48+
$customer->city = 'New York';
49+
$customer->company = 'PHPFUI';
50+
$customer->country_region = 'USA';
51+
$customer->email_address = 'bruce@phpfui.com';
52+
$customer->fax_number = '212-345-6789';
53+
$customer->first_name = 'Bruce';
54+
$customer->home_phone = '987-654-3210';
55+
$customer->job_title = 'Head Honcho';
56+
$customer->last_name = 'Wells';
57+
$customer->mobile_phone = '123-456-7890';
58+
$customer->state_province = 'NY';
59+
$customer->web_page = 'http://www.phpfui.com';
60+
$customer->zip_postal_code = '12345';
61+
$id = $customer->insertOrIgnore();
62+
$this->assertGreaterThan(0, $id);
63+
$this->assertEquals(30, $customerTable->count());
64+
65+
$newCustomer = new \Tests\App\Record\Customer($id);
66+
$this->assertEquals('12345', $newCustomer->zip_postal_code);
67+
$newCustomer->zip_postal_code = '54321';
68+
$result = $newCustomer->insertOrIgnore();
69+
$this->assertEquals(0, $result);
70+
$this->assertEmpty(\PHPFUI\ORM::getLastError());
71+
72+
$updatedCustomer = new \Tests\App\Record\Customer($id);
73+
$this->assertEquals('12345', $updatedCustomer->zip_postal_code);
74+
$this->assertTrue($transaction->rollBack());
75+
$this->assertEquals(29, $customerTable->count());
76+
}
77+
78+
public function testInsertOrUpdate() : void
79+
{
80+
$transaction = new \PHPFUI\ORM\Transaction();
81+
$customerTable = new \Tests\App\Table\Customer();
82+
$this->assertEquals(29, $customerTable->count());
83+
84+
$customer = new \Tests\App\Record\Customer();
85+
$customer->address = '123 Broadway';
86+
$customer->business_phone = '212-987-6543';
87+
$customer->city = 'New York';
88+
$customer->company = 'PHPFUI';
89+
$customer->country_region = 'USA';
90+
$customer->email_address = 'bruce@phpfui.com';
91+
$customer->fax_number = '212-345-6789';
92+
$customer->first_name = 'Bruce';
93+
$customer->home_phone = '987-654-3210';
94+
$customer->job_title = 'Head Honcho';
95+
$customer->last_name = 'Wells';
96+
$customer->mobile_phone = '123-456-7890';
97+
$customer->state_province = 'NY';
98+
$customer->web_page = 'http://www.phpfui.com';
99+
$customer->zip_postal_code = '12345';
100+
$id = $customer->insertOrUpdate();
101+
$this->assertGreaterThan(0, $id);
102+
$this->assertEquals(30, $customerTable->count());
103+
104+
$newCustomer = new \Tests\App\Record\Customer($id);
105+
$this->assertEquals('12345', $newCustomer->zip_postal_code);
106+
$newCustomer->zip_postal_code = '54321';
107+
$result = $newCustomer->insertOrUpdate();
108+
$this->assertGreaterThan(0, $result);
109+
$this->assertEquals(30, $customerTable->count());
110+
111+
$updatedCustomer = new \Tests\App\Record\Customer($id);
112+
$this->assertEquals('54321', $updatedCustomer->zip_postal_code);
113+
$this->assertTrue($transaction->rollBack());
114+
$this->assertEquals(29, $customerTable->count());
115+
}
116+
39117
public function testMultipleInserts() : void
40118
{
41119
$transaction = new \PHPFUI\ORM\Transaction();
@@ -216,82 +294,4 @@ public function testStringNullInsert() : void
216294
$this->assertEquals('default', $insertedTest->stringDefaultNotNull);
217295
$this->assertTrue($transaction->rollBack());
218296
}
219-
220-
public function testInsertOrUpdate() : void
221-
{
222-
$transaction = new \PHPFUI\ORM\Transaction();
223-
$customerTable = new \Tests\App\Table\Customer();
224-
$this->assertEquals(29, $customerTable->count());
225-
226-
$customer = new \Tests\App\Record\Customer();
227-
$customer->address = '123 Broadway';
228-
$customer->business_phone = '212-987-6543';
229-
$customer->city = 'New York';
230-
$customer->company = 'PHPFUI';
231-
$customer->country_region = 'USA';
232-
$customer->email_address = 'bruce@phpfui.com';
233-
$customer->fax_number = '212-345-6789';
234-
$customer->first_name = 'Bruce';
235-
$customer->home_phone = '987-654-3210';
236-
$customer->job_title = 'Head Honcho';
237-
$customer->last_name = 'Wells';
238-
$customer->mobile_phone = '123-456-7890';
239-
$customer->state_province = 'NY';
240-
$customer->web_page = 'http://www.phpfui.com';
241-
$customer->zip_postal_code = '12345';
242-
$id = $customer->insertOrUpdate();
243-
$this->assertGreaterThan(0, $id);
244-
$this->assertEquals(30, $customerTable->count());
245-
246-
$newCustomer = new \Tests\App\Record\Customer($id);
247-
$this->assertEquals('12345', $newCustomer->zip_postal_code);
248-
$newCustomer->zip_postal_code = '54321';
249-
$result = $newCustomer->insertOrUpdate();
250-
$this->assertGreaterThan(0, $result);
251-
$this->assertEquals(30, $customerTable->count());
252-
253-
$updatedCustomer = new \Tests\App\Record\Customer($id);
254-
$this->assertEquals('54321', $updatedCustomer->zip_postal_code);
255-
$this->assertTrue($transaction->rollBack());
256-
$this->assertEquals(29, $customerTable->count());
257-
}
258-
259-
public function testInsertOrIgnore() : void
260-
{
261-
$transaction = new \PHPFUI\ORM\Transaction();
262-
$customerTable = new \Tests\App\Table\Customer();
263-
$this->assertEquals(29, $customerTable->count());
264-
265-
$customer = new \Tests\App\Record\Customer();
266-
$customer->address = '123 Broadway';
267-
$customer->business_phone = '212-987-6543';
268-
$customer->city = 'New York';
269-
$customer->company = 'PHPFUI';
270-
$customer->country_region = 'USA';
271-
$customer->email_address = 'bruce@phpfui.com';
272-
$customer->fax_number = '212-345-6789';
273-
$customer->first_name = 'Bruce';
274-
$customer->home_phone = '987-654-3210';
275-
$customer->job_title = 'Head Honcho';
276-
$customer->last_name = 'Wells';
277-
$customer->mobile_phone = '123-456-7890';
278-
$customer->state_province = 'NY';
279-
$customer->web_page = 'http://www.phpfui.com';
280-
$customer->zip_postal_code = '12345';
281-
$id = $customer->insertOrIgnore();
282-
$this->assertGreaterThan(0, $id);
283-
$this->assertEquals(30, $customerTable->count());
284-
285-
$newCustomer = new \Tests\App\Record\Customer($id);
286-
$this->assertEquals('12345', $newCustomer->zip_postal_code);
287-
$newCustomer->zip_postal_code = '54321';
288-
$result = $newCustomer->insertOrIgnore();
289-
$this->assertEquals(0, $result);
290-
$this->assertEmpty(\PHPFUI\ORM::getLastError());
291-
292-
$updatedCustomer = new \Tests\App\Record\Customer($id);
293-
$this->assertEquals('12345', $updatedCustomer->zip_postal_code);
294-
$this->assertTrue($transaction->rollBack());
295-
$this->assertEquals(29, $customerTable->count());
296-
}
297297
}

0 commit comments

Comments
 (0)