Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix problem caused by duplicate config merging. #580

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Model/Behavior/UploadBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class UploadBehavior extends Behavior
*/
public function initialize(array $config): void
{
unset($config['className']);

$configs = [];
foreach ($config as $field => $settings) {
if (is_int($field)) {
Expand All @@ -46,8 +48,7 @@ public function initialize(array $config): void
}
}

$this->setConfig($configs);
$this->setConfig('className', null);
$this->setConfig($configs, null, false);

$schema = $this->_table->getSchema();
/** @var string $field */
Expand Down
11 changes: 8 additions & 3 deletions tests/TestCase/Model/Behavior/UploadBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -743,13 +743,13 @@ public function testNameCallback()
$table = $this->getTableLocator()->get('Files');
$behavior = new ChildBehavior($table, [
'filename' => [
'nameCallback' => function ($table, $entity, $data, $field, $settings) {
return 'Awesome Filename.png';
},
'nameCallback' => [$this, 'nameCallback'],
'transformer' => SlugTransformer::class,
],
]);

$this->assertSame([$this, 'nameCallback'], $behavior->getConfig('filename.nameCallback'));

$event = new Event('Model.beforeSave', $table);
$entity = new Entity([
'filename' => $this->dataOk['field'],
Expand All @@ -763,4 +763,9 @@ public function testNameCallback()

$this->assertEquals($expected, $behavior->constructedFiles);
}

public function nameCallback($table, $entity, $data, $field, $settings)
{
return 'Awesome Filename.png';
}
}