Skip to content

Conversation

kbond
Copy link
Member

@kbond kbond commented Jul 11, 2022

Per a slack discussion with @nikophil.

Assert::that('[4, 5, 6]')
    ->isJson() // json_decode's the current value and starts a new expectation with this
    ->contains(5)
;

Assert::that('5')
    ->isJson() 
    ->is(5)
    ->isGreaterThan(4)
;

@kbond kbond added the enhancement New feature or request label Jul 11, 2022
@kbond
Copy link
Member Author

kbond commented Jul 11, 2022

Not sure we want to do this but wanted to capture our conversation with a POC. We could go even further and move the Json class from zenstruck/browser here (and have Expectation::isJson(): Json).

*
* Fails if not a valid json string.
*/
public function isJson(): self
Copy link
Member

Choose a reason for hiding this comment

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

not sure of the name: it sounds like it's just an expectation, but it does more... decodeJson() ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, this tripped me up as well. Technically it is also an expectation but is not clear that it changes the underlying data.

I chose this purely because the api reads better: "assert that value is json" vs "assert that value decode json". I definitely probably get too hung up on these semantics 😄.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

2 participants