Skip to content

Commit

Permalink
Add deprecation warnings to HasMany
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 16, 2017
1 parent 7eaa9ef commit b0ebd29
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/ORM/Association/HasMany.php
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
22 changes: 19 additions & 3 deletions tests/TestCase/ORM/Association/HasManyTest.php
Expand Up @@ -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());
}

/**
Expand Down

0 comments on commit b0ebd29

Please sign in to comment.