From 8b1bcc49b89dc0ab347892135ca75b64a005c5e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Pustu=C5=82ka?= Date: Mon, 15 May 2017 15:18:36 +0200 Subject: [PATCH] Updated `add*()` methods to return `$this` for method chaining. --- src/ORM/Table.php | 12 +++++++++--- tests/TestCase/ORM/TableTest.php | 13 ++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/ORM/Table.php b/src/ORM/Table.php index 19d6c280745..5e76b9626b2 100644 --- a/src/ORM/Table.php +++ b/src/ORM/Table.php @@ -816,13 +816,15 @@ public function entityClass($name = null) * * @param string $name The name of the behavior. Can be a short class reference. * @param array $options The options for the behavior to use. - * @return void + * @return $this * @throws \RuntimeException If a behavior is being reloaded. * @see \Cake\ORM\Behavior */ public function addBehavior($name, array $options = []) { $this->_behaviors->load($name, $options); + + return $this; } /** @@ -837,12 +839,14 @@ public function addBehavior($name, array $options = []) * ``` * * @param string $name The alias that the behavior was added with. - * @return void + * @return $this * @see \Cake\ORM\Behavior */ public function removeBehavior($name) { $this->_behaviors->unload($name); + + return $this; } /** @@ -908,7 +912,7 @@ public function associations() * keys are used the values will be treated as association aliases. * * @param array $params Set of associations to bind (indexed by association type) - * @return void + * @return $this * @see \Cake\ORM\Table::belongsTo() * @see \Cake\ORM\Table::hasOne() * @see \Cake\ORM\Table::hasMany() @@ -925,6 +929,8 @@ public function addAssociations(array $params) $this->{$assocType}($associated, $options); } } + + return $this; } /** diff --git a/tests/TestCase/ORM/TableTest.php b/tests/TestCase/ORM/TableTest.php index f25f1dd2688..7fa5b9a3ef0 100644 --- a/tests/TestCase/ORM/TableTest.php +++ b/tests/TestCase/ORM/TableTest.php @@ -822,7 +822,8 @@ public function testAddAssociations() ]; $table = new Table(['table' => 'dates']); - $table->addAssociations($params); + $result = $table->addAssociations($params); + $this->assertSame($table, $result); $associations = $table->associations(); @@ -1550,7 +1551,8 @@ public function testAddBehavior() 'table' => 'articles', 'behaviors' => $mock ]); - $table->addBehavior('Sluggable'); + $result = $table->addBehavior('Sluggable'); + $this->assertSame($table, $result); } /** @@ -1561,8 +1563,8 @@ public function testAddBehavior() public function testAddBehaviorDuplicate() { $table = new Table(['table' => 'articles']); - $this->assertNull($table->addBehavior('Sluggable', ['test' => 'value'])); - $this->assertNull($table->addBehavior('Sluggable', ['test' => 'value'])); + $this->assertSame($table, $table->addBehavior('Sluggable', ['test' => 'value'])); + $this->assertSame($table, $table->addBehavior('Sluggable', ['test' => 'value'])); try { $table->addBehavior('Sluggable', ['thing' => 'thing']); $this->fail('No exception raised'); @@ -1589,7 +1591,8 @@ public function testRemoveBehavior() 'table' => 'articles', 'behaviors' => $mock ]); - $table->removeBehavior('Sluggable'); + $result = $table->removeBehavior('Sluggable'); + $this->assertSame($table, $result); } /**