Skip to content

Commit

Permalink
Merge pull request #415 from slywalker/fix-error-when-class-name
Browse files Browse the repository at this point in the history
Fixed error when class name was specified
  • Loading branch information
josegonzalez committed Nov 21, 2016
2 parents 90f3f8a + 73d9cc9 commit f0982d7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Model/Behavior/UploadBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function initialize(array $config)
}

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

Type::map('upload.file', 'Josegonzalez\Upload\Database\Type\FileType');
$schema = $this->_table->schema();
Expand Down
31 changes: 30 additions & 1 deletion tests/TestCase/Model/Behavior/UploadBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function testInitialize()
$property->setAccessible(true);
$property->setValue($behavior, $table);

$behavior->expects($this->exactly(2))
$behavior->expects($this->exactly(3))
->method('config')
->will($this->returnValue($this->settings));

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

public function testInitializeAddBehaviorOptionsInterfaceConfig()
{
$settings = [
'className' => 'Josegonzalez\Upload\Model\Behavior\UploadBehavior',
'field' => []
];
$table = $this->getMock('Cake\ORM\Table');
$schema = $this->getMock('Cake\Database\Schema\Table', [], [$table, []]);
$schema->expects($this->once())
->method('columnType')
->with('field', 'upload.file');
$table->expects($this->at(0))
->method('schema')
->will($this->returnValue($schema));
$table->expects($this->at(1))
->method('schema')
->will($this->returnValue($schema));

$methods = array_diff($this->behaviorMethods, ['initialize', 'config']);
$behavior = $this->getMock('Josegonzalez\Upload\Model\Behavior\UploadBehavior', $methods, [$table, $settings], '', false);
$reflection = new ReflectionClass($behavior);
$property = $reflection->getProperty('_table');
$property->setAccessible(true);
$property->setValue($behavior, $table);
$behavior->initialize($settings);

$this->assertEquals(['field' => []], $behavior->config());
}

public function testBeforeMarshalOk()
{
$validator = $this->getMock('Cake\Validation\Validator');
Expand Down

0 comments on commit f0982d7

Please sign in to comment.