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

Add withCount support #920

Merged
merged 11 commits into from
Jan 18, 2025
Merged

Conversation

SergeAntonets
Copy link

@SergeAntonets SergeAntonets commented Nov 18, 2024

This PR adds withCount to the ResponseFromApiResource and will be supported by the factoryCreate model source

@SergeAntonets SergeAntonets changed the title Draft: Add withCount support WIP: Add withCount support Nov 18, 2024
@SergeAntonets
Copy link
Author

Hi @shalvah, I am finalizing the PR and want to add some test coverage, but it actually requires adding a database to test the "withCount" feature. Additionally, I don't see any tests related to the "with" feature, likely because it also requires a database, which might be why it's missing.

Any thouths/suggestions around this? thanks

@SergeAntonets SergeAntonets changed the title WIP: Add withCount support Add withCount support Nov 19, 2024
@SergeAntonets SergeAntonets marked this pull request as ready for review November 19, 2024 23:13
@shalvah
Copy link
Contributor

shalvah commented Nov 20, 2024

There are some tests that do use a database (SQLite in memory). We even have migrations. Example:

Schema::create('users', function ($table) {
$table->id();
});

You can follow the example.

@SergeAntonets SergeAntonets changed the title Add withCount support [WIP] Add withCount support Nov 22, 2024
@SergeAntonets SergeAntonets changed the title [WIP] Add withCount support Add withCount support Nov 22, 2024
@SergeAntonets
Copy link
Author

@shalvah, thanks. I missed that. The PR is ready; please take a look whenever you have time.

@shalvah
Copy link
Contributor

shalvah commented Nov 29, 2024

Is the withCount() method not supported on older Laravel versions? If so, you can skip the test using something like

if (phpversion() < 8.1) {
$this->markTestSkipped('Enums are only supported in PHP 8.1 or later');
}
. I've forgotten how, but Laravel provides a method to get the framework version.

@SergeAntonets
Copy link
Author

@shalvah fixed! The "whenCounted" method was introduced in Laravel v9. See: laravel/framework#43101

PS: added a few more checks

Sergey Antonets and others added 3 commits November 29, 2024 22:11
@shalvah shalvah changed the base branch from master to vNext January 18, 2025 20:39
@shalvah shalvah merged commit 8a2884e into knuckleswtf:vNext Jan 18, 2025
7 checks passed
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