Code Monkey home page Code Monkey logo

Comments (3)

lucatume avatar lucatume commented on June 12, 2024

Hi, this is the right place to ask the question.

What I think is happening: you are telling the WPDb module it should populate the database before each test and the module is doing exactly that but using an empty SQL dump file.

The WPDb module will reset the database to a pristine state before each test; this is to avoid tests from influencing each other and create false positives or false negatives.
Think of a first test method creating a post and of a second method creating a post; if the second method tried to assert the database should contain 1 post it would fail as the database actually contains the post created from the first test method too.
The 3 parameters you have to look at here in WPDb configuration are:

  • dump - this tells the WPDb module that, when asked to repopulate the database, it should use this SQL dump file
  • populate - this tells the module that it should populate the database using the dump file before running each test case (the class)
  • cleanup - this tells the module that is should populate the database using the dump file before each test method

The WPDb module is an extension of Codeception Db module so the same documentation applies.

What I usually do when setting up my tests is go through the installation manually, activate the theme/plugins I need and then run some wp-cli scripts:

wp site empty --yes
wp theme activate my-theme
wp plugin activate one two three my-plugin
wp db export wp-content/plugins/my-plugin/tests/_data/dump.sql

where the commands should point/specify themes/plugins you need and the real location of that tests/_data/dump.sql file.

from wp-browser.

Flyaway87 avatar Flyaway87 commented on June 12, 2024

Obviously I missed all the dump.sql part... Now it works perfectly!
Many thanks for all the tips, that's really appreciated :)

from wp-browser.

lucatume avatar lucatume commented on June 12, 2024

You are welcome, closing as solved.

from wp-browser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.