Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
While looking at \Drupal\Tests\file\Functional\FileFieldDisplayTest::testNodeDisplay()
I noticed the following snippet:
$test_file = $this->getTestFile('text');
simpletest_generate_file('escaped-&-text', 64, 10, 'text');
$test_file = File::create([
'uri' => 'public://escaped-&-text.txt',
'name' => 'escaped-&-text',
'filesize' => filesize('public://escaped-&-text.txt'),
]);
As you can see that $test_file
variable is being overwritten by File::create()
call and there is a simpletest_generate_file()
call which should be avoided because this is a PHPUnit test.
Proposed resolution
- Remove
$test_file = $this->getTestFile('text');
- replace
simpletest_generate_file()
call with its equivalent$this->generateFile()
Remaining tasks
Write patch
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Comment | File | Size | Author |
---|---|---|---|
#3 | remove-unused-local-var-simpletest_generate_file-2985317-3.patch | 826 bytes | msankhala |
Comments
Comment #2
msankhala CreditAttribution: msankhala as a volunteer and at Srijan | A Material+ Company commentedComment #3
msankhala CreditAttribution: msankhala as a volunteer and at Srijan | A Material+ Company commentedHere is the patch
Comment #4
surbz CreditAttribution: surbz at Srijan | A Material+ Company commentedThanks for this patch @msankhala
This makes more sense now and the patch applies cleanly as well.
// \m/
Comment #5
surbz CreditAttribution: surbz at Srijan | A Material+ Company commentedComment #6
alexpottCommitted and pushed 7ee41bffbc to 8.7.x and e1db334696 to 8.6.x. Thanks!