-
Notifications
You must be signed in to change notification settings - Fork 21
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
Easy command to run Seeders #47
Comments
@jasonagnew There has been a couple of things that I've found I wanted to add to this recently and this issue is one. I'm working on an addition that would help with this. Executing a teardown before seeding is the not correct place for that action, as it's supposed to be used as the last execution as part of the clean up routine, I've got something which should work for your needs though. So I have an early version of a I'll get a PR in as soon as I'm finished testing and cleaning up. Some examples: Command yarn wp-cypress wp "seed CategoriesSeeder --tear-down" Spec describe("Categories.", () => {
before(() => {
cy.seed("CategoriesSeeder");
});
it("I can add a new category.", () => {
cy.visitAdmin();
cy.visit("/wp-admin/edit-tags.php?taxonomy=category");
// ...
});
after(() => {
cy.tearDown("CategoriesSeeder");
});
}); Seeder <?php
use WP_Cypress\Seeder\Seeder;
use WP_Cypress\Fixtures;
class CategoriesSeeder extends Seeder {
const CATEGORIES = [
'Test',
'New Test',
];
public function run() {
foreach( self::CATEGORIES as $category ) {
wp_insert_term( $category, 'category' );
}
}
public function tear_down() {
foreach( self::CATEGORIES as $category ) {
$term = get_term_by( 'name', $category, 'category' );
wp_delete_term( $term->term_id, 'category' );
}
}
} |
Is your feature request related to a problem? Please describe.
It's not always clear to users of WP Cypress how to easily test Seeders while developing them. I would typically
The other issue is having teardown for Seeder would be useful, so its possible to keep re-running it.
Describe the solution you'd like
Provide a direct command
Provide
teardown/down()
method on seeders that would be run before the Seeder is called with this command.Describe alternatives you've considered
While working on seeder it is easy enough to create your own down method and have it called before your Seeder and remove it once done.
Additional context
Although not a big issue it's more about giving less familiar people more guidance.
The text was updated successfully, but these errors were encountered: