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

Easy command to run Seeders #47

Closed
jasonagnew opened this issue Nov 26, 2020 · 1 comment · Fixed by #61 or #70
Closed

Easy command to run Seeders #47

jasonagnew opened this issue Nov 26, 2020 · 1 comment · Fixed by #61 or #70
Assignees
Labels
enhancement New feature or request

Comments

@jasonagnew
Copy link
Member

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

yarn wp-cypress wp "seed {SeederName}"

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

yarn wp-cypress seed {SeederName}

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.

@liamdefty liamdefty added the enhancement New feature or request label Nov 27, 2020
@liamdefty liamdefty removed their assignment Mar 25, 2021
@ampersarnie
Copy link
Member

ampersarnie commented Apr 23, 2021

@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 tear_down() method that can be added to seeders as well as a cy.tearDown() function to call that within the *.spec.js tests. I'm also extending the seeding command to have the tear-down flag to run the seeder tear down.

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' );
		}
	}
}

@ampersarnie ampersarnie self-assigned this Apr 23, 2021
@ampersarnie ampersarnie linked a pull request Apr 29, 2021 that will close this issue
4 tasks
@con322 con322 mentioned this issue Jul 16, 2021
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants