Fix PHPStan errors for Email editor PHP package integration test folder

MAILPOET-6318
This commit is contained in:
Oluwaseun Olorunsola
2024-11-22 16:38:13 +01:00
committed by Jan Lysý
parent a4ad960492
commit 325c4c74f4
10 changed files with 35 additions and 13 deletions

View File

@@ -6,7 +6,9 @@ parameters:
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php - vendor/php-stubs/wordpress-stubs/wordpress-stubs.php
- ../../vendor/codeception/codeception/autoload.php - ../../vendor/codeception/codeception/autoload.php
- ../../vendor/codeception/verify/src/Codeception/Verify/Verify.php - ../../vendor/codeception/verify/src/Codeception/Verify/Verify.php
- ../../../packages/php/email-editor/tests/_support/_generated/IntegrationTesterActions.php
scanDirectories:
- ../../../packages/php/email-editor/tests/_support
inferPrivatePropertyTypeFromConstructor: true inferPrivatePropertyTypeFromConstructor: true
checkGenericClassInNonGenericObjectType: false checkGenericClassInNonGenericObjectType: false
parallel: parallel:
@@ -15,6 +17,24 @@ parameters:
ignoreErrors: ignoreErrors:
- '#_before\(\) has no return type specified#' # skip integration test before errors - '#_before\(\) has no return type specified#' # skip integration test before errors
- '#Container::get\(\) is not referenced in a parameter.#' - '#Container::get\(\) is not referenced in a parameter.#'
-
message: '#Cannot call method initialize\(\) on mixed#'
path: ../../../packages/php/email-editor/tests/integration/*
-
message: '#has no return type specified.#'
path: ../../../packages/php/email-editor/tests/integration/*
-
message: '#assertStringContainsString\(\) expects string#'
path: ../../../packages/php/email-editor/tests/integration/*
-
message: '#assertStringNotContainsString\(\) expects string#'
path: ../../../packages/php/email-editor/tests/integration/*
-
message: '#settings_controller \(MailPoet\\EmailEditor\\Engine\\Settings_Controller\) does not accept mixed#'
path: ../../../packages/php/email-editor/tests/integration/*
-
message: '#Renderer\) does not accept mixed.#'
path: ../../../packages/php/email-editor/tests/integration/*
reportUnmatchedIgnoredErrors: true reportUnmatchedIgnoredErrors: true
dynamicConstantNames: dynamicConstantNames:
- MAILPOET_PREMIUM_INITIALIZED - MAILPOET_PREMIUM_INITIALIZED

View File

@@ -31,7 +31,7 @@ $commands = array(
"$phpStanBin analyse ", "$phpStanBin analyse ",
"-c $emailEditorCustomConfig ", "-c $emailEditorCustomConfig ",
"$emailEditorPhpDir/src ", "$emailEditorPhpDir/src ",
// "$emailEditorPhpDir/tests/integration ", // TODO: will uncomment after fixing src errors "$emailEditorPhpDir/tests/integration ",
"$emailEditorPhpDir/tests/unit ", "$emailEditorPhpDir/tests/unit ",
); );

View File

@@ -31,7 +31,7 @@ class Email_Editor_Test extends \MailPoetTest {
*/ */
public function _before() { public function _before() {
parent::_before(); parent::_before();
$this->email_editor = $this->di_container->get( Email_Editor::class ); $this->email_editor = $this->di_container->get( Email_Editor::class ); // @phpstan-ignore-line
$this->post_register_callback = function ( $post_types ) { $this->post_register_callback = function ( $post_types ) {
$post_types[] = array( $post_types[] = array(
'name' => 'custom_email_type', 'name' => 'custom_email_type',

View File

@@ -23,7 +23,7 @@ class Patterns_Test extends \MailPoetTest {
*/ */
public function _before() { public function _before() {
parent::_before(); parent::_before();
$this->patterns = $this->di_container->get( Patterns::class ); $this->patterns = $this->di_container->get( Patterns::class ); // @phpstan-ignore-line
$this->cleanup_patterns(); $this->cleanup_patterns();
} }
@@ -33,6 +33,7 @@ class Patterns_Test extends \MailPoetTest {
public function testItRegistersPatternCategories() { public function testItRegistersPatternCategories() {
$this->patterns->initialize(); $this->patterns->initialize();
$categories = \WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered(); $categories = \WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered();
/** @var array{name: string, label: string, description: string} $category */ // phpcs:ignore
$category = array_pop( $categories ); $category = array_pop( $categories );
$this->assertEquals( 'email-contents', $category['name'] ); $this->assertEquals( 'email-contents', $category['name'] );
$this->assertEquals( 'Email Contents', $category['label'] ); $this->assertEquals( 'Email Contents', $category['label'] );

View File

@@ -29,7 +29,7 @@ class Blocks_Registry_Test extends \MailPoetTest {
*/ */
public function _before() { public function _before() {
parent::_before(); parent::_before();
$this->registry = $this->di_container->get( Blocks_Registry::class ); $this->registry = $this->di_container->get( Blocks_Registry::class ); // @phpstan-ignore-line
} }
/** /**

View File

@@ -134,8 +134,8 @@ class Content_Renderer_Test extends \MailPoetTest {
*/ */
private function getStylesValueForTag( $html, $tag ): ?string { private function getStylesValueForTag( $html, $tag ): ?string {
$html = new \WP_HTML_Tag_Processor( $html ); $html = new \WP_HTML_Tag_Processor( $html );
if ( $html->next_tag( $tag ) ) { if ( $html->next_tag( $tag ) ) { // @phpstan-ignore-line
return $html->get_attribute( 'style' ); return $html->get_attribute( 'style' ); // @phpstan-ignore-line
} }
return null; return null;
} }

View File

@@ -211,7 +211,7 @@ class Renderer_Test extends \MailPoetTest {
private function getStylesValueForTag( string $html, array $query ): ?string { private function getStylesValueForTag( string $html, array $query ): ?string {
$html = new \WP_HTML_Tag_Processor( $html ); $html = new \WP_HTML_Tag_Processor( $html );
if ( $html->next_tag( $query ) ) { if ( $html->next_tag( $query ) ) {
return $html->get_attribute( 'style' ); return $html->get_attribute( 'style' ); // @phpstan-ignore-line
} }
return null; return null;
} }

View File

@@ -24,7 +24,7 @@ class Theme_Controller_Test extends \MailPoetTest {
*/ */
public function _before() { public function _before() {
parent::_before(); parent::_before();
$this->theme_controller = $this->di_container->get( Theme_Controller::class ); $this->theme_controller = $this->di_container->get( Theme_Controller::class ); // @phpstan-ignore-line
} }
/** /**

View File

@@ -28,9 +28,9 @@ class Renderer_Test extends \MailPoetTest {
*/ */
public function _before() { public function _before() {
parent::_before(); parent::_before();
$this->renderer = $this->di_container->get( Renderer::class ); $this->renderer = $this->di_container->get( Renderer::class ); // @phpstan-ignore-line
$this->di_container->get( Email_Editor::class )->initialize(); $this->di_container->get( Email_Editor::class )->initialize(); // @phpstan-ignore-line
$this->di_container->get( Initializer::class )->initialize(); $this->di_container->get( Initializer::class )->initialize(); // @phpstan-ignore-line
} }
/** /**

View File

@@ -128,6 +128,7 @@ abstract class MailPoetTest extends \Codeception\TestCase\Test { // phpcs:ignore
* @param array $overrides The properties to override. * @param array $overrides The properties to override.
*/ */
public function getServiceWithOverrides( string $id, array $overrides ) { public function getServiceWithOverrides( string $id, array $overrides ) {
// @phpstan-ignore-line
$instance = $this->di_container->get( $id ); $instance = $this->di_container->get( $id );
return Stub::copy( $instance, $overrides ); return Stub::copy( $instance, $overrides );
} }