Skip to content

Commit

Permalink
Update usage of deprecated TableRegistry.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jul 22, 2020
1 parent 519f7a4 commit 8d45c21
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 94 deletions.
25 changes: 12 additions & 13 deletions tests/TestCase/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace Search\Test\TestCase;

use Cake\Core\Configure;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use InvalidArgumentException;
use Search\Manager;
Expand All @@ -25,7 +24,7 @@ class ManagerTest extends TestCase
*/
public function testShorthandMethods()
{
$table = TableRegistry::get('Articles');
$table = $this->getTableLocator()->get('Articles');

$options = ['foo' => 'bar'];

Expand Down Expand Up @@ -65,7 +64,7 @@ public function testMagicShorthandMethods()
{
Configure::write('App.namespace', 'Search\Test\TestApp');

$table = TableRegistry::get('Articles');
$table = $this->getTableLocator()->get('Articles');

$manager = new Manager($table);
$manager->testFilter('test1');
Expand All @@ -86,7 +85,7 @@ public function testMagicShorthandMethods()
*/
public function testAll()
{
$table = TableRegistry::get('Articles');
$table = $this->getTableLocator()->get('Articles');
$manager = new Manager($table);

$this->assertEmpty(iterator_to_array($manager->getFilters()));
Expand All @@ -107,7 +106,7 @@ public function testAll()
*/
public function testAdd()
{
$table = TableRegistry::get('Articles');
$table = $this->getTableLocator()->get('Articles');
$manager = new Manager($table);
$manager->add('testOne', 'Search.Value');
$manager->add('testTwo', 'Search.Compare');
Expand All @@ -123,7 +122,7 @@ public function testAdd()
*/
public function testGetFilters()
{
$table = TableRegistry::get('Articles');
$table = $this->getTableLocator()->get('Articles');
$manager = new Manager($table);
$manager->add('test', 'Search.Value');
$manager->add('test2', 'Search.Compare');
Expand All @@ -147,7 +146,7 @@ public function testGetFiltersNonExistentCollection()
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The collection class "NonExistentCollection" does not exist');

$table = TableRegistry::get('Articles');
$table = $this->getTableLocator()->get('Articles');
$manager = new Manager($table);
$manager->getFilters('non_existent');
}
Expand All @@ -157,7 +156,7 @@ public function testGetFiltersNonExistentCollection()
*/
public function testRemove()
{
$table = TableRegistry::get('Articles');
$table = $this->getTableLocator()->get('Articles');
$manager = new Manager($table);

$manager->add('test', 'Search.Value');
Expand All @@ -179,7 +178,7 @@ public function testRemove()
*/
public function testRepository()
{
$table = TableRegistry::get('Articles');
$table = $this->getTableLocator()->get('Articles');
$manager = new Manager($table);
$result = $manager->getRepository();
$this->assertInstanceOf('\Cake\Datasource\RepositoryInterface', $result);
Expand All @@ -190,7 +189,7 @@ public function testRepository()
*/
public function testTable()
{
$table = TableRegistry::get('Articles');
$table = $this->getTableLocator()->get('Articles');
$manager = new Manager($table);
$result = $manager->getRepository();
$this->assertInstanceOf('\Cake\Datasource\RepositoryInterface', $result);
Expand All @@ -201,7 +200,7 @@ public function testTable()
*/
public function testCollection()
{
$table = TableRegistry::get('Articles');
$table = $this->getTableLocator()->get('Articles');
$manager = new Manager($table);

$result = $manager->getCollectionName();
Expand Down Expand Up @@ -232,7 +231,7 @@ public function testCollection()
*/
public function testCollectionCombined()
{
$table = TableRegistry::get('Articles');
$table = $this->getTableLocator()->get('Articles');
$manager = new Manager($table);

$result = $manager->getCollectionName();
Expand All @@ -247,7 +246,7 @@ public function testCollectionCombined()
*/
public function testInvalidCollectionClass()
{
$table = TableRegistry::get('Articles');
$table = $this->getTableLocator()->get('Articles');
$manager = new Manager($table, Configure::class);

$this->expectException(InvalidArgumentException::class);
Expand Down
9 changes: 4 additions & 5 deletions tests/TestCase/Model/Behavior/SearchBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace Search\Test\TestCase\Model\Behavior;

use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use Search\Manager;
use Search\Model\Filter\FilterCollection;
Expand Down Expand Up @@ -45,16 +44,16 @@ public function setUp(): void
{
parent::setUp();

TableRegistry::clear();
$this->Articles = TableRegistry::get('Articles', [
$this->getTableLocator()->clear();
$this->Articles = $this->getTableLocator()->get('Articles', [
'className' => 'Search\Test\TestApp\Model\Table\ArticlesTable',
]);
$this->Articles->addBehavior('Search.Search');
$this->Comments = TableRegistry::get('Comments', [
$this->Comments = $this->getTableLocator()->get('Comments', [
'className' => 'Search\Test\TestApp\Model\Table\CommentsTable',
]);
$this->Comments->addBehavior('Search.Search');
$this->Sections = TableRegistry::get('Sections', [
$this->Sections = $this->getTableLocator()->get('Sections', [
'className' => 'Search\Test\TestApp\Model\Table\SectionsTable',
]);
$this->Sections->addBehavior('Search.Search');
Expand Down
3 changes: 1 addition & 2 deletions tests/TestCase/Model/Filter/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace Search\Test\TestCase\Model\Filter;

use Cake\Datasource\RepositoryInterface;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use Search\Manager;
use Search\Test\TestApp\Model\Filter\TestFilter;
Expand Down Expand Up @@ -32,7 +31,7 @@ class BaseTest extends TestCase
*/
public function setUp(): void
{
$table = TableRegistry::get('Articles');
$table = $this->getTableLocator()->get('Articles');
$this->Manager = new Manager($table);
}

Expand Down
33 changes: 16 additions & 17 deletions tests/TestCase/Model/Filter/BooleanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace Search\Test\TestCase\Model\Filter;

use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use Cake\Utility\Hash;
use Search\Manager;
Expand All @@ -25,7 +24,7 @@ class BooleanTest extends TestCase
*/
public function testProcessWithFlagOn()
{
$articles = TableRegistry::get('Articles');
$articles = $this->getTableLocator()->get('Articles');
$manager = new Manager($articles);
$filter = new Boolean('is_active', $manager);
$filter->setArgs(['is_active' => 'on']);
Expand All @@ -47,7 +46,7 @@ public function testProcessWithFlagOn()
*/
public function testProcessWithFlagOff()
{
$articles = TableRegistry::get('Articles');
$articles = $this->getTableLocator()->get('Articles');
$manager = new Manager($articles);
$filter = new Boolean('is_active', $manager);
$filter->setArgs(['is_active' => 'off']);
Expand All @@ -69,7 +68,7 @@ public function testProcessWithFlagOff()
*/
public function testProcessWithStringFlagTrue()
{
$articles = TableRegistry::get('Articles');
$articles = $this->getTableLocator()->get('Articles');
$manager = new Manager($articles);
$filter = new Boolean('is_active', $manager);
$filter->setArgs(['is_active' => 'true']);
Expand All @@ -91,7 +90,7 @@ public function testProcessWithStringFlagTrue()
*/
public function testProcessWithStringFlagFalse()
{
$articles = TableRegistry::get('Articles');
$articles = $this->getTableLocator()->get('Articles');
$manager = new Manager($articles);
$filter = new Boolean('is_active', $manager);
$filter->setArgs(['is_active' => 'false']);
Expand All @@ -113,7 +112,7 @@ public function testProcessWithStringFlagFalse()
*/
public function testProcessWithBooleanFlagTrue()
{
$articles = TableRegistry::get('Articles');
$articles = $this->getTableLocator()->get('Articles');
$manager = new Manager($articles);
$filter = new Boolean('is_active', $manager);
$filter->setArgs(['is_active' => true]);
Expand All @@ -135,7 +134,7 @@ public function testProcessWithBooleanFlagTrue()
*/
public function testProcessWithBooleanFlagFalse()
{
$articles = TableRegistry::get('Articles');
$articles = $this->getTableLocator()->get('Articles');
$manager = new Manager($articles);
$filter = new Boolean('is_active', $manager);
$filter->setArgs(['is_active' => false]);
Expand All @@ -157,7 +156,7 @@ public function testProcessWithBooleanFlagFalse()
*/
public function testProcessWithStringFlag1()
{
$articles = TableRegistry::get('Articles');
$articles = $this->getTableLocator()->get('Articles');
$manager = new Manager($articles);
$filter = new Boolean('is_active', $manager);
$filter->setArgs(['is_active' => '1']);
Expand All @@ -179,7 +178,7 @@ public function testProcessWithStringFlag1()
*/
public function testProcessWithStringFlag0()
{
$articles = TableRegistry::get('Articles');
$articles = $this->getTableLocator()->get('Articles');
$manager = new Manager($articles);
$filter = new Boolean('is_active', $manager);
$filter->setArgs(['is_active' => '0']);
Expand All @@ -201,7 +200,7 @@ public function testProcessWithStringFlag0()
*/
public function testProcessWithIntegerFlag1()
{
$articles = TableRegistry::get('Articles');
$articles = $this->getTableLocator()->get('Articles');
$manager = new Manager($articles);
$filter = new Boolean('is_active', $manager);
$filter->setArgs(['is_active' => 1]);
Expand All @@ -220,7 +219,7 @@ public function testProcessWithIntegerFlag1()

public function testProcessWithIntegerFlag0()
{
$articles = TableRegistry::get('Articles');
$articles = $this->getTableLocator()->get('Articles');
$manager = new Manager($articles);
$filter = new Boolean('is_active', $manager);
$filter->setArgs(['is_active' => 0]);
Expand All @@ -242,7 +241,7 @@ public function testProcessWithIntegerFlag0()
*/
public function testProcessWithFlagInvalid()
{
$articles = TableRegistry::get('Articles');
$articles = $this->getTableLocator()->get('Articles');
$manager = new Manager($articles);
$filter = new Boolean('is_active', $manager);
$filter->setArgs(['is_active' => 'neitherTruthyNorFalsy']);
Expand All @@ -259,7 +258,7 @@ public function testProcessWithFlagInvalid()
*/
public function testProcessMultiValueSafe()
{
$articles = TableRegistry::get('Articles');
$articles = $this->getTableLocator()->get('Articles');
$manager = new Manager($articles);
$filter = new Boolean('is_active', $manager, ['multiValue' => true]);
$filter->setArgs(['is_active' => [0, 1]]);
Expand All @@ -276,7 +275,7 @@ public function testProcessMultiValueSafe()
*/
public function testProcessMultiField()
{
$articles = TableRegistry::get('Articles');
$articles = $this->getTableLocator()->get('Articles');
$manager = new Manager($articles);
$filter = new Boolean('boolean', $manager, [
'fields' => ['is_active', 'other'],
Expand All @@ -300,7 +299,7 @@ public function testProcessMultiField()
*/
public function testProcessMultiFieldWithAndMode()
{
$articles = TableRegistry::get('Articles');
$articles = $this->getTableLocator()->get('Articles');
$manager = new Manager($articles);
$filter = new Boolean('boolean', $manager, [
'fields' => ['is_active', 'other'],
Expand All @@ -325,7 +324,7 @@ public function testProcessMultiFieldWithAndMode()
*/
public function testProcessDefaultFallbackForDisallowedMultiValue()
{
$articles = TableRegistry::get('Articles');
$articles = $this->getTableLocator()->get('Articles');
$manager = new Manager($articles);
$filter = new Boolean('is_active', $manager, ['defaultValue' => true]);
$filter->setArgs(['is_active' => ['foo', 'bar']]);
Expand All @@ -347,7 +346,7 @@ public function testProcessDefaultFallbackForDisallowedMultiValue()
*/
public function testProcessNoDefaultFallbackForDisallowedMultiValue()
{
$articles = TableRegistry::get('Articles');
$articles = $this->getTableLocator()->get('Articles');
$manager = new Manager($articles);
$filter = new Boolean('is_active', $manager);
$filter->setArgs(['is_active' => ['foo', 'bar']]);
Expand Down
5 changes: 2 additions & 3 deletions tests/TestCase/Model/Filter/CallbackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace Search\Test\TestCase\Model\Filter;

use Cake\ORM\Query;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use Cake\Utility\Hash;
use Search\Manager;
Expand All @@ -26,7 +25,7 @@ class CallbackTest extends TestCase
*/
public function testProcess()
{
$articles = TableRegistry::get('Articles');
$articles = $this->getTableLocator()->get('Articles');
$manager = new Manager($articles);

$filter = new Callback('title', $manager, [
Expand All @@ -53,7 +52,7 @@ public function testProcess()
*/
public function testProcessFalse()
{
$articles = TableRegistry::get('Articles');
$articles = $this->getTableLocator()->get('Articles');
$manager = new Manager($articles);

$filter = new Callback('title', $manager, [
Expand Down
Loading

0 comments on commit 8d45c21

Please sign in to comment.