Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
40 changes: 40 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: PHPUnit

on:
pull_request:
branches: ["**"]
push:
branches: ["master"]

permissions:
contents: read

jobs:
phpunit:
name: Run PHPUnit
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php: ["8.4"]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer
coverage: none

- name: Validate composer.json
run: composer validate --no-interaction

- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist

- name: Run tests
run: vendor/bin/phpunit
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### v4.15.1 (2026-01-19)
* * *

### Regression Bug Fixes:
* Fix list fields to accept JSON objects with explicit numeric keys. [Reference](https://github.com/chargebee/chargebee-php/pull/116#issuecomment-3715071348).
* Add `PHPUnit` test case coverage workflow on pull request.

### v4.15.0 (2026-01-16)
* * *

Expand Down
2 changes: 1 addition & 1 deletion src/ValueObjects/Encoders/URLFormEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private static function serialize($value, $prefix = null, $idx = null, $jsonKeys
$key = (!is_null($prefix) ? $prefix : '') .
(!is_null($prefix) ? '[' . $usK . ']' : $usK) .
(!is_null($idx) ? '[' . $idx . ']' : '');
$serialized[$key] = is_string($v)?$v:json_encode($v, JSON_FORCE_OBJECT);
$serialized[$key] = is_string($v) ? $v : json_encode((is_array($v) && $v === []) ? (object)[] : $v);
} else if (is_array($v) && !is_int($k)) {
$tempPrefix = (!is_null($prefix)) ? $prefix . '[' . Util::toUnderscoreFromCamelCase($k) . ']' : Util::toUnderscoreFromCamelCase($k);
$serialized = array_merge($serialized, self::serialize($v, $tempPrefix, null, $jsonKeys, $level + 1));
Expand Down
2 changes: 1 addition & 1 deletion src/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

final class Version
{
const VERSION = '4.15.0';
const VERSION = '4.15.1';
}

?>
28 changes: 28 additions & 0 deletions tests/ValueObjects/Encoder/URLFormEncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,32 @@ public function testEncodeParamsWithAEmptyJsonAttribute(): void {
$this->assertIsString($encoded);
$this->assertSame("first_name=John&last_name=Doe&meta_data=%7B%7D", $encoded);
}

/** Convert params to URL-form encoding. Do not transform json arrays to array based indexing. it should not ItemPriceId { "0" => "some_price_id"} */
/** id=foo&name=foo&discount_percentage=10&apply_on=each_specified_item&item_constraints[constraint][0]=specific&item_constraints[item_type][0]=plan&item_constraints[item_price_ids][0]=["some_price_id"] */
public function testEncodeParamsShouldNotUseArrayBasedIndexingForJsonArray(): void
{
$params = [
'id' => 'foo',
'name' => 'foo',
'discount_percentage' => 10.0,
'apply_on' => 'each_specified_item',
'item_constraints' => [
[
'constraint' => 'specific',
'item_type' => 'plan',
'item_price_ids' => [
'some_price_id',
],
],
],
];

$json_keys = [
"itemPriceIds" => 1
];
$encoded = URLFormEncoder::encode($params, $json_keys);
$this->assertIsString($encoded);
$this->assertSame("id=foo&name=foo&discount_percentage=10&apply_on=each_specified_item&item_constraints%5Bconstraint%5D%5B0%5D=specific&item_constraints%5Bitem_type%5D%5B0%5D=plan&item_constraints%5Bitem_price_ids%5D%5B0%5D=%5B%22some_price_id%22%5D", $encoded);
}
}