Skip to content

Commit

Permalink
Merge pull request #389 from Phillaf/master
Browse files Browse the repository at this point in the history
Prevent erasing _config that's been set in the constructor
  • Loading branch information
josegonzalez committed Jun 7, 2016
2 parents b2b9ff6 + c314b44 commit ff3801f
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<blacklist>
<directory suffix=".php">./docs</directory>
<directory suffix=".php">./vendor</directory>
<directory suffix=".php">./tests</directory>
<file>./tests/bootstrap.php</file>
</blacklist>
</filter>
Expand Down
1 change: 0 additions & 1 deletion src/Model/Behavior/UploadBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public function initialize(array $config)
}
}

$this->_config = [];
$this->config($configs);

Type::map('upload.file', 'Josegonzalez\Upload\Database\Type\FileType');
Expand Down
41 changes: 41 additions & 0 deletions tests/Fixture/FilesFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
namespace Josegonzalez\Upload\Test\Fixture;

use Cake\TestSuite\Fixture\TestFixture;

class FilesFixture extends TestFixture
{
public $table = 'files';

/**
* fields property
*
* @var array
*/
public $fields = [
'id' => ['type' => 'integer'],
'filename' => ['type' => 'integer'],
'created' => ['type' => 'datetime', 'null' => true],
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]]
];

/**
* records property
*
* @var array
*/
public $records = [
['filename' => 'FileOne'],
['filename' => 'FileTwo'],
['filename' => 'FileThree'],
];

public function init()
{
$created = $modified = date('Y-m-d H:i:s');
array_walk($this->records, function (&$record) use ($created, $modified) {
$record += compact('created');
});
parent::init();
}
}
9 changes: 9 additions & 0 deletions tests/Stub/ChildBehavior.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
namespace Josegonzalez\Upload\Test\Stub;

use Josegonzalez\Upload\Model\Behavior\UploadBehavior;

class ChildBehavior extends UploadBehavior
{
protected $_defaultConfig = ['key' => 'value'];
}
16 changes: 16 additions & 0 deletions tests/TestCase/Model/Behavior/UploadBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@
use Cake\Event\Event;
use Cake\ORM\Entity;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use Josegonzalez\Upload\Model\Behavior\UploadBehavior;
use Josegonzalez\Upload\Test\Stub\ChildBehavior;
use ReflectionClass;

class UploadBehaviorTest extends TestCase
{
public $fixtures = [
'plugin.Josegonzalez/Upload.Files',
];

public function setup()
{
$this->entity = $this->getMock('Cake\ORM\Entity');
Expand Down Expand Up @@ -71,6 +77,16 @@ public function testInitialize()
$behavior->initialize($this->settings);
}

public function testInheritedConfig()
{
$table = TableRegistry::get('Josegonzales/Upload.Files');
$behavior = new ChildBehavior($table, []);

$result = $behavior->config();
$expected = ['key' => 'value'];
$this->assertEquals($expected, $result);
}

public function testInitializeIndexedConfig()
{
$settings = ['field'];
Expand Down

0 comments on commit ff3801f

Please sign in to comment.