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

Make keyed data accessible with ActiveFixture #11445

Merged
merged 8 commits into from
Jun 20, 2022

Conversation

nfourtythree
Copy link
Contributor

Description

Craft's implementation of ActiveFixture overrides the load method. In doing so it is not populating the data property during the process.

This causes an issue as it means if you are using this class you are unable to retrieve the data from the fixture. Using $this->tester->grabFixture('my-fixture', 'alias-key') returns null. This PR fixes that issue and will now return the data for that fixture.

This all gives great flexibility when writing tests that use fixtures as you will be able to write assertions based on the actual data without having to do any extra queries.

@nfourtythree nfourtythree added the testing ✅ features related to testing label Jun 15, 2022
@nfourtythree nfourtythree requested a review from a team as a code owner June 15, 2022 10:24
@nfourtythree nfourtythree self-assigned this Jun 15, 2022
@@ -63,7 +63,8 @@ public function load(): void
throw new InvalidArgumentException('Unable to save fixture data');
}

$this->ids[] = $arInstance->id;
$this->data[$key] = array_merge($row, $arInstance->toArray());
Copy link
Member

Choose a reason for hiding this comment

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

Should this be just $this->data[$key] = $arInstance; ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes probably, I think I got a bit tunnel-visioned trying to keep it close to the base method in Yii's `ActiveFixture class: https://github.com/yiisoft/yii2/blob/master/framework/test/ActiveFixture.php#L86

@brandonkelly brandonkelly changed the base branch from develop to 4.1 June 20, 2022 14:21
@brandonkelly brandonkelly merged commit ce0c03c into 4.1 Jun 20, 2022
@brandonkelly brandonkelly deleted the feature/active-fixture-keyed-data branch June 20, 2022 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing ✅ features related to testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants