Skip to content

Conversation

@gcatanese
Copy link
Contributor

Add test to verify JSON serialisation (i.e. attributes with default value are not included)

@gcatanese gcatanese requested a review from a team as a code owner July 9, 2025 09:34
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @gcatanese, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new unit test to validate the JSON serialization logic for request models within the Adyen Checkout SDK. The primary goal is to ensure that complex data structures, such as CreateCheckoutSessionRequest with nested Amount and LineItem objects, are correctly transformed into their expected JSON representation, confirming proper attribute inclusion and formatting.

Highlights

  • Comprehensive Serialization Validation: The test constructs a sample CreateCheckoutSessionRequest with various populated fields and asserts that its json_encoded output precisely matches a predefined expected JSON string, ensuring correct structure and data representation.
  • Dependency Addition: The Adyen\Model\Checkout\LineItem class has been imported to support the creation of LineItem objects within the new test case.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request adds a test case to verify the JSON serialization of the CreateCheckoutSessionRequest model, ensuring that attributes with default values are not included in the serialized output. Suggestions were made to improve the test's readability and maintainability by adding a comment explaining the test's purpose, extracting common parameters to constants, and using json_encode to generate the expected JSON string.

Comment on lines +386 to +387
public function testJsonSerializationMatchesExpected()
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It's good to see a test for JSON serialization. Consider adding a comment explaining the purpose of this test, specifically that it verifies attributes with default values are not included in the JSON output. This enhances readability and maintainability.

    /**
     * Test request JSON payload serialization
     * Verifies that attributes with default values are not included in the JSON output.
     */
    public function testJsonSerializationMatchesExpected()

Comment on lines +401 to +404
->setMerchantAccount('YOUR_MERCHANT_ACCOUNT')
->setReference('YOUR_PAYMENT_REFERENCE')
->setReturnUrl('https://mycompany.example.org/redirect?orderRef=YOUR_PAYMENT_REFERENCE')
->setLineItems([$lineItem1, $lineItem2]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider extracting the common parameters used in the CreateCheckoutSessionRequest to constants. This improves readability and maintainability, especially if these values are used in other tests as well.

        $merchantAccount = 'YOUR_MERCHANT_ACCOUNT';
        $paymentReference = 'YOUR_PAYMENT_REFERENCE';

        $request = new CreateCheckoutSessionRequest();
        $request
            ->setChannel('Web')
            ->setAmount($amount)
            ->setCountryCode('NL')
            ->setMerchantAccount($merchantAccount)
            ->setReference($paymentReference)
            ->setReturnUrl('https://mycompany.example.org/redirect?orderRef=' . $paymentReference)
            ->setLineItems([$lineItem1, $lineItem2]);

Comment on lines +406 to +430
$expectedJson = <<<JSON
{
"channel": "Web",
"amount": {
"currency": "EUR",
"value": 10000
},
"countryCode": "NL",
"merchantAccount": "YOUR_MERCHANT_ACCOUNT",
"reference": "YOUR_PAYMENT_REFERENCE",
"returnUrl": "https://mycompany.example.org/redirect?orderRef=YOUR_PAYMENT_REFERENCE",
"lineItems": [
{
"quantity": 1,
"amountIncludingTax": 5000,
"description": "Sunglasses"
},
{
"quantity": 1,
"amountIncludingTax": 5000,
"description": "Headphones"
}
]
}
JSON;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The expectedJson is defined as a HEREDOC string. While this is valid, consider using json_encode with the JSON_PRETTY_PRINT option to generate the expected JSON string from a PHP array. This approach can improve readability and reduce the risk of syntax errors in the JSON string.

        $expectedJson = json_encode([
            "channel" => "Web",
            "amount" => [
                "currency" => "EUR",
                "value" => 10000
            ],
            "countryCode" => "NL",
            "merchantAccount" => 'YOUR_MERCHANT_ACCOUNT',
            "reference" => 'YOUR_PAYMENT_REFERENCE',
            "returnUrl" => "https://mycompany.example.org/redirect?orderRef=YOUR_PAYMENT_REFERENCE",
            "lineItems" => [
                [
                    "quantity" => 1,
                    "amountIncludingTax" => 5000,
                    "description" => "Sunglasses"
                ],
                [
                    "quantity" => 1,
                    "amountIncludingTax" => 5000,
                    "description" => "Headphones"
                ]
            ]
        ], JSON_PRETTY_PRINT);

@gcatanese gcatanese merged commit 7c9e261 into main Jul 9, 2025
7 checks passed
@gcatanese gcatanese deleted the add-serialisation-test branch July 9, 2025 09:40
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 9, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants