diff --git a/src/ORM/Association/HasMany.php b/src/ORM/Association/HasMany.php index 454a8034cde..4335327ba96 100644 --- a/src/ORM/Association/HasMany.php +++ b/src/ORM/Association/HasMany.php @@ -141,6 +141,10 @@ public function getSaveStrategy() */ public function saveStrategy($strategy = null) { + deprecationWarning( + 'HasMany::saveStrategy() is deprecated. ' . + 'Use setSaveStrategy()/getSaveStrategy() instead.' + ); if ($strategy !== null) { $this->setSaveStrategy($strategy); } @@ -630,6 +634,10 @@ public function getSort() */ public function sort($sort = null) { + deprecationWarning( + 'HasMany::sort() is deprecated. ' . + 'Use setSort()/getSort() instead.' + ); if ($sort !== null) { $this->setSort($sort); } diff --git a/tests/TestCase/ORM/Association/HasManyTest.php b/tests/TestCase/ORM/Association/HasManyTest.php index 67373dbe8a2..e47ae21e61d 100644 --- a/tests/TestCase/ORM/Association/HasManyTest.php +++ b/tests/TestCase/ORM/Association/HasManyTest.php @@ -137,14 +137,30 @@ public function testCanBeJoined() /** * Tests sort() method * + * @group deprecated * @return void */ public function testSort() + { + $this->deprecated(function () { + $assoc = new HasMany('Test'); + $this->assertNull($assoc->sort()); + $assoc->sort(['id' => 'ASC']); + $this->assertEquals(['id' => 'ASC'], $assoc->sort()); + }); + } + + /** + * Tests setSort() method + * + * @return void + */ + public function testSetSort() { $assoc = new HasMany('Test'); - $this->assertNull($assoc->sort()); - $assoc->sort(['id' => 'ASC']); - $this->assertEquals(['id' => 'ASC'], $assoc->sort()); + $this->assertNull($assoc->getSort()); + $assoc->setSort(['id' => 'ASC']); + $this->assertEquals(['id' => 'ASC'], $assoc->getSort()); } /**