Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSR4 & Class Map Autoloading #704

Merged
merged 32 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
150c93f
Define PSR4 autoloading
nmolham-godaddy Aug 26, 2024
54f199a
Autoloading Country_Helper
nmolham-godaddy Aug 26, 2024
187db85
Autoloading traits
nmolham-godaddy Aug 26, 2024
fb7cf27
Autoloading enums
nmolham-godaddy Aug 26, 2024
7abe302
Map Payment_Gateway namespace
nmolham-godaddy Aug 26, 2024
822e47a
Place PaymentFormContextChecker under the correct namespace
nmolham-godaddy Aug 26, 2024
2deb25c
Autoload Handlers namespace
nmolham-godaddy Aug 26, 2024
7350d97
Autoload Payment_Gateway\External_Checkout namespace
nmolham-godaddy Aug 26, 2024
5e6f978
Autoload Payment_Gateway\External_Checkout\Google_Pay namespace
nmolham-godaddy Aug 26, 2024
854ccc8
Autoload Payment_Gateway\Blocks namespace
nmolham-godaddy Aug 26, 2024
ba85ecf
Autoload Settings_API namespace
nmolham-godaddy Aug 26, 2024
5c48eb1
Autoload Helpers namespace
nmolham-godaddy Aug 26, 2024
6779677
Autoload API namespace
nmolham-godaddy Aug 26, 2024
0fa7993
Autoload Admin namespace
nmolham-godaddy Aug 26, 2024
95fd07b
Autoload Addresses namespace
nmolham-godaddy Aug 26, 2024
fb5efbb
Temp api/traits dir rename
nmolham-godaddy Aug 26, 2024
d7ee9d8
Revert temp renaming
nmolham-godaddy Aug 26, 2024
3ffed13
Move Country_Helper under Helpers namespace
nmolham-godaddy Aug 26, 2024
3fb89fa
Setup class aliases
nmolham-godaddy Aug 28, 2024
9817b0a
Setup class mapping via composer
nmolham-godaddy Aug 28, 2024
7ddac72
Remove all unnecessary class files inclusion
nmolham-godaddy Aug 28, 2024
b35d742
Test for samples of non-PSR4 classes
nmolham-godaddy Aug 28, 2024
7ee0cd6
restore load_class method
nmolham-godaddy Aug 28, 2024
5728a3d
Version number formatting.
agibson-godaddy Aug 28, 2024
67e69bc
Autoload testing with class_exists and/or interface_exists
nmolham-godaddy Aug 29, 2024
0abbe06
Merge branch 'release/5.14.0' into chore/setup-autoloading
nmolham-godaddy Aug 29, 2024
7337b61
Merge branch 'release/5.14.0' into chore/setup-autoloading
nmolham-godaddy Aug 29, 2024
2d51e6d
Move Lifcycle class under corresponding namespace
nmolham-godaddy Aug 29, 2024
d2725d9
Update plugin loader example
nmolham-godaddy Aug 29, 2024
e9cbdf5
Remove redundant woothemes_queue_update
nmolham-godaddy Aug 29, 2024
68da0a5
Only set up alias if it doesn't already exist
agibson-godaddy Aug 29, 2024
e826a4a
Update changelog
agibson-godaddy Aug 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
"codeception/module-asserts": "^1.3",
"10up/wp_mock": "^1.0"
},
"autoload": {
"psr-4": {
"SkyVerge\\WooCommerce\\PluginFramework\\v5_13_1\\": "woocommerce/",
"SkyVerge\\WooCommerce\\PluginFramework\\v5_13_1\\Admin\\": "woocommerce/admin/",
"SkyVerge\\WooCommerce\\PluginFramework\\v5_13_1\\Payment_Gateway\\": "woocommerce/payment-gateway/",
"SkyVerge\\WooCommerce\\PluginFramework\\v5_13_1\\API\\": "woocommerce/api/"
}
},
"autoload-dev": {
"psr-4": {
"SkyVerge\\WooCommerce\\PluginFramework\\v5_13_1\\Tests\\": "tests/"
Expand Down
6 changes: 0 additions & 6 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
require_once PLUGIN_ROOT_DIR.'/vendor/autoload.php';
require_once PLUGIN_ROOT_DIR.'/woocommerce/class-sv-wc-plugin.php';
require_once PLUGIN_ROOT_DIR.'/woocommerce/class-sv-wc-plugin-exception.php';
require_once PLUGIN_ROOT_DIR.'/woocommerce/Enums/Traits/EnumTrait.php';
require_once PLUGIN_ROOT_DIR.'/woocommerce/Enums/PaymentFormContext.php';
require_once PLUGIN_ROOT_DIR.'/woocommerce/Traits/CanGetNewInstanceTrait.php';
require_once PLUGIN_ROOT_DIR.'/woocommerce/Traits/CanConvertToArrayTrait.php';
require_once PLUGIN_ROOT_DIR.'/woocommerce/Traits/IsSingletonTrait.php';
require_once PLUGIN_ROOT_DIR.'/woocommerce/Helpers/ArrayHelper.php';

WP_Mock::setUsePatchwork(true);
WP_Mock::bootstrap();
Expand Down
1 change: 0 additions & 1 deletion tests/unit/API/CacheableRequestTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public function setUp() : void

require_once PLUGIN_ROOT_DIR.'/woocommerce/api/interface-sv-wc-api-request.php';
require_once PLUGIN_ROOT_DIR.'/woocommerce/api/abstract-sv-wc-api-json-request.php';
require_once PLUGIN_ROOT_DIR.'/woocommerce/api/traits/Cacheable_Request_Trait.php';
}

/**
Expand Down
57 changes: 57 additions & 0 deletions tests/unit/AutoloadingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace SkyVerge\WooCommerce\PluginFramework\v5_13_1\Tests\Unit;

use Mockery;
use SkyVerge\WooCommerce\PluginFramework\v5_13_1\Addresses as Addresses;
use SkyVerge\WooCommerce\PluginFramework\v5_13_1\Admin\Notes_Helper;
use SkyVerge\WooCommerce\PluginFramework\v5_13_1\API\Abstract_Cacheable_API_Base;
use SkyVerge\WooCommerce\PluginFramework\v5_13_1\Payment_Gateway\Blocks as Payment_Gateway_Blocks;
use SkyVerge\WooCommerce\PluginFramework\v5_13_1\Payment_Gateway\External_Checkout\Admin;
use SkyVerge\WooCommerce\PluginFramework\v5_13_1\Payment_Gateway\External_Checkout\External_Checkout;
use SkyVerge\WooCommerce\PluginFramework\v5_13_1\Payment_Gateway\External_Checkout\Frontend;
use SkyVerge\WooCommerce\PluginFramework\v5_13_1\Payment_Gateway\External_Checkout\Google_Pay as Google_Pay_Checkout;
use SkyVerge\WooCommerce\PluginFramework\v5_13_1\Payment_Gateway\External_Checkout\Orders;
use SkyVerge\WooCommerce\PluginFramework\v5_13_1\Payment_Gateway\Handlers as Handlers;
use SkyVerge\WooCommerce\PluginFramework\v5_13_1\Settings_API as Settings_API;
use SkyVerge\WooCommerce\PluginFramework\v5_13_1\Tests\TestCase;

/**
* @covers composer.json/autoload
*/
class AutoloadingTest extends TestCase
{
public function testCanAutoload() : void
{
require_once PLUGIN_ROOT_DIR.'/woocommerce/api/class-sv-wc-api-base.php';

$list = [
Handlers\Capture::class,
Handlers\Abstract_Payment_Handler::class,
Handlers\Abstract_Hosted_Payment_Handler::class,
External_Checkout::class,
Admin::class,
Frontend::class,
Orders::class,
Google_Pay_Checkout\Google_Pay::class,
Google_Pay_Checkout\Admin::class,
Google_Pay_Checkout\AJAX::class,
Google_Pay_Checkout\Frontend::class,
Payment_Gateway_Blocks\Gateway_Blocks_Handler::class,
Payment_Gateway_Blocks\Gateway_Checkout_Block_Integration::class,
Settings_API\Abstract_Settings::class,
Settings_API\Setting::class,
Settings_API\Control::class,
Abstract_Cacheable_API_Base::class,
Notes_Helper::class,
Addresses\Address::class,
Addresses\Customer_Address::class,
];

Mockery::mock('\Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType');

foreach ($list as $className) {
$this->assertInstanceOf($className, Mockery::mock($className)->makePartial());
agibson-godaddy marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
<?php

namespace SkyVerge\WooCommerce\PluginFramework\v5_13_1\Tests\Unit;
namespace SkyVerge\WooCommerce\PluginFramework\v5_13_1\Tests\Unit\Helpers;

use SkyVerge\WooCommerce\PluginFramework\v5_13_1\Country_Helper;
use SkyVerge\WooCommerce\PluginFramework\v5_13_1\Handlers\Country_Helper;
use SkyVerge\WooCommerce\PluginFramework\v5_13_1\Tests\TestCase;

class CountryHelperTest extends TestCase
{
public function setUp() : void
{
parent::setUp();

require_once PLUGIN_ROOT_DIR.'/woocommerce/Country_Helper.php';
}

/**
* @covers \SkyVerge\WooCommerce\PluginFramework\v5_13_1\Country_Helper::convert_alpha_country_code()
* @covers \SkyVerge\WooCommerce\PluginFramework\v5_13_1\Handlers\Country_Helper::convert_alpha_country_code()
*
* @dataProvider provider_convert_alpha_country_code
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

namespace SkyVerge\WooCommerce\PluginFramework\v5_13_1\Tests\Unit;
namespace SkyVerge\WooCommerce\PluginFramework\v5_13_1\Tests\Unit\Payment_Gateway;

use Generator;
use Mockery;
use ReflectionException;
use SkyVerge\WooCommerce\PluginFramework\v5_13_1\Enums\PaymentFormContext;
use SkyVerge\WooCommerce\PluginFramework\v5_13_1\PaymentFormContextChecker;
use SkyVerge\WooCommerce\PluginFramework\v5_13_1\Payment_Gateway\PaymentFormContextChecker;
use SkyVerge\WooCommerce\PluginFramework\v5_13_1\SV_WC_Helper;
use SkyVerge\WooCommerce\PluginFramework\v5_13_1\Tests\TestCase;
use WooCommerce;
Expand All @@ -23,8 +23,6 @@ public function setUp() : void
{
parent::setUp();

require_once PLUGIN_ROOT_DIR.'/woocommerce/payment-gateway/PaymentFormContextChecker.php';

$this->testObject = Mockery::mock(PaymentFormContextChecker::class)
->shouldAllowMockingProtectedMethods()
->makePartial();
Expand All @@ -40,7 +38,7 @@ public function tearDown() : void
}

/**
* @covers \SkyVerge\WooCommerce\PluginFramework\v5_13_1\PaymentFormContextChecker::getContextSessionKeyName()
* @covers \SkyVerge\WooCommerce\PluginFramework\v5_13_1\Payment_Gateway\PaymentFormContextChecker::getContextSessionKeyName()
* @throws ReflectionException
*/
public function testCanGetContextSessionKeyName() : void
Expand All @@ -54,7 +52,7 @@ public function testCanGetContextSessionKeyName() : void
}

/**
* @covers \SkyVerge\WooCommerce\PluginFramework\v5_13_1\PaymentFormContextChecker::maybeSetContext()
* @covers \SkyVerge\WooCommerce\PluginFramework\v5_13_1\Payment_Gateway\PaymentFormContextChecker::maybeSetContext()
*/
public function testCanSetContext() : void
{
Expand Down Expand Up @@ -83,7 +81,7 @@ public function testCanSetContext() : void
}

/**
* @covers \SkyVerge\WooCommerce\PluginFramework\v5_13_1\PaymentFormContextChecker::getCurrentPaymentFormContext()
* @covers \SkyVerge\WooCommerce\PluginFramework\v5_13_1\Payment_Gateway\PaymentFormContextChecker::getCurrentPaymentFormContext()
*
* @dataProvider providerCanGetCurrentPaymentFormContext
*
Expand Down Expand Up @@ -144,7 +142,7 @@ public function providerCanGetCurrentPaymentFormContext() : Generator
}

/**
* @covers \SkyVerge\WooCommerce\PluginFramework\v5_13_1\PaymentFormContextChecker::getStoredPaymentFormContext()
* @covers \SkyVerge\WooCommerce\PluginFramework\v5_13_1\Payment_Gateway\PaymentFormContextChecker::getStoredPaymentFormContext()
* @throws ReflectionException
*/
public function testCanGetStoredPaymentFormContext() : void
Expand Down Expand Up @@ -172,7 +170,7 @@ public function testCanGetStoredPaymentFormContext() : void
}

/**
* @covers \SkyVerge\WooCommerce\PluginFramework\v5_13_1\PaymentFormContextChecker::currentContextRequiresTermsAndConditionsAcceptance()
* @covers \SkyVerge\WooCommerce\PluginFramework\v5_13_1\Payment_Gateway\PaymentFormContextChecker::currentContextRequiresTermsAndConditionsAcceptance()
*
* @dataProvider providerCanDetermineCurrentContextRequiresTermsAndConditionsAcceptance
*
Expand Down
8 changes: 0 additions & 8 deletions tests/unit/Settings_API/ControlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@

class ControlTest extends TestCase
{

public function setUp() : void
{
parent::setUp();

require_once PLUGIN_ROOT_DIR.'/woocommerce/Settings_API/Control.php';
}

/**
* @covers \SkyVerge\WooCommerce\PluginFramework\v5_13_1\Settings_API\Control::get_setting_id()
* @throws SV_WC_Plugin_Exception
Expand Down
10 changes: 0 additions & 10 deletions tests/unit/Settings_API/SettingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@

class SettingTest extends TestCase
{
public function setUp() : void
{
parent::setUp();

require_once PLUGIN_ROOT_DIR.'/woocommerce/Settings_API/Abstract_Settings.php';
require_once PLUGIN_ROOT_DIR.'/woocommerce/Settings_API/Setting.php';
}

/**
* @covers \SkyVerge\WooCommerce\PluginFramework\v5_13_1\Settings_API\Setting::set_id()
*
Expand Down Expand Up @@ -303,8 +295,6 @@ public function provider_set_value() : array
*/
public function provider_set_control() : array
{
require_once PLUGIN_ROOT_DIR.'/woocommerce/Settings_API/Control.php';

$control = new Control();

return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
*/

namespace SkyVerge\WooCommerce\PluginFramework\v5_13_1;
namespace SkyVerge\WooCommerce\PluginFramework\v5_13_1\Handlers;

defined( 'ABSPATH' ) or exit;

if ( ! class_exists( '\\SkyVerge\\WooCommerce\\PluginFramework\\v5_13_1\\Country_Helper' ) ) :
use SkyVerge\WooCommerce\PluginFramework\v5_13_1\SV_WC_Plugin_Compatibility;

defined( 'ABSPATH' ) or exit;

/**
* SkyVerge Country Helper Class
Expand All @@ -42,7 +41,7 @@ class Country_Helper {


/** @var array ISO 3166-alpha2 => ISO 3166-alpha3 */
static public $alpha3 = [
static public array $alpha3 = [
'AF' => 'AFG', 'AL' => 'ALB', 'DZ' => 'DZA', 'AD' => 'AND', 'AO' => 'AGO',
'AG' => 'ATG', 'AR' => 'ARG', 'AM' => 'ARM', 'AU' => 'AUS', 'AT' => 'AUT',
'AZ' => 'AZE', 'BS' => 'BHS', 'BH' => 'BHR', 'BD' => 'BGD', 'BB' => 'BRB',
Expand Down Expand Up @@ -95,7 +94,7 @@ class Country_Helper {
];

/** @var array ISO 3166-alpha2 => ISO 3166-numeric */
static public $numeric = [
static public array $numeric = [
'AF' => '004', 'AX' => '248', 'AL' => '008', 'DZ' => '012', 'AS' => '016',
'AD' => '020', 'AO' => '024', 'AI' => '660', 'AQ' => '010', 'AG' => '028',
'AR' => '032', 'AM' => '051', 'AW' => '533', 'AU' => '036', 'AT' => '040',
Expand Down Expand Up @@ -149,7 +148,7 @@ class Country_Helper {
];

/** @var array ISO 3166-alpha2 => phone calling code(s) */
static public $calling_codes = [
static public array $calling_codes = [
'BD' => '+880',
'BE' => '+32',
'BF' => '+226',
Expand Down Expand Up @@ -657,6 +656,3 @@ public static function get_flipped_calling_codes() {


}


endif;
28 changes: 0 additions & 28 deletions woocommerce/class-sv-wc-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,27 +452,8 @@ private function includes() {
// common exception class
require_once( $framework_path . '/class-sv-wc-plugin-exception.php' );

// traits
require_once( $framework_path . '/Traits/CanGetNewInstanceTrait.php' );
require_once( $framework_path . '/Traits/IsSingletonTrait.php' );
require_once( $framework_path . '/Traits/CanConvertToArrayTrait.php' );

// helpers
require_once( $framework_path . '/Helpers/ArrayHelper.php' );

// addresses
require_once( $framework_path . '/Addresses/Address.php' );
require_once( $framework_path . '/Addresses/Customer_Address.php' );

// Settings API
require_once( $framework_path . '/Settings_API/Abstract_Settings.php' );
require_once( $framework_path . '/Settings_API/Setting.php' );
require_once( $framework_path . '/Settings_API/Control.php' );

// common utility methods
require_once( $framework_path . '/class-sv-wc-helper.php' );
require_once( $framework_path . '/Country_Helper.php' );
require_once( $framework_path . '/admin/Notes_Helper.php' );

// backwards compatibility for older WC versions
require_once( $framework_path . '/class-sv-wc-plugin-compatibility.php' );
Expand All @@ -494,25 +475,16 @@ private function includes() {
require_once( $framework_path . '/api/abstract-sv-wc-api-json-request.php' );
require_once( $framework_path . '/api/abstract-sv-wc-api-json-response.php' );

// Cacheable API
require_once( $framework_path . '/api/traits/Cacheable_Request_Trait.php' );
require_once( $framework_path . '/api/Abstract_Cacheable_API_Base.php' );

// REST API Controllers
require_once( $framework_path . '/rest-api/Controllers/Settings.php' );

// Handlers
require_once( $framework_path . '/Handlers/Script_Handler.php' );
require_once( $framework_path . '/class-sv-wc-plugin-dependencies.php' );
require_once( $framework_path . '/class-sv-wc-hook-deprecator.php' );
require_once( $framework_path . '/class-sv-wp-admin-message-handler.php' );
require_once( $framework_path . '/class-sv-wc-admin-notice-handler.php' );
require_once( $framework_path . '/Lifecycle.php' );
require_once( $framework_path . '/rest-api/class-sv-wc-plugin-rest-api.php' );

// Enums
require_once $framework_path . '/Enums/Traits/EnumTrait.php';
require_once $framework_path . '/Enums/PaymentFormContext.php';
}


Expand Down
5 changes: 0 additions & 5 deletions woocommerce/payment-gateway/Blocks/Gateway_Blocks_Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
use SkyVerge\WooCommerce\PluginFramework\v5_13_1\Blocks\Blocks_Handler;
use SkyVerge\WooCommerce\PluginFramework\v5_13_1\SV_WC_Payment_Gateway_Plugin;


use function Patchwork\Redefinitions\LanguageConstructs\_require_once;

if ( ! class_exists( '\\SkyVerge\\WooCommerce\\PluginFramework\\v5_13_1\\Payment_Gateway\Blocks\\Gateway_Blocks_Handler' ) ) :

/**
Expand Down Expand Up @@ -59,8 +56,6 @@ public function handle_blocks_integration() : void {
/** @var SV_WC_Payment_Gateway_Plugin $plugin */
$plugin = $this->plugin;

require_once( $plugin->get_payment_gateway_framework_path() . '/Blocks/Gateway_Checkout_Block_Integration.php' );

foreach ( $plugin->get_gateways() as $gateway ) {

if ( $checkout_integration = $gateway->get_checkout_block_integration_instance() ) {
Expand Down
3 changes: 2 additions & 1 deletion woocommerce/payment-gateway/PaymentFormContextChecker.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

namespace SkyVerge\WooCommerce\PluginFramework\v5_13_1;
namespace SkyVerge\WooCommerce\PluginFramework\v5_13_1\Payment_Gateway;

use SkyVerge\WooCommerce\PluginFramework\v5_13_1\Enums\PaymentFormContext;
use SkyVerge\WooCommerce\PluginFramework\v5_13_1\SV_WC_Helper;

/**
* Helper class for setting and checking the page context that a payment form for a given gateway is rendered on.
Expand Down
Loading
Loading