fix: PHP 8.3 TypeError on Articles admin page (v2.5.1) (#32)
Squash-merge of PR #32 — QA APPROVED (2026-06-17 SHA 5c483fdc)
Agent-Session: 2026-06-17-phase1-vps-runner-deploy-500fixes
This commit is contained in:
34
tests/unit/ArticlesListTotalCastTest.php
Normal file
34
tests/unit/ArticlesListTotalCastTest.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Test that articles list total count is cast to int.
|
||||
*
|
||||
* @package Peptide_News
|
||||
*/
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ArticlesListTotalCastTest extends TestCase {
|
||||
/**
|
||||
* Verify that $wpdb->get_var returning a numeric string does not
|
||||
* cause a TypeError in number_format() (PHP 8.3 strict typing).
|
||||
*/
|
||||
public function test_total_cast_prevents_type_error() {
|
||||
$total_as_string = '451'; // what $wpdb->get_var() returns
|
||||
$total = (int) $total_as_string;
|
||||
$this->assertIsInt( $total );
|
||||
$this->assertSame( 451, $total );
|
||||
// This should not throw TypeError on PHP 8.3
|
||||
$formatted = number_format( $total );
|
||||
$this->assertSame( '451', $formatted );
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify null return (missing table) results in 0, not a TypeError.
|
||||
*/
|
||||
public function test_null_total_cast_to_zero() {
|
||||
$total = (int) null;
|
||||
$this->assertSame( 0, $total );
|
||||
$formatted = number_format( $total );
|
||||
$this->assertSame( '0', $formatted );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user