From 8fadb56fb7b7713b89e8fc92d39373ce5c448795 Mon Sep 17 00:00:00 2001 From: Zac Spitzer Date: Sat, 3 Jun 2023 12:44:36 +0200 Subject: [PATCH] tweak events tests --- tests/events.cfc | 30 ++++++------------------------ tests/events/eventHandler.cfc | 13 ++++++++++--- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/tests/events.cfc b/tests/events.cfc index 39b17fbf..792a998f 100644 --- a/tests/events.cfc +++ b/tests/events.cfc @@ -1,22 +1,3 @@ - component extends="org.lucee.cfml.test.LuceeTestCase" labels="orm" { //public function setUp(){} @@ -52,7 +33,8 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="orm" { systemOutput("ERROR: " & err.error, true, true); } } - local.expectedEvents = [ "preInsert", "postInsert", "onFlush", "onClear" ]; // TBC + local.expectedEvents = [ "onFlush", "preInsert", "preInsert", "postInsert", "postInsert", "onClear" ]; + // local.expectedEvents = [ "preInsert", "postInsert", "onFlush", "onClear" ]; // TBC expect( res.events ).toBe( expectedEvents ); expect( res.errors.len() ).toBe( 0, "errors" ); expect( res.events.len() ).toBe( 4, "events" ); @@ -69,8 +51,9 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="orm" { loop array=res.errors, item="local.err"{ systemOutput("ERROR: " & err.error, true, true); } - } - local.expectedEvents = [ "preLoad", "postLoad", "onFlush", "onClear" ]; // TBC + } + local.expectedEvents = [ "onFlush", "onClear" ]; + //local.expectedEvents = [ "preLoad", "postLoad", "onFlush", "onClear" ]; // TBC expect( res.events ).toBe( expectedEvents ); expect( res.errors.len() ).toBe( 0, "errors" ); expect( res.events.len() ).toBe( 4, "events" ); @@ -82,5 +65,4 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="orm" { var baseURI = getDirectoryFromPath( contractPath( getCurrentTemplatePath() ) ); return baseURI&""&calledName; } -} - \ No newline at end of file +} \ No newline at end of file diff --git a/tests/events/eventHandler.cfc b/tests/events/eventHandler.cfc index 527a0265..694c1e20 100644 --- a/tests/events/eventHandler.cfc +++ b/tests/events/eventHandler.cfc @@ -35,7 +35,7 @@ component hint="logs out any orm events" { eventLog( arguments ); } - function preUpdate( entity, Struct oldData ){ + function preUpdate( entity, oldData ){ systemOutput(oldData, true); eventLog( arguments ); } @@ -80,10 +80,10 @@ component hint="logs out any orm events" { if ( isSimpleValue( args.2 ) ){ systemOutput("simple arguments.2: " & args.2, true); } else if ( isStruct( args.2) ) { - systemOutput("struct arguments.2: " & args.2.toJson(), true); + systemOutput("struct arguments.2: " & serializeJson(args.2), true); // hmm?? } else { try { - systemOutput("arguments.2: " & args.2.toJson(), true); + systemOutput("arguments.2: " & args.2.getClass(), true); //hmm? } catch (e) { systemOutput("arguments.2: " & e.message, true); } @@ -98,6 +98,13 @@ component hint="logs out any orm events" { "args": args } ); + var noEntityExpected = { + "onFlush" : true, + "onClear" : true + }; + + if (structKeyExists(noEntityExpected, eventName)) return; + try { if ( isNull(arguments.args.entity ) ) { throw ("entity was null");