WordPress.org

Make WordPress Core

Opened 10 months ago

Last modified 3 weeks ago

#39975 new task (blessed)

Remove direct calls to '/tmp/' in Unit Tests

Reported by: joemcgill Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: has-patch
Focuses: Cc:

Description

As noted by @mikeschroder in 39875, there are several places in our unit tests where we assume the temp directory is '/tmp/' and make direct calls. Instead, we should use something like wp_tempnam() to ensure we're writing and removing files from the right place during tests.

Attachments (3)

39975.01.patch (6.5 KB) - added by DJPaul 8 months ago.
39975.2.diff (7.5 KB) - added by christophherr 3 weeks ago.
Replaces three additional occurrences of /tmp in phpunittests/widgets
39975.3.diff (9.0 KB) - added by christophherr 3 weeks ago.
Removes symlinks from phpunit/tests/link/themeFile.php using parts of @danielhueskens patch on #40856

Download all attachments as: .zip

Change History (7)

@DJPaul
8 months ago

#1 @DJPaul
8 months ago

  • Keywords has-patch added; needs-patch removed

Please see 39975.01.patch which makes the requested change. There is one whitespace change (space at the end of the line) accidentally included.

#3 @netweb
7 months ago

Related, possible duplicate: #40856

@christophherr
3 weeks ago

Replaces three additional occurrences of /tmp in phpunittests/widgets

@christophherr
3 weeks ago

Removes symlinks from phpunit/tests/link/themeFile.php using parts of @danielhueskens patch on #40856

#4 @christophherr
3 weeks ago

This would greatly improve the unit test experience on Windows.

39975.2 replaces additional usages of /tmp from three files in phpunit/tests/widgets
39975.1 and 30075.2 remove 157 errors.

39975.3 replaces symlinks from phpunit/tests/link/themeFile.php using parts of @danielhuesken 's patch on #40856.
On Windows 10 with PHP 7.1.11, this removes the following warnings:

Warning: unlink(C:\laragon\www\trunk/src/wp-content\themes\theme-file-parent): Permission denied in C:\laragon\www\trunk\tests\phpunit\tests\link\themeFile.php on line 13

Warning: unlink(C:\laragon\www\trunk/src/wp-content\themes\theme-file-child): Permission denied in C:\laragon\www\trunk\tests\phpunit\tests\link\themeFile.php on line 14

and also avoids additional warnings when the tests are run again (because unlink didn't remove the symlink in the previous run) :

Warning: symlink(): Cannot create symlink, error code(183) in C:\laragon\www\trunk\tests\phpunit\tests\link\themeFile.php on line 8

Warning: symlink(): Cannot create symlink, error code(183) in C:\laragon\www\trunk\tests\phpunit\tests\link\themeFile.php on line 9

6 failures remain after 39975.3:

1) Tests_WP_Customize_Manager::test_import_theme_starter_content
Expected reuse of non-auto-draft attachment.
Failed asserting that an array contains 914.

C:\laragon\www\trunk\tests\phpunit\tests\customize\manager.php:644

2) Tests_DB::test_mysqli_flush_sync
procedure could not be created (missing privileges?)

C:\laragon\www\trunk\tests\phpunit\tests\db.php:621

3) Test_Theme_File::test_theme_file_uri_returns_valid_uri with data set #0 ('parent-only.php', 'theme-file-parent', array('theme-file-parent'))
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-''
+'C:\laragon\www\trunk\tests\phpunit\includes/../data/themedir1/default/parent-only.php'

C:\laragon\www\trunk\tests\phpunit\tests\link\themeFile.php:117

4) Test_Theme_File::test_theme_file_uri_returns_valid_uri with data set #1 ('child-only.php', 'theme-file-child', array('theme-file-child'))
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-''
+'C:\laragon\www\trunk\tests\phpunit\includes/../data/themedir1/default/child-only.php'

C:\laragon\www\trunk\tests\phpunit\tests\link\themeFile.php:117

5) Test_Theme_File::test_theme_file_uri_returns_valid_uri with data set #2 ('parent-and-child.php', 'theme-file-child', array('theme-file-parent', 'theme-file-child'))
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-''
+'C:\laragon\www\trunk\tests\phpunit\includes/../data/themedir1/default/parent-and-child.php'

C:\laragon\www\trunk\tests\phpunit\tests\link\themeFile.php:117

6) Test_Theme_File::test_theme_file_uri_returns_valid_uri with data set #3 ('neither.php', 'theme-file-parent', array())
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-''
+'C:\laragon\www\trunk\tests\phpunit\includes/../data/themedir1/default/neither.php'

C:\laragon\www\trunk\tests\phpunit\tests\link\themeFile.php:117
Last edited 3 weeks ago by christophherr (previous) (diff)
Note: See TracTickets for help on using tickets.