WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 4 years ago

#29020 closed task (blessed) (fixed)

Unit tests for dbDelta()

Reported by: jdgrimes Owned by: jorbin
Milestone: 4.3 Priority: normal
Severity: normal Version: 4.0
Component: Upgrade/Install Keywords: has-patch
Focuses: Cc:
PR Number:

Description

The dbDelta() function is kind of a mess, and also very buggy. There are several open tickets seeking to improve it:

#10404
#28591
#20634
#20263
#14445

...

Let's pave the way for them by adding some basic unit tests for the function, which can be expanded to test the enhancements/bugfixes.

Attachments (4)

29020.diff (5.8 KB) - added by jdgrimes 5 years ago.
Initial tests
29020.2.diff (5.7 KB) - added by jdgrimes 5 years ago.
29020.3.diff (6.4 KB) - added by salcode 4 years ago.
29020.4.diff (1.3 KB) - added by tryon 4 years ago.
Insert test

Download all attachments as: .zip

Change History (19)

@jdgrimes
5 years ago

Initial tests

#1 @jdgrimes
5 years ago

  • Keywords has-patch added

29020.diff is a first pass. Once applied, run

$ phpunit tests/phpunit/tests/admin/functions/dbdelta.php
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests... To execute these, use --group ajax.
PHPUnit 3.7.28 by Sebastian Bergmann.

Configuration read from /Users/johngrimes/svn/wordpress/trunk/phpunit.xml.dist

..S....

Time: 10.83 seconds, Memory: 24.50Mb

OK, but incomplete or skipped tests!
Tests: 7, Assertions: 10, Skipped: 1.

Skipped test is for backticks, related to #20263.

#2 follow-up: @nacin
5 years ago

Awesome, thanks! Let's toss the tests for #20263 into that ticket, rather than committing them now. (Now that we have a merged repo, they should be committed with the code to fix it.)

The best place for these tests is likely tests/phpunit/tests/db/dbDelta.php, class name Tests_DB_dbDelta. (Alternatively, tests/phpunit/tests/admin/includesUpgrade.php, class Tests_Admin_includesUpgrade.)

@jdgrimes
5 years ago

#3 in reply to: ↑ 2 @jdgrimes
5 years ago

Replying to nacin:

Awesome, thanks! Let's toss the tests for #20263 into that ticket, rather than committing them now. (Now that we have a merged repo, they should be committed with the code to fix it.)

The best place for these tests is likely tests/phpunit/tests/db/dbDelta.php, class name Tests_DB_dbDelta. (Alternatively, tests/phpunit/tests/admin/includesUpgrade.php, class Tests_Admin_includesUpgrade.)

29020.2.diff moves the tests to tests/phpunit/tests/db/dbDelta.php, changes the class name, and removes the tests for #20263.

#4 @DrewAPicture
5 years ago

  • Component changed from General to Upgrade/Install

29020.2.diff still applies.

#5 @jorbin
5 years ago

  • Milestone changed from Awaiting Review to 4.3

20920.2.diff looks like some good tests that are all currently passing.

I would like to see this combined with the tests added in [32108], likely by making those tests better (using the setup and teardown functions here for example ).

@pento - any thoughts on these tests?

#6 @obenland
5 years ago

  • Owner set to jorbin
  • Status changed from new to assigned

#7 @pento
5 years ago

29020.2.diff is a good start.

I suspect dbDelta() unit tests will be an ongoing effort, much like unit tests for wpautop(). As we discover more edge cases, add more unit tests.

@salcode
4 years ago

#8 @salcode
4 years ago

Merges patch 29020.2.diff changes into existing tests file

Patch created at WordCamp Philly 2015
@tryon
@jtsternberg
@ebinnion
@JPry
@avnarun
@kevkoeh
@jorbin
@salcode

#9 @jorbin
4 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 32770:

Improve dbDelta unit tests

Add new tests for more parts of dbDelta. This was cleaned up and prepared for commit at #wcphilly contributor day.

Props jdgrimes, tryon, jtsternberg, ebinnion, JPry, avnarun, kevkoeh, jorbin, salcode.
Fixes #29020.

@tryon
4 years ago

Insert test

#10 @tryon
4 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Added 'Insert Into' test for dbdelta

Patch created at WordCamp Philly 2015

#11 @obenland
4 years ago

@jorbin, can you check on that additional patch and commit/close when you get a chance?

This ticket was mentioned in Slack in #core by helen. View the logs.


4 years ago

This ticket was mentioned in Slack in #core by obenland. View the logs.


4 years ago

#14 @obenland
4 years ago

  • Type changed from enhancement to task (blessed)

#15 @jorbin
4 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 33175:

Add dbDelta insert test

Test to make sure that dbDelta properly inserts a value into the DB.

Props tryon, jtsternberg, ebinnion, JPry, avnarun, kevkoeh, salcode.
Fixes #29020.

Note: See TracTickets for help on using tickets.