Skip to content

Commit

Permalink
Merge pull request #14 from penske-media-corp/feature/image-support
Browse files Browse the repository at this point in the history
Add image support to Post mocker
  • Loading branch information
mauteri authored Nov 22, 2022
2 parents f53054a + 2a063ba commit 5850029
Show file tree
Hide file tree
Showing 56 changed files with 368 additions and 83 deletions.
4 changes: 2 additions & 2 deletions autoload.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
/**
* PMC Unit Test Autoloader
* Autoloader for unit test.
*
* @package @pmc-unit-test
* @package pmc-unit-test
*/

namespace PMC\Unit_Test;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pmc/unit-test",
"version": "1.0.5",
"version": "1.0.6",
"description": "PMC Unit Test",
"authors": [
],
Expand Down
3 changes: 3 additions & 0 deletions docs/mock-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ Supported mocked post arguments:
...
],

// Featured image
'featured_image' => __DIR__ . '/some-image.png',;

// PMC Post options
'post_options' => [ 'opt1', 'opt2', ... ],

Expand Down
8 changes: 8 additions & 0 deletions examples/theme/tests/base.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?php
/**
* Base test for unit test.
*
* @package pmc-unit-test
*/
namespace Examples\Theme\Tests;

/**
* Class Base.
*/
abstract class Base extends \PMC\Unit_Test\Base {
}
5 changes: 5 additions & 0 deletions examples/theme/tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php
/**
* Bootstrap for unit test.
*
* @package pmc-unit-test
*/

namespace Examples\Theme\Tests;

Expand Down
9 changes: 9 additions & 0 deletions examples/theme/tests/test-example.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<?php
/**
* Example test for unit test.
*
* @package pmc-unit-test
*/

namespace Examples\Theme\Tests;

