diff --git a/tests/unit/Dispatcher/CallActionMethodCest.php b/tests/unit/Dispatcher/CallActionMethodCest.php index 46a9cf2ab5..781f4b947a 100644 --- a/tests/unit/Dispatcher/CallActionMethodCest.php +++ b/tests/unit/Dispatcher/CallActionMethodCest.php @@ -13,16 +13,18 @@ namespace Phalcon\Tests\Unit\Dispatcher; -use Codeception\Example; use Phalcon\Di\Di; use Phalcon\Events\Event; use Phalcon\Events\Manager; use Phalcon\Mvc\Dispatcher; -use Phalcon\Registry; +use Phalcon\Support\Registry; use UnitTester; class CallActionMethodCest { + private bool $wasCalled = false; + private bool $altCalled = false; + /** * Tests Phalcon\Dispatcher :: callActionMethod() * @@ -33,21 +35,15 @@ public function dispatcherCallActionMethod(UnitTester $I) { $I->wantToTest('Dispatcher - callActionMethod()'); - $wasCalled = (object) [ - 'wasCalled' => false, - 'method' => function () { - $this->wasCalled = true; - } - ]; - $dispatcher = new Dispatcher(); $dispatcher->callActionMethod( - $wasCalled, - 'method' + $this, + 'wasCalled' ); - $I->assertTrue($wasCalled->wasCalled); + $I->assertTrue($this->wasCalled); + $I->assertFalse($this->altCalled); } /** @@ -60,21 +56,11 @@ public function dispatcherCallActionMethodWithEvents(UnitTester $I) { $I->wantToTest('Dispatcher - callActionMethod()'); - $wasCalled = (object) [ - 'wasCalled' => false, - 'method' => function () { - $this->wasCalled = 1; - }, - 'altMethod' => function () { - $this->wasCalled = 2; - } - ]; - $eventsManager = new Manager(); $eventsManager->attach( 'dispatch:beforeCallAction', - function (Event $event, Dispatcher $dispatcher, Registry $observer) use ($eventsManager, $wasCalled) { - $observer->action = "altMethod"; + function (Event $event, Dispatcher $dispatcher, Registry $observer) { + $observer->action = "altCalled"; } ); @@ -84,10 +70,21 @@ function (Event $event, Dispatcher $dispatcher, Registry $observer) use ($events $dispatcher->setDi(new Di()); $dispatcher->callActionMethod( - $wasCalled, - 'method' + $this, + 'wasCalled' ); - $I->assertEquals(2, $wasCalled->wasCalled); + $I->assertTrue($this->altCalled); + $I->assertFalse($this->wasCalled); + } + + public function wasCalled(): void + { + $this->wasCalled = true; + } + + public function altCalled(): void + { + $this->altCalled = true; } }