ResetApplicationObjectExtensions(); // Count all the calls to this object MockApplicationObjectExtensionForTest::SetCallBack([ApplicationObjectExtensionTest::class, 'IncrementCallCount']); } public function tearDown(): void { MockApplicationObjectExtensionForTest::SetModifications('Person', 'name', 0); MockApplicationObjectExtensionForTest::SetCallBack(null); parent::tearDown(); } public static function IncrementCallCount(string $sOrigin) { self::$aCalls[$sOrigin] = (self::$aCalls[$sOrigin] ?? 0) + 1; self::$iCalls++; } public static function ResetCallCount() { self::$aCalls = []; self::$iCalls = 0; } public function testExtensionCalled() { // Check that extension is called $oPerson = $this->CreatePerson(1); $oPerson->Set('first_name', 'testUpdateReentranceProtection'); MockApplicationObjectExtensionForTest::SetModifications('Person', 'name', 1); self::ResetCallCount(); $oPerson->DBUpdate(); // Called twice, the first call will provoke the DBUpdate and call again the object extension $this->assertEquals(2, self::$iCalls); } public function testUpdateReentranceProtection() { $oPerson = $this->CreatePerson(1); // Check that loop limit is 10 $i = 15; self::ResetCallCount(); MockApplicationObjectExtensionForTest::SetModifications('Person', 'name', $i); $oPerson->Set('first_name', 'testUpdateReentranceProtection'); $oPerson->DBUpdate(); $this->assertEquals(10, self::$iCalls); } public function testModificationsOnUpdate() { $oPerson = $this->CreatePerson(1); $oPerson->Set('first_name', 'testUpdateReentranceProtection'); self::ResetCallCount(); MockApplicationObjectExtensionForTest::SetModifications('Person', 'name', 1); $oPerson->DBUpdate(); $this->assertEquals(2, self::$iCalls); } public function testModificationsOnInsert() { self::ResetCallCount(); MockApplicationObjectExtensionForTest::SetModifications('Person', 'name', 1); $oPerson = $this->CreatePerson(1); $this->assertEquals(2, self::$iCalls); } public function testModificationsOnInsertWith2Extensions() { self::ResetCallCount(); require_once 'iApplicationObjectExtension/MockApplicationObjectExtensionForTest2.php'; $this->ResetApplicationObjectExtensions(); // Count all the calls to this object MockApplicationObjectExtensionForTest2::SetCallBack([ApplicationObjectExtensionTest::class, 'IncrementCallCount']); MockApplicationObjectExtensionForTest::SetModifications('Person', 'name', 2); MockApplicationObjectExtensionForTest2::SetModifications('Person', 'first_name', 2); $oPerson = $this->CreatePerson(1); $this->assertEquals(6, self::$iCalls); } }