You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using UploadedFile::fake()->image('image.jpg'). Instead of producing a fake image it cuts the test and produce Test code or tested code did not (only) close its own output buffers.
This is a snippet code of my test.
test('author can create a new book', function () {
$cover = UploadedFile::fake()->image('image.jpg');
$response = actingAs($this->user)->post(
uri: route('books.store') ,
data:[
'book_title' => 'Book Title 1',
'synopsis' => 'Book Test Sample Synopsis',
'tags' => $this->tags->random(5),
'genres' => $this->genres->random(3),
'cover_photo' => $cover,
]
);
$response->assertValid();
assertDatabaseHas(Book::class,[
'book_title' => 'Book Title 1',
'synopsis' => 'Book Test Sample Synopsis',
]);
});
Test Result :
WARN Tests\Feature\Author\AuthorBookTest
! author can create a new book → Test code or tested code did not (only) close its own output buffers 1.30s
Tests: 1 risky (0 assertions)
Duration: 1.82s
Im using PestPHP but I also try it in PHPUnit. It's still the same. But using UploadedFile::fake()->create() works.
Steps To Reproduce
Just how you normally create a new test.
php artisan make:test Author/AuthorBookTest
Type the test.
php artisan test --filter=AuthorBookTest
The text was updated successfully, but these errors were encountered:
Did you try creating a fresh repo and testing this? I just tried and could not reproduce. I'm not sure if it's something within your controller that is causing the issue or if it is actually UploadedFile::fake() that is causing the problem.
Are you running via Docker? What platform/architecture are you on? What version of PHPUnit are you running? Could you upload a repo with the minimal amount of data to produce the issue so we can triage this problem?
I submitted a PR to phpunit since the risky message doesn't indicate whether or not output buffers were closed. That would help diagnose the exact problem.
Thank you for the response @cosmastech. When I created a fresh repo and tried to test it again, it did not indicate as risky but produce an error undefined method imagecreatetruecolor() and after further research I found out that I need to uncomment the gd extension in php.ini file and it solves the problem.
Laravel Version
10.8.0
PHP Version
8.2
Database Driver & Version
No response
Description
Using
UploadedFile::fake()->image('image.jpg')
. Instead of producing a fake image it cuts the test and produce Test code or tested code did not (only) close its own output buffers.This is a snippet code of my test.
Test Result :
Im using PestPHP but I also try it in PHPUnit. It's still the same. But using
UploadedFile::fake()->create()
works.Steps To Reproduce
Just how you normally create a new test.
php artisan make:test Author/AuthorBookTest
php artisan test --filter=AuthorBookTest
The text was updated successfully, but these errors were encountered: