Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 16, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 16, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 16, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 16, 2025

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025

      Minecraft licensing robbed us of this controversial NFL schedule release video

      May 16, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The power of generators

      May 16, 2025
      Recent

      The power of generators

      May 16, 2025

      Simplify Factory Associations with Laravel’s UseFactory Attribute

      May 16, 2025

      This Week in Laravel: React Native, PhpStorm Junie, and more

      May 16, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025
      Recent

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Assert the Exact JSON Structure of a Response in Laravel 11.19

    Assert the Exact JSON Structure of a Response in Laravel 11.19

    July 31, 2024

    The Laravel team released v11.19 this week, including asserting the exact JSON structure, a whereNone query builder method, a Number::trim() method, HTML assertion convenience methods, and more.

    A stand-out contributor in Laravel 11.19 is Günther Debrauwer, who contributed four pull requests to the framework this week!

    Add assertExactJsonStructure() Test Method

    Günther Debrauwer contributed the assertExactJsonStructure() to ensure that a test response completely follows an expected structure:

    /*
    Given the following response:
    {
    “data”: {
    “id”: 1,
    “firstname”: “Taylor”,
    “lastname”: “Otwell”
    }
    }
    */

    // This fails
    $response->assertExactJsonStructure([
    ‘data’ => [
    ‘firstname’,
    ‘lastname’,
    ],
    ]);

    // This succeeds
    $response->assertExactJsonStructure([
    ‘data’ => [
    ‘id’,
    ‘firstname’,
    ‘lastname’,
    ],
    ]);

    The assertJsonStructure() method will pass in both of the above examples, so you can use the exact version to ensure the entire shape of the response matches.

    Add whereNone Method to the Query Builder

    Einar Hansen contributed the whereNone to compliment the whereAny and whereAll methods:

    $users = DB::table(‘users’)
    ->where(‘active’, true)
    ->whereNone([
    ‘first_name’,
    ‘last_name’,
    ’email’,
    ], ‘LIKE’, ‘einar%’)
    ->get();
    /*
    SELECT *
    FROM users
    WHERE active = true AND NOT (
    first_name LIKE ‘einar%’ OR
    last_name LIKE ‘einar%’ OR
    email LIKE ‘einar%’
    )
    */

    See Pull Request #52260 for more details.

    Add withoutHeader Test Method

    Günther Debrauwer contributed a withoutHeader() method when making test requests. This method could be useful if you have a default header that you want to send with each request but also want to write a test when the header is not present:

    $this->withoutHeader(‘Foo’)->get(…);

    Add assertSeeHtml Test Methods

    Günther Debrauwer contributed three new HTML assertions that are syntactic sugar for assertSee() with escape disabled:

    $response->assertSeeHtml(‘<li>foo</li>’);

    $response->assertSeeHtmlInOrder([
    ‘<li>foo</li>’, ‘<li>bar</li>’, ‘<li>baz</li>’
    ]);

    $response->assertDontSeeHtml(‘<li>foo</li>’);

    // The new methods are equivalent to using `assertSee*` methods without escaping HTML:
    $response->assertSee(value: ‘<li>foo</li>’, escape: false);

    Add a Number::trim() Method

    Günther Debrauwer contributed a Number::trim() method that trims 0 digits after the decimal point of a given number:

    $this->assertSame(12, Number::trim(12));
    $this->assertSame(120, Number::trim(120));
    $this->assertSame(12, Number::trim(12.0));
    $this->assertSame(12.3, Number::trim(12.3));
    $this->assertSame(12.3, Number::trim(12.30));
    $this->assertSame(12.3456789, Number::trim(12.3456789));
    $this->assertSame(12.3456789, Number::trim(12.34567890000));

    One use-case in the Pull Request is that json_encode() will convert a float number that doesn’t have any digits after the decimal point:

    json_encode([‘value’ => 4.0, ‘another’ => 5.21340]);
    // = “{“value”:4,”another”:5.2134}

    When asserting these values in a test, you can use the Number::trim() to match this behavior.

    Release notes

    You can see the complete list of new features and updates below and the diff between 11.18.0 and 11.19.0 on GitHub. The following release notes are directly from the changelog:

    v11.19.0

    fix @return typehint in IlluminateContractsProcessInvokedProcess::wait method by @mdmahbubhelal in https://github.com/laravel/framework/pull/52304

    [11.x] Add php doc for ServiceProvider bindings and singletons properties by @Anton5360 in https://github.com/laravel/framework/pull/52298

    [10.x] backport #52188 by @calebdw in https://github.com/laravel/framework/pull/52293

    Update docblock to accept an Expression for whereLike methods by @patrickomeara in https://github.com/laravel/framework/pull/52299

    [11.x] Fix Bcrypt/Argon/Argon2I Hashers not checking database field for nullish value before checking hash compatibility by @localpath in https://github.com/laravel/framework/pull/52297

    [11.x] Method to trim ‘0’ digits after decimal point of a given number by @gdebrauwer in https://github.com/laravel/framework/pull/52284

    [11.x] Add whereNone method to the query builder by @einar-hansen in https://github.com/laravel/framework/pull/52260

    [11.x] Fix flat array parameter for relation upsert by @iamgergo in https://github.com/laravel/framework/pull/52289

    [11.x] assertSeeHtml, assertDontSeeHtml and assertSeeHtmlInOrder testing methods by @gdebrauwer in https://github.com/laravel/framework/pull/52285

    [11.x] Fully qualify morph columns when using WHERE clauses by @maartenpaauw in https://github.com/laravel/framework/pull/52227

    [10.x] Fix runPaginationCountQuery not working properly for union queries by @chinleung in https://github.com/laravel/framework/pull/52314

    [11.x] Add assertExactJsonStructure method by @gdebrauwer in https://github.com/laravel/framework/pull/52311

    [11.x] Add withoutHeader() test method by @gdebrauwer in https://github.com/laravel/framework/pull/52309

    [11.x] Widen typehints in base service provider by @devfrey in https://github.com/laravel/framework/pull/52308

    [11.X] “Model::preventAccessingMissingAttributes()” Causes Exception During Pagination with ResourceCollection by @Katalam in https://github.com/laravel/framework/pull/52305

    [11.x] Fixes through() relationship by @leobeal in https://github.com/laravel/framework/pull/52318

    [11.x] Add new success Method to the Docblock of IlluminateConsoleViewComponentsFactory by @devajmeireles in https://github.com/laravel/framework/pull/52310

    [11.x] Fix tests in wrong file by @christophrumpel in https://github.com/laravel/framework/pull/52329

    The post Assert the Exact JSON Structure of a Response in Laravel 11.19 appeared first on Laravel News.

    Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleOpenAI starts rolling out advanced Voice Mode to ChatGPT Plus users
    Next Article Perficient is a 2024 Top Workplace in Orange County

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 17, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-4610 – WordPress WP-Members Membership Plugin Stored Cross-Site Scripting Vulnerability

    May 17, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    CVE-2025-4384 – PcVue MQTT Certificate Validation Bypass

    Common Vulnerabilities and Exposures (CVEs)

    Top Free Optimization Software for Optimal Windows Performance

    Development

    Immediate Action Required: Critical Apache InLong Vulnerability Exploitable

    Development

    Understanding results of the cloud based load test in VSTS

    Development

    Highlights

    Development

    Researchers at KAUST Use Anderson Exploitation to Maximize GPU Efficiency with Greater Model Accuracy and Generalizability

    November 2, 2024

    Escalation in AI implies an increased infrastructure expenditure. The massive and multidisciplinary research exerts economic…

    The Pros and Cons of Using Variables in Figma Prototypes

    June 17, 2024

    Prestazioni a Confronto: Quale Scegliere tra il kernel Linux Liquorix e il kernel Linux 6.12?

    December 23, 2024

    CVE-2025-30377 – Microsoft Office Use After Free Remote Code Execution Vulnerability

    May 13, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.