Use PHP 7.4 featers and PHP 8 polyfills
This commit is contained in:
@ -9,11 +9,11 @@ class Dashboard_Admin_Page_Test extends WP_UnitTestCase {
|
||||
/**
|
||||
* Test the register_scripts method enqueues the necessary scripts and styles.
|
||||
*/
|
||||
public function test_register_scripts() {
|
||||
public function test_register_scripts(): void {
|
||||
// Create a mock instance of Dashboard_Admin_Page and call the register_scripts method
|
||||
$dashboard_admin_page = $this->getMockBuilder(Dashboard_Admin_Page::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('output'))
|
||||
->setMethods(['output'])
|
||||
->getMock();
|
||||
|
||||
// Fake dates for testing
|
||||
|
@ -33,7 +33,7 @@ class Membership_Edit_Admin_Page_Test extends WP_UnitTestCase {
|
||||
$this->swap_time = strtotime('+100 days');
|
||||
|
||||
$this->membership = current($faker->get_fake_data_generated('memberships'));
|
||||
$cart = new Cart(array());
|
||||
$cart = new Cart([]);
|
||||
$this->membership->schedule_swap($cart, gmdate('Y-m-d H:i:s', $this->swap_time));
|
||||
// Mock Membership_Edit_Admin_Page with dependencies and methods.
|
||||
$this->membership_edit_admin_page = new Membership_Edit_Admin_Page();
|
||||
@ -43,7 +43,7 @@ class Membership_Edit_Admin_Page_Test extends WP_UnitTestCase {
|
||||
/**
|
||||
* Tests that page_loaded calls add_swap_notices.
|
||||
*/
|
||||
public function test_page_loaded_calls_add_swap_notices() {
|
||||
public function test_page_loaded_calls_add_swap_notices(): void {
|
||||
$_REQUEST['id'] = $this->membership->get_id();
|
||||
$this->membership_edit_admin_page->page_loaded();
|
||||
|
||||
|
@ -7,7 +7,7 @@ use WP_Ultimo\Managers\Gateway_Manager;
|
||||
|
||||
class Gateway_Functions_Test extends \WP_UnitTestCase {
|
||||
|
||||
public function test_wu_get_gateway_returns_false_for_invalid_id() {
|
||||
public function test_wu_get_gateway_returns_false_for_invalid_id(): void {
|
||||
$invalid_gateway_id = 'non_existent_gateway';
|
||||
|
||||
$result = wu_get_gateway($invalid_gateway_id);
|
||||
@ -15,7 +15,7 @@ class Gateway_Functions_Test extends \WP_UnitTestCase {
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
public function test_wu_get_gateway_returns_instance_for_valid_id() {
|
||||
public function test_wu_get_gateway_returns_instance_for_valid_id(): void {
|
||||
$valid_gateway_id = 'manual';
|
||||
|
||||
$gateway = wu_get_gateway($valid_gateway_id);
|
||||
|
@ -3,7 +3,7 @@
|
||||
namespace WP_Ultimo;
|
||||
|
||||
class Date_Functions_Test extends \WP_UnitTestCase {
|
||||
public function test_wu_get_days_ago() {
|
||||
public function test_wu_get_days_ago(): void {
|
||||
$days = wu_get_days_ago('2024-01-01 00:00:00', '2024-01-31 00:00:00');
|
||||
|
||||
$this->assertEquals(-30, $days);
|
||||
|
@ -10,7 +10,7 @@ class Discount_Code_Test extends WP_UnitTestCase {
|
||||
/**
|
||||
* Tests that a valid discount code returns true.
|
||||
*/
|
||||
public function test_is_valid_active_discount_code() {
|
||||
public function test_is_valid_active_discount_code(): void {
|
||||
$discount_code = new Discount_Code();
|
||||
$discount_code->set_active(true);
|
||||
|
||||
@ -22,7 +22,7 @@ class Discount_Code_Test extends WP_UnitTestCase {
|
||||
/**
|
||||
* Tests that an inactive discount code returns an error.
|
||||
*/
|
||||
public function test_is_valid_inactive_discount_code() {
|
||||
public function test_is_valid_inactive_discount_code(): void {
|
||||
$discount_code = new Discount_Code();
|
||||
$discount_code->set_active(false);
|
||||
|
||||
@ -36,7 +36,7 @@ class Discount_Code_Test extends WP_UnitTestCase {
|
||||
/**
|
||||
* Tests that a discount code with max uses returns an error after being used maximum times.
|
||||
*/
|
||||
public function test_is_valid_max_uses_exceeded() {
|
||||
public function test_is_valid_max_uses_exceeded(): void {
|
||||
$discount_code = new Discount_Code();
|
||||
$discount_code->set_active(true);
|
||||
$discount_code->set_max_uses(5);
|
||||
@ -55,7 +55,7 @@ class Discount_Code_Test extends WP_UnitTestCase {
|
||||
/**
|
||||
* Tests that a discount code before the start date is invalid.
|
||||
*/
|
||||
public function test_is_valid_before_start_date() {
|
||||
public function test_is_valid_before_start_date(): void {
|
||||
$discount_code = new Discount_Code();
|
||||
$discount_code->set_active(true);
|
||||
$discount_code->set_date_start(date('Y-m-d H:i:s', strtotime('+1 day')));
|
||||
@ -70,7 +70,7 @@ class Discount_Code_Test extends WP_UnitTestCase {
|
||||
/**
|
||||
* Tests that a discount code after the expiration date is invalid.
|
||||
*/
|
||||
public function test_is_valid_after_expiration_date() {
|
||||
public function test_is_valid_after_expiration_date(): void {
|
||||
$discount_code = new Discount_Code();
|
||||
$discount_code->set_active(true);
|
||||
$discount_code->set_date_expiration(date('Y-m-d H:i:s', strtotime('-1 day')));
|
||||
@ -85,12 +85,12 @@ class Discount_Code_Test extends WP_UnitTestCase {
|
||||
/**
|
||||
* Tests that a discount code limited to specific products returns true for allowed products.
|
||||
*/
|
||||
public function test_is_valid_for_allowed_product() {
|
||||
public function test_is_valid_for_allowed_product(): void {
|
||||
$product_id = 123;
|
||||
$discount_code = new Discount_Code();
|
||||
$discount_code->set_active(true);
|
||||
$discount_code->set_limit_products(true);
|
||||
$discount_code->set_allowed_products(array($product_id));
|
||||
$discount_code->set_allowed_products([$product_id]);
|
||||
|
||||
$result = $discount_code->is_valid($product_id);
|
||||
|
||||
@ -100,13 +100,13 @@ class Discount_Code_Test extends WP_UnitTestCase {
|
||||
/**
|
||||
* Tests that a discount code limited to specific products returns an error for disallowed products.
|
||||
*/
|
||||
public function test_is_valid_for_disallowed_product() {
|
||||
public function test_is_valid_for_disallowed_product(): void {
|
||||
$allowed_product_id = 123;
|
||||
$disallowed_product_id = 456;
|
||||
$discount_code = new Discount_Code();
|
||||
$discount_code->set_active(true);
|
||||
$discount_code->set_limit_products(true);
|
||||
$discount_code->set_allowed_products(array($allowed_product_id));
|
||||
$discount_code->set_allowed_products([$allowed_product_id]);
|
||||
|
||||
$result = $discount_code->is_valid($disallowed_product_id);
|
||||
|
||||
@ -118,7 +118,7 @@ class Discount_Code_Test extends WP_UnitTestCase {
|
||||
/**
|
||||
* Tests that a discount code with no product limits returns true.
|
||||
*/
|
||||
public function test_is_valid_no_product_limits() {
|
||||
public function test_is_valid_no_product_limits(): void {
|
||||
$discount_code = new Discount_Code();
|
||||
$discount_code->set_active(true);
|
||||
$discount_code->set_limit_products(false);
|
||||
|
@ -9,7 +9,7 @@ class Domain_Test extends WP_UnitTestCase {
|
||||
/**
|
||||
* Test that has_valid_ssl_certificate returns true for valid SSL certificates.
|
||||
*/
|
||||
public function test_has_valid_ssl_certificate_with_valid_certificate() {
|
||||
public function test_has_valid_ssl_certificate_with_valid_certificate(): void {
|
||||
// Mocking a domain with a valid SSL certificate.
|
||||
$domain = new Domain();
|
||||
$domain->set_domain('dogs.4thelols.uk');
|
||||
@ -21,7 +21,7 @@ class Domain_Test extends WP_UnitTestCase {
|
||||
/**
|
||||
* Test that has_valid_ssl_certificate returns false when the SSL certificate is invalid.
|
||||
*/
|
||||
public function test_has_valid_ssl_certificate_with_invalid_certificate() {
|
||||
public function test_has_valid_ssl_certificate_with_invalid_certificate(): void {
|
||||
// Mocking a domain with an invalid SSL certificate.
|
||||
$domain = new Domain();
|
||||
$domain->set_domain('eeeeeeeeeeeeeeeeauauexample.com');
|
||||
@ -33,7 +33,7 @@ class Domain_Test extends WP_UnitTestCase {
|
||||
/**
|
||||
* Test that has_valid_ssl_certificate handles empty domain.
|
||||
*/
|
||||
public function test_has_valid_ssl_certificate_with_empty_domain() {
|
||||
public function test_has_valid_ssl_certificate_with_empty_domain(): void {
|
||||
// Mocking a domain with an empty value.
|
||||
$domain = new Domain();
|
||||
$domain->set_domain('');
|
||||
|
@ -32,9 +32,9 @@ class Membership_Test extends \WP_UnitTestCase {
|
||||
/**
|
||||
* Test if the customer is allowed access to the membership.
|
||||
*/
|
||||
public function test_is_customer_allowed() {
|
||||
public function test_is_customer_allowed(): void {
|
||||
// Admins with 'manage_network' capability should always return true.
|
||||
$admin_user_id = $this->factory()->user->create(array('role' => 'administrator'));
|
||||
$admin_user_id = $this->factory()->user->create(['role' => 'administrator']);
|
||||
grant_super_admin($admin_user_id);
|
||||
wp_set_current_user($admin_user_id);
|
||||
$this->assertTrue($this->membership->is_customer_allowed(), 'Failed asserting that admin is allowed.');
|
||||
@ -58,7 +58,7 @@ class Membership_Test extends \WP_UnitTestCase {
|
||||
/**
|
||||
* Test adding a product to the membership.
|
||||
*/
|
||||
public function test_add_product() {
|
||||
public function test_add_product(): void {
|
||||
// Add a product with a specific ID and quantity.
|
||||
$quantity = 2;
|
||||
$faker = new Faker();
|
||||
@ -92,7 +92,7 @@ class Membership_Test extends \WP_UnitTestCase {
|
||||
/**
|
||||
* Test removing a product from the membership.
|
||||
*/
|
||||
public function test_remove_product() {
|
||||
public function test_remove_product(): void {
|
||||
// Add a product with a specific quantity.
|
||||
$quantity = 5;
|
||||
$faker = new Faker();
|
||||
@ -123,7 +123,7 @@ class Membership_Test extends \WP_UnitTestCase {
|
||||
/**
|
||||
* Test get_remaining_days_in_cycle() method.
|
||||
*/
|
||||
public function test_get_remaining_days_in_cycle() {
|
||||
public function test_get_remaining_days_in_cycle(): void {
|
||||
$this->membership->set_amount(12.99);
|
||||
// Case 1: Non-recurring membership should return 10000.
|
||||
$this->membership->set_recurring(false);
|
||||
|
@ -9,11 +9,11 @@ class Dashboard_Taxes_Tab_Test extends WP_UnitTestCase {
|
||||
/**
|
||||
* Test that register_scripts method registers the correct scripts.
|
||||
*/
|
||||
public function test_register_scripts_registers_scripts() {
|
||||
public function test_register_scripts_registers_scripts(): void {
|
||||
// Create a mock instance of Dashboard_Admin_Page and call the register_scripts method.
|
||||
$dashboard_admin_page = $this->getMockBuilder(Dashboard_Taxes_Tab::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('output'))
|
||||
->setMethods(['output'])
|
||||
->getMock();
|
||||
|
||||
// Execute register_scripts method.
|
||||
|
@ -11,7 +11,7 @@ class WP_Ultimo_Test extends \WP_UnitTestCase {
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLoadAllHelperFunctionsCorrectly() {
|
||||
public function testLoadAllHelperFunctionsCorrectly(): void {
|
||||
// Assert that all helper functions are loaded correctly.
|
||||
// This is all done in the bootstrap.
|
||||
$this->assertTrue(function_exists('wu_to_float'));
|
||||
@ -19,13 +19,13 @@ class WP_Ultimo_Test extends \WP_UnitTestCase {
|
||||
$this->assertTrue(function_exists('wu_get_initials'));
|
||||
}
|
||||
|
||||
public function testLoaded() {
|
||||
public function testLoaded(): void {
|
||||
$wpUltimo = \WP_Ultimo();
|
||||
$this->assertTrue($wpUltimo->version === \WP_Ultimo::VERSION);
|
||||
$this->assertTrue($wpUltimo->is_loaded());
|
||||
}
|
||||
|
||||
public function testPublicProperties() {
|
||||
public function testPublicProperties(): void {
|
||||
$wpUltimo = \WP_Ultimo();
|
||||
$this->assertTrue($wpUltimo->settings instanceof Settings);
|
||||
$this->assertTrue($wpUltimo->helper instanceof Helper);
|
||||
|
Reference in New Issue
Block a user