/**
* Class Test_Example.
*/
class Test_Example extends Base {

public function test_mock_post() {
Expand Down
3 changes: 2 additions & 1 deletion src/classes/autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
* @author Amit Gupta <[email protected]>
* @since 2019-01-31
*
* @package pmc-unit-test
*/

namespace PMC\Unit_Test;

/**
* @package pmc-unit-test
* Class Autoloader
*/
class Autoloader {

Expand Down
5 changes: 3 additions & 2 deletions src/classes/base-ajax.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?php
/**
* Base file for ajax pmc plugin unit test
* Defined the standard test base class for all unit test.
*
* @package pmc-unit-test
*/

namespace PMC\Unit_Test;

/**
* Class Base_Ajax.
*
* Define as abstract class to prevent test suite from scanning for test method
*
* Should only add method that is specific for Ajax testing only.
* For common shared code, please @see traits/base.php
*
*/
abstract class Base_Ajax extends \WP_Ajax_UnitTestCase {
use \PMC\Unit_Test\Traits\Asserts;
Expand Down
2 changes: 1 addition & 1 deletion src/classes/base.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Base file for pmc plugin unit test
* Defined the standard test base class for all unit test.
*
* @package pmc-unit-test
*/
Expand Down
7 changes: 3 additions & 4 deletions src/classes/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Common bootstrap file use for all theme & pmc plugin unit test
* Common bootstrap file use for all theme & pmc plugin unit test.
*
* @package pmc-unit-test
*/
Expand All @@ -12,7 +12,6 @@
// phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler
// phpcs:disable WordPressVIPMinimum.Variables.RestrictedVariables.cache_constraints___SERVER__HTTP_USER_AGENT__
// phpcs:disable WordPressVIPMinimum.Constants.RestrictedConstants.DefiningRestrictedConstant

namespace PMC\Unit_Test;

use PMC\Unit_Test\Interfaces\Mocker as MockerInterface;
Expand All @@ -33,9 +32,9 @@
}

/**
* PHPunit Bootstrap test class.
* Class Bootstrap.
*
* @codeCoverageIgnore No one tests a phpunit bootstrap file.
* @codeCoverageIgnore
*/
class Bootstrap {
const DEFAULT_PRIORITY = 10;
Expand Down
11 changes: 7 additions & 4 deletions src/classes/deprecated.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<?php
/**
* Deprecated functionality.
*
* @package pmc-unit-test
*/

// phpcs:disable WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_file_put_contents
// phpcs:disable WordPress.WP.AlternativeFunctions.json_encode_json_encode
// phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace


namespace PMC\Unit_Test;

use PMC\Global_Functions\Traits\Singleton;

/**
* Class Deprecated
* @package PMC\Unit_Test
* Class Deprecated.
*/
final class Deprecated {
use Singleton;
Expand Down
10 changes: 7 additions & 3 deletions src/classes/diff-parser.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<?php
/**
* Diff parsing class.
*
* @package pmc-unit-test
*/

// phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_fopen
// phpcs:disable WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition

namespace PMC\Unit_Test;

use PMC\Global_Functions\Traits\Singleton;

/**
* Class Diff_Parser
* @package PMC\Unit_Test
* Class Diff_Parser.
*/
final class Diff_Parser {
use Singleton;
Expand Down
7 changes: 6 additions & 1 deletion src/classes/object-cache.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<?php
/**
* Extends the WP Object Cache to allow unit test to inspect the caching behaviors as needed
* Extends the WP Object Cache to allow unit test to inspect the caching behaviors as needed.
*
* @package pmc-unit-test
*/

namespace PMC\Unit_Test;
use WP_Object_Cache;

/**
* Class Object_Cache.
*/
class Object_Cache extends WP_Object_Cache {
public $logs = [];

Expand Down
6 changes: 4 additions & 2 deletions src/classes/utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
* Utility class with utility methods for Unit Tests
*
* @author Amit Gupta <[email protected]>
*
* @since 2016-12-13
* @package pmc-unit-test
*/

namespace PMC\Unit_Test;


/**
* Class Utility.
*/
class Utility {

/**
Expand Down
11 changes: 7 additions & 4 deletions src/interfaces/mocker.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php
namespace PMC\Unit_Test\Interfaces;

/**
* All data mocker class must implement this Interface to be auto registered by PMC Unit Test during plugin load.
*
* Interface Mocker
* @package PMC\Unit_Test\Interfaces
* @package pmc-unit-test
*/

namespace PMC\Unit_Test\Interfaces;

/**
* Interface Mocker.
*/
interface Mocker {
public function provide_service();
Expand Down
11 changes: 6 additions & 5 deletions src/interfaces/seeder.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php
/**
* All test data that support auto sample data generation must implement this interface.
*
* @package pmc-unit-test
*/
namespace PMC\Unit_Test\Interfaces;


/**
* All test data that support auto sample data generation must implement this interface
*
* Interface Seeder
* @package PMC\Unit_Test\Interfaces
* Interface Seeder.
*/
interface Seeder {
public function seed();
Expand Down
4 changes: 2 additions & 2 deletions src/mocks/factory.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Mock factory for pmc unit test
* Factory class for unit test.
*
* @package pmc-unit-test
*/
Expand All @@ -12,7 +12,7 @@
use WP_UnitTestCase_Base;

/**
* Mocks Factory
* Class Factory.
*/
final class Factory {
use Singleton;
Expand Down
9 changes: 6 additions & 3 deletions src/mocks/http.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
<?php
/**
* Mocker class for WP Requests
*
* @author Hau Vong <[email protected]>
* Mocker class for WP Requests.
*
* We intercept all wp remote call by override the default transport
* by override the hidden static variable \Requests::$transports to this custom class
*
* All mocked method are prefix with "mock_" to prevent potential function name collision with Requests_Transport_cURL
*
* @author Hau Vong <[email protected]>
* @package pmc-unit-test
*/

namespace PMC\Unit_Test\Mocks;

use SimplePie;

/**
* Class Http.
*/
class Http
extends \Requests_Transport_cURL
implements \PMC\Unit_Test\Interfaces\Mocker {
Expand Down
11 changes: 7 additions & 4 deletions src/mocks/input.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<?php
/**
* Mocker for mocking the input global variable $_GET, $_POST, $_REQUEST, etc...
*
* @package pmc-unit-test
*/

namespace PMC\Unit_Test\Mocks;

use PMC\Unit_Test\Interfaces\Mocker as MockerInterface;
use PMC\Unit_Test\Interfaces\Seeder as SeederInterface;
use PMC\Unit_Test\Traits\Mocker as MockerTrait;

/**
* Mocker for mocking the input global variable $_GET, $_POST, $_REQUEST, etc...
*
* Class Input
* @package PMC\Unit_Test\Mocks
* Class Input.
*/
final class Input
implements MockerInterface {
Expand Down
11 changes: 7 additions & 4 deletions src/mocks/mail.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<?php
/**
* Mocker for wp_mail function
*
* @package pmc-unit-test
*/

// phpcs:disable Generic.Classes.DuplicateClassName.Found
// phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable

namespace PMC\Unit_Test\Mocks;

use PMC\Unit_Test\Interfaces\Mocker as MockerInterface;
Expand Down Expand Up @@ -30,10 +35,8 @@ public function __get( $name ) {
// @codeCoverageEnd

/**
* Mocker for wp_mail function
*
* Class Mail
* @package PMC\Unit_Test\Mocks
* Class Mail.
*/
final class Mail
extends Mock_Mailer
Expand Down
Loading

0 comments on commit 5850029

Please sign in to comment.