Migrate tests/unit folder to WordPress Coding Standard
[MAILPOET-6240]
This commit is contained in:
@@ -11,6 +11,11 @@
|
|||||||
<exclude-pattern>tests/*</exclude-pattern>
|
<exclude-pattern>tests/*</exclude-pattern>
|
||||||
</rule>
|
</rule>
|
||||||
|
|
||||||
|
<!-- Exclude bootstrap from the SeparateFunctionsFromOO.Mixed rule -->
|
||||||
|
<rule ref="Universal.Files.SeparateFunctionsFromOO.Mixed">
|
||||||
|
<exclude-pattern>tests/unit/_bootstrap.php</exclude-pattern>
|
||||||
|
</rule>
|
||||||
|
|
||||||
<!-- Skip the vendor directory -->
|
<!-- Skip the vendor directory -->
|
||||||
<exclude-pattern>vendor/*</exclude-pattern>
|
<exclude-pattern>vendor/*</exclude-pattern>
|
||||||
</ruleset>
|
</ruleset>
|
||||||
|
@@ -1,12 +1,24 @@
|
|||||||
<?php declare(strict_types = 1);
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of the MailPoet plugin.
|
||||||
|
*
|
||||||
|
* @package MailPoet\EmailEditor
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
namespace MailPoet\EmailEditor;
|
namespace MailPoet\EmailEditor;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for Container class.
|
||||||
|
*/
|
||||||
class Container_Test extends TestCase {
|
class Container_Test extends TestCase {
|
||||||
|
/**
|
||||||
|
* Test if sets and gets service.
|
||||||
|
*/
|
||||||
public function testSetAndGetService(): void {
|
public function testSetAndGetService(): void {
|
||||||
$container = new Container();
|
$container = new Container();
|
||||||
|
|
||||||
@@ -22,6 +34,9 @@ class Container_Test extends TestCase {
|
|||||||
$this->assertInstanceOf( stdClass::class, $service );
|
$this->assertInstanceOf( stdClass::class, $service );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if sets and gets service with dependencies.
|
||||||
|
*/
|
||||||
public function testGetReturnsSameInstance(): void {
|
public function testGetReturnsSameInstance(): void {
|
||||||
$container = new Container();
|
$container = new Container();
|
||||||
|
|
||||||
@@ -32,19 +47,22 @@ class Container_Test extends TestCase {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Retrieve the service twice
|
// Retrieve the service twice.
|
||||||
$service1 = $container->get( 'singleton_service' );
|
$service1 = $container->get( 'singleton_service' );
|
||||||
$service2 = $container->get( 'singleton_service' );
|
$service2 = $container->get( 'singleton_service' );
|
||||||
|
|
||||||
// Check that both instances are the same
|
// Check that both instances are the same.
|
||||||
$this->assertSame( $service1, $service2 );
|
$this->assertSame( $service1, $service2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if it throws exception for non-existing service.
|
||||||
|
*/
|
||||||
public function testExceptionForNonExistingService(): void {
|
public function testExceptionForNonExistingService(): void {
|
||||||
// Create the container instance
|
// Create the container instance.
|
||||||
$container = new Container();
|
$container = new Container();
|
||||||
|
|
||||||
// Attempt to get a non-existing service should throw an exception
|
// Attempt to get a non-existing service should throw an exception.
|
||||||
$this->expectException( Exception::class );
|
$this->expectException( Exception::class );
|
||||||
$this->expectExceptionMessage( 'Service not found: non_existing_service' );
|
$this->expectExceptionMessage( 'Service not found: non_existing_service' );
|
||||||
|
|
||||||
|
@@ -1,16 +1,41 @@
|
|||||||
<?php declare(strict_types = 1);
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of the MailPoet plugin.
|
||||||
|
*
|
||||||
|
* @package MailPoet\EmailEditor
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
$console = new \Codeception\Lib\Console\Output( array() );
|
$console = new \Codeception\Lib\Console\Output( array() );
|
||||||
|
|
||||||
if ( ! function_exists( 'esc_attr' ) ) {
|
if ( ! function_exists( 'esc_attr' ) ) {
|
||||||
|
/**
|
||||||
|
* Mock esc_attr function.
|
||||||
|
*
|
||||||
|
* @param string $attr Attribute to escape.
|
||||||
|
*/
|
||||||
function esc_attr( $attr ) {
|
function esc_attr( $attr ) {
|
||||||
return $attr;
|
return $attr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for unit tests.
|
||||||
|
*/
|
||||||
abstract class MailPoetUnitTest extends \Codeception\TestCase\Test {
|
abstract class MailPoetUnitTest extends \Codeception\TestCase\Test {
|
||||||
protected $runTestInSeparateProcess = false;
|
/**
|
||||||
protected $preserveGlobalState = false;
|
* Disable running tests in separate processes.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $runTestInSeparateProcess = false; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.PropertyNotSnakeCase
|
||||||
|
/**
|
||||||
|
* Disable preserving global state.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $preserveGlobalState = false; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.PropertyNotSnakeCase
|
||||||
}
|
}
|
||||||
|
|
||||||
require '_stubs.php';
|
require '_stubs.php';
|
||||||
|
@@ -1,14 +1,33 @@
|
|||||||
<?php declare(strict_types = 1);
|
<?php
|
||||||
// phpcs:ignoreFile - We want to allow multiple classes etc.
|
/**
|
||||||
|
* This file is part of the MailPoet plugin.
|
||||||
|
*
|
||||||
|
* @package MailPoet\EmailEditor
|
||||||
|
*/
|
||||||
|
|
||||||
// Dummy WP classes
|
declare(strict_types = 1);
|
||||||
if (!class_exists(\WP_Theme_JSON::class)) {
|
|
||||||
|
// Dummy WP classes.
|
||||||
|
if ( ! class_exists( \WP_Theme_JSON::class ) ) {
|
||||||
|
/**
|
||||||
|
* Class WP_Theme_JSON
|
||||||
|
*/
|
||||||
class WP_Theme_JSON {
|
class WP_Theme_JSON {
|
||||||
|
/**
|
||||||
|
* Get data.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function get_data() {
|
public function get_data() {
|
||||||
return [];
|
return array();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Get settings.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function get_settings() {
|
public function get_settings() {
|
||||||
return [];
|
return array();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user