penske-media-corp / pmc-unit-test

PMC WordPress unit test framework
GNU General Public License v2.0
7 stars 1 forks source link

Move factory set up to protected setter instead of #12

Open berkod opened 2 years ago

berkod commented 2 years ago

I think we need to move the factory set up to a different setter for php8. It's throwing errors in php8 pipelines. Not 100% sure if that's the right way to fix this.

https://github.com/penske-media-corp/pmc-unit-test/blob/867611bdab4465ce18dd0422f0622e5c93945bc2/src/mocks/factory.php#L19-L22

1) Test_Class_Plugin::test_filter_wpcom_legacy_redirector_redirect_status
Error: Cannot access protected property Test_Class_Plugin::$factory

/home/runner/work/pmc-plugins/pmc-plugins/pmc-unit-test/vendor/pmc/unit-test/src/mocks/factory.php:21
/home/runner/work/pmc-plugins/pmc-plugins/pmc-unit-test/vendor/pmc/unit-test/src/traits/base.php:110
/home/runner/work/pmc-plugins/pmc-plugins/pmc-unit-test/vendor/pmc/unit-test/src/traits/base.php:134
/home/runner/work/pmc-plugins/pmc-plugins/pmc-410/tests/classes/test-class-plugin.php:21

2) Test_Class_Plugin::test_maybe_set_http_status_410
Error: Cannot access protected property Test_Class_Plugin::$factory

/home/runner/work/pmc-plugins/pmc-plugins/pmc-unit-test/vendor/pmc/unit-test/src/mocks/factory.php:21
/home/runner/work/pmc-plugins/pmc-plugins/pmc-unit-test/vendor/pmc/unit-test/src/traits/base.php:110
/home/runner/work/pmc-plugins/pmc-plugins/pmc-unit-test/vendor/pmc/unit-test/src/traits/base.php:134
/home/runner/work/pmc-plugins/pmc-plugins/pmc-410/tests/classes/test-class-plugin.php:21
hauvong commented 2 years ago

Not related to PHP8. This is caused by WP 6.1.0 deprecating the $this->factory access documented here.

https://github.com/WordPress/wordpress-develop/blob/trunk/tests/phpunit/includes/abstract-testcase.php#L29

This can be quickly patch like this: eg.

        $this->_test_factory = Utility::invoke_hidden_static_method( WP_UnitTestCase_Base::class, 'factory' );