Fix PHPStan class-string errors
MAILPOET-6318
This commit is contained in:
committed by
Jan Lysý
parent
cbfdba7bd2
commit
5ce9008f90
@@ -17,10 +17,6 @@ parameters:
|
|||||||
maximumNumberOfProcesses: 3 # Static analysis is running on Circle CI medium+ that has 3 CPUs
|
maximumNumberOfProcesses: 3 # Static analysis is running on Circle CI medium+ that has 3 CPUs
|
||||||
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.#'
|
|
||||||
-
|
|
||||||
message: '#Cannot call method initialize\(\) on mixed#'
|
|
||||||
path: ../../../packages/php/email-editor/tests/integration/*
|
|
||||||
-
|
-
|
||||||
message: '#has no return type specified.#'
|
message: '#has no return type specified.#'
|
||||||
path: ../../../packages/php/email-editor/tests/integration/*
|
path: ../../../packages/php/email-editor/tests/integration/*
|
||||||
@@ -30,15 +26,6 @@ parameters:
|
|||||||
-
|
-
|
||||||
message: '#assertStringNotContainsString\(\) expects string#'
|
message: '#assertStringNotContainsString\(\) expects string#'
|
||||||
path: ../../../packages/php/email-editor/tests/integration/*
|
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/*
|
|
||||||
-
|
|
||||||
message: '#Access to an undefined property MailPoet\\EmailEditor\\.*Test::\$tester.#'
|
|
||||||
path: ../../../packages/php/email-editor/tests/integration/*
|
|
||||||
reportUnmatchedIgnoredErrors: true
|
reportUnmatchedIgnoredErrors: true
|
||||||
dynamicConstantNames:
|
dynamicConstantNames:
|
||||||
- MAILPOET_PREMIUM_INITIALIZED
|
- MAILPOET_PREMIUM_INITIALIZED
|
||||||
|
@@ -43,7 +43,7 @@ class Container {
|
|||||||
* Method for getting a registered service
|
* Method for getting a registered service
|
||||||
*
|
*
|
||||||
* @template T
|
* @template T
|
||||||
* @param string|class-string<T> $name The name of the service.
|
* @param class-string<T> $name The name of the service.
|
||||||
* @return T
|
* @return T
|
||||||
* @throws \Exception If the service is not found.
|
* @throws \Exception If the service is not found.
|
||||||
*/
|
*/
|
||||||
|
@@ -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 ); // @phpstan-ignore-line
|
$this->email_editor = $this->di_container->get( Email_Editor::class );
|
||||||
$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',
|
||||||
|
@@ -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 ); // @phpstan-ignore-line
|
$this->patterns = $this->di_container->get( Patterns::class );
|
||||||
$this->cleanup_patterns();
|
$this->cleanup_patterns();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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 ); // @phpstan-ignore-line
|
$this->registry = $this->di_container->get( Blocks_Registry::class );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -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 ); // @phpstan-ignore-line
|
$this->theme_controller = $this->di_container->get( Theme_Controller::class );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -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 ); // @phpstan-ignore-line
|
$this->renderer = $this->di_container->get( Renderer::class );
|
||||||
$this->di_container->get( Email_Editor::class )->initialize(); // @phpstan-ignore-line
|
$this->di_container->get( Email_Editor::class )->initialize();
|
||||||
$this->di_container->get( Initializer::class )->initialize(); // @phpstan-ignore-line
|
$this->di_container->get( Initializer::class )->initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -124,10 +124,11 @@ abstract class MailPoetTest extends \Codeception\TestCase\Test { // phpcs:ignore
|
|||||||
/**
|
/**
|
||||||
* Get a service from the DI container.
|
* Get a service from the DI container.
|
||||||
*
|
*
|
||||||
* @param string $id The service ID.
|
* @template T
|
||||||
|
* @param class-string<T> $id The service ID.
|
||||||
* @param array $overrides The properties to override.
|
* @param array $overrides The properties to override.
|
||||||
*/
|
*/
|
||||||
public function getServiceWithOverrides( string $id, array $overrides ) {
|
public function getServiceWithOverrides( $id, array $overrides ) {
|
||||||
$instance = $this->di_container->get( $id );
|
$instance = $this->di_container->get( $id );
|
||||||
return Stub::copy( $instance, $overrides );
|
return Stub::copy( $instance, $overrides );
|
||||||
}
|
}
|
||||||
|
@@ -10,12 +10,16 @@ namespace MailPoet\EmailEditor;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use stdClass;
|
|
||||||
|
class Simple_Service {} // phpcs:ignore
|
||||||
|
|
||||||
|
class Singleton_Service {} // phpcs:ignore
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit test for Container class.
|
* Unit test for Container class.
|
||||||
|
* Ignoring Only one object structure is allowed in a file.
|
||||||
*/
|
*/
|
||||||
class Container_Test extends TestCase {
|
class Container_Test extends TestCase { // phpcs:ignore
|
||||||
/**
|
/**
|
||||||
* Test if sets and gets service.
|
* Test if sets and gets service.
|
||||||
*/
|
*/
|
||||||
@@ -23,15 +27,15 @@ class Container_Test extends TestCase {
|
|||||||
$container = new Container();
|
$container = new Container();
|
||||||
|
|
||||||
$container->set(
|
$container->set(
|
||||||
'simple_service',
|
Simple_Service::class,
|
||||||
function () {
|
function () {
|
||||||
return new stdClass();
|
return new Simple_Service();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$service = $container->get( 'simple_service' );
|
$service = $container->get( Simple_Service::class );
|
||||||
|
|
||||||
$this->assertInstanceOf( stdClass::class, $service );
|
$this->assertInstanceOf( Simple_Service::class, $service );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,15 +45,15 @@ class Container_Test extends TestCase {
|
|||||||
$container = new Container();
|
$container = new Container();
|
||||||
|
|
||||||
$container->set(
|
$container->set(
|
||||||
'singleton_service',
|
Singleton_Service::class,
|
||||||
function () {
|
function () {
|
||||||
return new stdClass();
|
return new Singleton_Service();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Retrieve the service twice.
|
// Retrieve the service twice.
|
||||||
$service1 = $container->get( 'singleton_service' );
|
$service1 = $container->get( Singleton_Service::class );
|
||||||
$service2 = $container->get( 'singleton_service' );
|
$service2 = $container->get( Singleton_Service::class );
|
||||||
|
|
||||||
// Check that both instances are the same.
|
// Check that both instances are the same.
|
||||||
$this->assertSame( $service1, $service2 );
|
$this->assertSame( $service1, $service2 );
|
||||||
@@ -66,6 +70,6 @@ class Container_Test extends TestCase {
|
|||||||
$this->expectException( Exception::class );
|
$this->expectException( Exception::class );
|
||||||
$this->expectExceptionMessage( 'Service not found: non_existing_service' );
|
$this->expectExceptionMessage( 'Service not found: non_existing_service' );
|
||||||
|
|
||||||
$container->get( 'non_existing_service' );
|
$container->get( 'non_existing_service' ); // @phpstan-ignore-line
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user