-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16376 from niden/T16308-di-dynamic-properties-4
T16308 di dynamic properties 4
- Loading branch information
Showing
3 changed files
with
53 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,59 +13,83 @@ | |
|
||
namespace Phalcon\Tests\Integration\Mvc\Micro; | ||
|
||
use ErrorException; | ||
use IntegrationTester; | ||
use Phalcon\Di\Di; | ||
use Phalcon\Di\FactoryDefault; | ||
use Phalcon\Html\Escaper; | ||
use Phalcon\Http\Request; | ||
use Phalcon\Mvc\Dispatcher; | ||
use Phalcon\Mvc\Micro; | ||
use Phalcon\Mvc\Router; | ||
|
||
use function restore_error_handler; | ||
use function set_error_handler; | ||
|
||
class GetServiceCest | ||
{ | ||
/** | ||
* Tests Phalcon\Mvc\Micro :: getService() | ||
* | ||
* @author Sid Roberts <https://github.com/SidRoberts> | ||
* @author Phalcon Team <[email protected]> | ||
* @since 2019-05-22 | ||
*/ | ||
public function mvcMicroGetService(IntegrationTester $I) | ||
{ | ||
$I->wantToTest('Mvc\Micro - getService()'); | ||
|
||
$micro = new Micro(); | ||
|
||
$di = new Di(); | ||
|
||
$micro->setDi($di); | ||
|
||
|
||
$escaper = new Escaper(); | ||
|
||
$micro = new Micro(); | ||
$container = new Di(); | ||
$escaper = new Escaper(); | ||
$micro->setDi($container); | ||
$micro->setService('escaper', $escaper); | ||
|
||
$I->assertSame( | ||
$escaper, | ||
$micro->getService('escaper') | ||
); | ||
|
||
$expected = $escaper; | ||
$actual = $micro->getService('escaper'); | ||
$I->assertSame($expected, $actual); | ||
|
||
$dispatcher = new Dispatcher(); | ||
|
||
$micro['dispatcher'] = $dispatcher; | ||
|
||
$I->assertSame( | ||
$dispatcher, | ||
$micro->getService('dispatcher') | ||
); | ||
|
||
$expected = $dispatcher; | ||
$actual = $micro->getService('dispatcher'); | ||
$I->assertSame($expected, $actual); | ||
|
||
$router = new Router(); | ||
$container->set('router', $router); | ||
|
||
$di->set('router', $router); | ||
|
||
$I->assertSame( | ||
$router, | ||
$micro->getService('router') | ||
$expected = $router; | ||
$actual = $micro->getService('router'); | ||
$I->assertSame($expected, $actual); | ||
} | ||
/** | ||
* Tests after binding event | ||
* | ||
* @author Phalcon Team <[email protected]> | ||
* @since 2023-07-03 | ||
*/ | ||
public function mvcMicroGetServiceWithProperty(IntegrationTester $I) | ||
{ | ||
$container = new FactoryDefault(); | ||
$micro = new Micro($container); | ||
$error = ''; | ||
|
||
set_error_handler( | ||
function ($number, $message, $file, $line) { | ||
throw new ErrorException($message, 0, $number, $file, $line); | ||
} | ||
); | ||
|
||
try { | ||
$class = Request::class; | ||
$request = $micro->request; | ||
$I->assertInstanceOf($class, $request); | ||
} catch (ErrorException $ex) { | ||
$error = $ex->getMessage(); | ||
} | ||
|
||
restore_error_handler(); | ||
|
||
$I->assertEmpty($error); | ||
} | ||
} |