Skip to content

Commit

Permalink
Merge pull request #16376 from niden/T16308-di-dynamic-properties-4
Browse files Browse the repository at this point in the history
T16308 di dynamic properties 4
  • Loading branch information
niden authored Jul 17, 2023
2 parents e01ae9b + 58e25db commit b760fd6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixed
- Tried to reproduce the behavior described in #16244 but had no success. [#16244](https://github.com/phalcon/cphalcon/issues/16244)
- Added `getAdapter()` in `Phalcon\Mvc\Model\Metadata` to retrieve the internal cache adapter if necessary. [#16244](https://github.com/phalcon/cphalcon/issues/16244)
- Extended `Phalcon\Di\Injectable` from `stdClass` to remove the deprecation warning (dynamic properties) for PHP 8.2 [#16308](https://github.com/phalcon/cphalcon/issues/16308)

## [5.2.2](https://github.com/phalcon/cphalcon/releases/tag/v5.2.2) (2023-06-18)

Expand Down
3 changes: 2 additions & 1 deletion phalcon/Di/Injectable.zep
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Phalcon\Di;

use stdClass;
use Phalcon\Di\Di;
use Phalcon\Session\BagInterface;

Expand Down Expand Up @@ -42,7 +43,7 @@ use Phalcon\Session\BagInterface;
* @property \Phalcon\Session\Bag|\Phalcon\Session\BagInterface $persistent
* @property \Phalcon\Mvc\View|\Phalcon\Mvc\ViewInterface $view
*/
abstract class Injectable implements InjectionAwareInterface
abstract class Injectable extends stdClass implements InjectionAwareInterface
{
/**
* Dependency Injector
Expand Down
76 changes: 50 additions & 26 deletions tests/integration/Mvc/Micro/GetServiceCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit b760fd6

Please sign in to comment.