Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T16308 di dynamic properties 4 #16376

Merged
merged 3 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading