Skip to content

Commit

Permalink
PHP 8.2 | Various tests: explicitly declare properties
Browse files Browse the repository at this point in the history
Dynamic (non-explicitly declared) property usage is expected to be deprecated as of PHP 8.2 and will become a fatal error in PHP 9.0.

There are a number of ways to mitigate this:
* If it's an accidental typo for a declared property: fix the typo.
* For known properties: declare them on the class.
* For unknown properties: add the magic `__get()`, `__set()` et al methods to the class or let the class extend `stdClass` which has highly optimized versions of these magic methods build in.
* For unknown _use of_ dynamic properties, the `#[AllowDynamicProperties]` attribute can be added to the class. The attribute will automatically be inherited by child classes.

This commit addresses a number of issues in the "known property" category within the test suite.

Refs:
* https://wiki.php.net/rfc/deprecate_dynamic_properties
  • Loading branch information
jrfnl committed Mar 15, 2022
1 parent c10a5f6 commit 358c21a
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/Mockery/Adapter/Phpunit/TestListenerTest.php
Expand Up @@ -28,6 +28,11 @@

class TestListenerTest extends MockeryTestCase
{
protected $container;
protected $listener;
protected $testResult;
protected $test;

protected function mockeryTestSetUp()
{
// We intentionally test the static container here. That is what the
Expand Down
2 changes: 2 additions & 0 deletions tests/Mockery/AdhocTest.php
Expand Up @@ -26,6 +26,8 @@
*/
class Mockery_AdhocTest extends MockeryTestCase
{
protected $container;

public function mockeryTestSetUp()
{
$this->container = new \Mockery\Container(\Mockery::getDefaultGenerator(), \Mockery::getDefaultLoader());
Expand Down
2 changes: 2 additions & 0 deletions tests/Mockery/DefaultMatchersTest.php
Expand Up @@ -50,6 +50,8 @@ public function __construct($value)

class DefaultMatchersTest extends MockeryTestCase
{
protected $mock;

public function mockeryTestSetUp()
{
parent::mockeryTestSetUp();
Expand Down
4 changes: 4 additions & 0 deletions tests/Mockery/ExpectationTest.php
Expand Up @@ -28,6 +28,8 @@ class ExpectationTest extends MockeryTestCase
{
use RegExpCompatability;

protected $mock;

public function mockeryTestSetUp()
{
parent::mockeryTestSetUp();
Expand Down Expand Up @@ -2228,6 +2230,8 @@ public function baz()

class Mockery_UseDemeter
{
protected $demeter;

public function __construct($demeter)
{
$this->demeter = $demeter;
Expand Down
Expand Up @@ -28,6 +28,8 @@ class ClassNamePassTest extends MockeryTestCase
{
const CODE = "namespace Mockery; class Mock {}";

protected $pass;

public function mockeryTestSetUp()
{
$this->pass = new ClassNamePass();
Expand Down
Expand Up @@ -28,6 +28,8 @@ class ClassPassTest extends MockeryTestCase
{
const CODE = "class Mock implements MockInterface {}";

protected $pass;

public function mockeryTestSetUp()
{
$this->pass = new ClassPass();
Expand Down
2 changes: 2 additions & 0 deletions tests/Mockery/HamcrestExpectationTest.php
Expand Up @@ -23,6 +23,8 @@

class HamcrestExpectationTest extends MockeryTestCase
{
protected $mock;

public function mockeryTestSetUp()
{
parent::mockeryTestSetUp();
Expand Down
2 changes: 2 additions & 0 deletions tests/Mockery/MockClassWithFinalWakeupTest.php
Expand Up @@ -25,6 +25,8 @@

class MockClassWithFinalWakeupTest extends MockeryTestCase
{
protected $container;

protected function mockeryTestSetUp()
{
$this->container = new \Mockery\Container();
Expand Down

0 comments on commit 358c21a

Please sign in to comment.