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

Feature Request: assertable method returns in architecture tests #1305

Open
josephkerkhof opened this issue Oct 23, 2024 · 2 comments
Open

Comments

@josephkerkhof
Copy link

I would love to use Pest's architecture test framework to perform assertions on what methods return.

My personal use case is to assert that my project's Http controller public methods (invokable or otherwise) return objects that inherit from LaravelData.

@danielh-official
Copy link

$response = get('route')->assertOk();

$json = $response->json();

# some code to determine that the response json is tied to LaravelData

Correct me if I'm wrong, but response JSON always resolves to array (in PHP), so you can't really tell what object they inherited from.

If you're testing the method directly, then toBeInstanceOf could help you with determining the inheritance of returned object.

https://pestphp.com/docs/expectations#expect-toBeInstanceOf

@josephkerkhof
Copy link
Author

This works if you're testing the method itself, but I want to be able to perform an architecture test on the controllers in my code. I don't want to invoke the method.

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

No branches or pull requests

2 participants