Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.x] Add castAsJson() to Database #53

Closed
wants to merge 1 commit into from
Closed

[2.x] Add castAsJson() to Database #53

wants to merge 1 commit into from

Conversation

phh
Copy link
Contributor

@phh phh commented Nov 29, 2023

Q A
Bug fix? no
New feature? yes

If you want to work with assertDatabaseHas() and determine if some json exists, you need to cast it as json, using the $this->castsAsJson(). This adds the proxy method that already exists in InteractsWithDatabase.

Usage:

assertDatabaseHas('posts', [
    'data'   => castAsJson(['status' => 'publish'])
]);

@phh
Copy link
Contributor Author

phh commented Nov 29, 2023

When trying to either use string, array or something like that you just get "wierd" errors like:

Failed asserting that a row in the table [posts] matches the attributes {
    "data": "{\"status\": \"publish\"}"
}.

Found: [
    {
        "data": "{\"status\": \"publish\"}"
    }
].

@phh
Copy link
Contributor Author

phh commented Nov 29, 2023

Seems like a duplicate of #42

@phh phh closed this Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant