@@ -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