Skip to content

Commit f0982d7

Browse files
authored
Merge pull request #415 from slywalker/fix-error-when-class-name
Fixed error when class name was specified
2 parents 90f3f8a + 73d9cc9 commit f0982d7

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Model/Behavior/UploadBehavior.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function initialize(array $config)
3535
}
3636

3737
$this->config($configs);
38+
$this->config('className', null);
3839

3940
Type::map('upload.file', 'Josegonzalez\Upload\Database\Type\FileType');
4041
$schema = $this->_table->schema();

tests/TestCase/Model/Behavior/UploadBehaviorTest.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testInitialize()
7070
$property->setAccessible(true);
7171
$property->setValue($behavior, $table);
7272

73-
$behavior->expects($this->exactly(2))
73+
$behavior->expects($this->exactly(3))
7474
->method('config')
7575
->will($this->returnValue($this->settings));
7676

@@ -113,6 +113,35 @@ public function testInitializeIndexedConfig()
113113
$this->assertEquals(['field' => []], $behavior->config());
114114
}
115115

116+
public function testInitializeAddBehaviorOptionsInterfaceConfig()
117+
{
118+
$settings = [
119+
'className' => 'Josegonzalez\Upload\Model\Behavior\UploadBehavior',
120+
'field' => []
121+
];
122+
$table = $this->getMock('Cake\ORM\Table');
123+
$schema = $this->getMock('Cake\Database\Schema\Table', [], [$table, []]);
124+
$schema->expects($this->once())
125+
->method('columnType')
126+
->with('field', 'upload.file');
127+
$table->expects($this->at(0))
128+
->method('schema')
129+
->will($this->returnValue($schema));
130+
$table->expects($this->at(1))
131+
->method('schema')
132+
->will($this->returnValue($schema));
133+
134+
$methods = array_diff($this->behaviorMethods, ['initialize', 'config']);
135+
$behavior = $this->getMock('Josegonzalez\Upload\Model\Behavior\UploadBehavior', $methods, [$table, $settings], '', false);
136+
$reflection = new ReflectionClass($behavior);
137+
$property = $reflection->getProperty('_table');
138+
$property->setAccessible(true);
139+
$property->setValue($behavior, $table);
140+
$behavior->initialize($settings);
141+
142+
$this->assertEquals(['field' => []], $behavior->config());
143+
}
144+
116145
public function testBeforeMarshalOk()
117146
{
118147
$validator = $this->getMock('Cake\Validation\Validator');

0 commit comments

Comments
 (0)