FriendsOfCake / cakephp-upload

CakePHP: Handle file uploading sans ridiculous automagic
https://cakephp-upload.readthedocs.io/
MIT License
551 stars 255 forks source link

Test Fixtures have type `upload.file` for upload field. #574

Closed tbelknapsgs closed 3 years ago

tbelknapsgs commented 3 years ago

I'm assuming this is a pretty simple bug. Version: 5.0.1 Cake: 4.1

Generating a new fixture for a table that has an uploadable file field. The output fixture marks the field type as "upload.file" rather than varchar.

davidyell commented 3 years ago

This is because it reads the schema for the table class, which stipulates that column type so the behaviour can process the file.

You'll need to manually change your fixture. There was some discussion about the root issue , but I can't find it now, the upshot was that the data type class should implement the base type of string.

Perhaps that needs to happen in the plugin? Either through class FileType extends StringType

tbelknapsgs commented 3 years ago

Thank you, David. This makes sense, just wasn't sure if this was the expected behavior, or not. Closing ticket.

AdrianHL commented 2 years ago

I found this issue happening when running filtered tests.

The solution we found is to load the plugin in the test class so that the application was bootstrapped as expected as described in https://book.cakephp.org/4/en/development/testing.html#integration-testing-psr-7-middleware

PS. The app is on CakePHP 4.2, PHP 8.1 and PHPUnit 9.5.

RichardPiel commented 1 year ago

I got same error but i don't use fixtures but migrations to initialize test database.

Do you have solution to avoid this behavior ?

Thanks

Edit: i loaded plugin in my test case, but i always got the same error. Edit2: Fixed, i had to load plugins before parent::setUp();

angelxmoreno commented 6 days ago

I encountered a similar issue, and initially thought it was related to my fixture setup. However, the third edit by RichardPiel was the solution that resolved it for me. Additionally, I ensured that the Josegonzalez/Upload plugin was loaded in my tests by adding the setUp() method in the ApplicationTest class:

protected function setUp(): void {
    parent::setUp();
    $this->loadPlugins(['Josegonzalez/Upload']);
}