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

[8.x] cast Expression as string so it can be encoded #34569

Merged
merged 1 commit into from
Sep 28, 2020

Conversation

browner12
Copy link
Contributor

If we pass an Expression to our database assertion, because it contains no public properties, when it is JSON encoded it will always return '{}', which is unhelpful to us in debugging.

this PR is far from an ideal solution, as the entire expression will be returned to the output, but it's better than the empty object it currently returns.

for example:

$this->assertDatabaseHas('users', [
    'name' => 'Andy',
    'skills' => $this->castAsJson(['laravel', 'vue', 'tailwind']),
];

If this is not found in the database it would currently output:

Failed asserting that a row in the table [dealers] matches the attributes {
    "name": "Andy",
    "skills": {},
}.

With this PR, it will instead output:

Failed asserting that a row in the table [dealers] matches the attributes {
    "name": "Andy",
    "skills": "CAST('[\"laravel\",\"vue\",\"tailwind\"]' AS JSON)",
}.

Again, not ideal, but at least the data is there for us to compare against.

because the `Expression` contains no public properties, when it is JSON encoded, it will always return '{}', which is unhelpful to us in debugging.
@taylorotwell taylorotwell merged commit a4b8981 into laravel:8.x Sep 28, 2020
@browner12 browner12 deleted the patch-1 branch September 28, 2020 20:48
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