Use PHP 7.4 featers and PHP 8 polyfills

This commit is contained in:
David Stone
2025-02-08 13:57:32 -07:00
parent 8bea6067cd
commit b41dc2b2eb
550 changed files with 15270 additions and 14627 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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('');

View File

@ -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);

View File

@ -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.