Skip to content

Commit

Permalink
Merge pull request #763 from cakephp/remove-tableregistry-usage
Browse files Browse the repository at this point in the history
Remove usage of TableRegistry
  • Loading branch information
othercorey authored Jun 7, 2020
2 parents a0b70d1 + efc6759 commit 1858160
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 32 deletions.
6 changes: 4 additions & 2 deletions src/Panel/HistoryPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,24 @@
*/
namespace DebugKit\Panel;

use Cake\ORM\TableRegistry;
use Cake\ORM\Locator\LocatorAwareTrait;
use DebugKit\DebugPanel;

/**
* Provides debug information on previous requests.
*/
class HistoryPanel extends DebugPanel
{
use LocatorAwareTrait;

/**
* Get the data for the panel.
*
* @return array
*/
public function data()
{
$table = TableRegistry::getTableLocator()->get('DebugKit.Requests');
$table = $this->getTableLocator()->get('DebugKit.Requests');
$recent = $table->find('recent');

return [
Expand Down
6 changes: 4 additions & 2 deletions src/Panel/SqlLogPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
use Cake\Core\Configure;
use Cake\Datasource\ConnectionInterface;
use Cake\Datasource\ConnectionManager;
use Cake\ORM\Locator\LocatorAwareTrait;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use DebugKit\Database\Log\DebugLog;
use DebugKit\DebugPanel;

Expand All @@ -27,6 +27,8 @@
*/
class SqlLogPanel extends DebugPanel
{
use LocatorAwareTrait;

/**
* Loggers connected
*
Expand Down Expand Up @@ -84,7 +86,7 @@ public function data()
return [
'tables' => array_map(function (Table $table) {
return $table->getAlias();
}, TableRegistry::getTableLocator()->genericInstances()),
}, $this->getTableLocator()->genericInstances()),
'loggers' => $this->_loggers,
];
}
Expand Down
5 changes: 3 additions & 2 deletions src/ToolbarService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Cake\Event\EventManager;
use Cake\Http\ServerRequest;
use Cake\Log\Log;
use Cake\ORM\TableRegistry;
use Cake\ORM\Locator\LocatorAwareTrait;
use Cake\Routing\Router;
use DebugKit\Panel\PanelRegistry;
use PDOException;
Expand All @@ -34,6 +34,7 @@
class ToolbarService
{
use InstanceConfigTrait;
use LocatorAwareTrait;

/**
* The panel registry.
Expand Down Expand Up @@ -230,7 +231,7 @@ public function saveData(ServerRequest $request, ResponseInterface $response)
'panels' => [],
];
/** @var \DebugKit\Model\Table\RequestsTable $requests */
$requests = TableRegistry::getTableLocator()->get('DebugKit.Requests');
$requests = $this->getTableLocator()->get('DebugKit.Requests');
$requests->gc();

$row = $requests->newEntity($data);
Expand Down
7 changes: 3 additions & 4 deletions tests/TestCase/Controller/DashboardControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
namespace DebugKit\Test\TestCase\Controller;

use Cake\ORM\TableRegistry;
use Cake\TestSuite\IntegrationTestCase;
use DebugKit\TestApp\Application;

Expand Down Expand Up @@ -43,7 +42,7 @@ public function setUp(): void

public function testIndexNoRequests()
{
$requests = TableRegistry::get('DebugKit.Requests');
$requests = $this->getTableLocator()->get('DebugKit.Requests');
$requests->Panels->deleteAll('1=1');
$requests->deleteAll('1=1');

Expand All @@ -56,7 +55,7 @@ public function testIndexNoRequests()

public function testIndexWithRequests()
{
$requests = TableRegistry::get('DebugKit.Requests');
$requests = $this->getTableLocator()->get('DebugKit.Requests');
$request = $requests->newEntity(['url' => '/example']);
$requests->save($request);

Expand All @@ -69,7 +68,7 @@ public function testIndexWithRequests()

public function testReset()
{
$requests = TableRegistry::get('DebugKit.Requests');
$requests = $this->getTableLocator()->get('DebugKit.Requests');
$this->assertGreaterThan(0, $requests->find()->count(), 'precondition failed');

$this->post('/debug-kit/dashboard/reset');
Expand Down
5 changes: 2 additions & 3 deletions tests/TestCase/Controller/MailPreviewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
namespace DebugKit\Test\TestCase\Controller;

use Cake\ORM\TableRegistry;
use Cake\Routing\Router;
use Cake\TestSuite\IntegrationTestCase;
use DebugKit\TestApp\Application;
Expand Down Expand Up @@ -106,7 +105,7 @@ public function testSentInvalidData()
*/
public function testSentValidData()
{
$panels = TableRegistry::get('Panels');
$panels = $this->getTableLocator()->get('Panels');
$panel = $panels->newEntity(['request_id' => 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa']);
$data = [
'emails' => [
Expand All @@ -132,7 +131,7 @@ public function testSentValidData()
*/
public function testSentValidDataRenderPart()
{
$panels = TableRegistry::get('Panels');
$panels = $this->getTableLocator()->get('Panels');
$panel = $panels->newEntity(['request_id' => 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa']);
$data = [
'emails' => [
Expand Down
3 changes: 1 addition & 2 deletions tests/TestCase/DebugSqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

use Cake\Database\Driver\Postgres;
use Cake\Datasource\ConnectionManager;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use DebugKit\DebugSql;

Expand Down Expand Up @@ -98,6 +97,6 @@ public function testSqlHtml()
*/
private function newQuery()
{
return TableRegistry::get('panels')->query();
return $this->getTableLocator()->get('panels')->query();
}
}
7 changes: 3 additions & 4 deletions tests/TestCase/Middleware/DebugKitMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use Cake\Http\CallbackStream;
use Cake\Http\Response;
use Cake\Http\ServerRequest;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use DebugKit\Middleware\DebugKitMiddleware;
use Psr\Http\Server\RequestHandlerInterface;
Expand Down Expand Up @@ -102,7 +101,7 @@ public function testInvokeSaveData()
$response = $middleware->process($request, $handler);
$this->assertInstanceOf(Response::class, $response, 'Should return the response');

$requests = TableRegistry::get('DebugKit.Requests');
$requests = $this->getTableLocator()->get('DebugKit.Requests');
$result = $requests->find()
->order(['Requests.requested_at' => 'DESC'])
->contain('Panels')
Expand Down Expand Up @@ -160,7 +159,7 @@ public function testInvokeNoModifyBinaryResponse()
$result = $middleware->process($request, $handler);
$this->assertInstanceOf(Response::class, $result, 'Should return a response');

$requests = TableRegistry::get('DebugKit.Requests');
$requests = $this->getTableLocator()->get('DebugKit.Requests');
$total = $requests->find()->where(['url' => '/articles'])->count();

$this->assertSame(1, $total, 'Should track response');
Expand Down Expand Up @@ -194,7 +193,7 @@ public function testInvokeNoModifyNonHtmlResponse()
$result = $middleware->process($request, $handler);
$this->assertInstanceOf(Response::class, $result, 'Should return a response');

$requests = TableRegistry::get('DebugKit.Requests');
$requests = $this->getTableLocator()->get('DebugKit.Requests');
$total = $requests->find()->where(['url' => '/articles'])->count();

$this->assertEquals(1, $total, 'Should track response');
Expand Down
3 changes: 1 addition & 2 deletions tests/TestCase/Model/Behavior/TimedBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
namespace DebugKit\Test\TestCase\Model\Behavior;

use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use DebugKit\DebugTimer;

Expand Down Expand Up @@ -44,7 +43,7 @@ class TimedBehaviorTest extends TestCase
public function setUp(): void
{
parent::setUp();
$this->Article = TableRegistry::get('Articles');
$this->Article = $this->getTableLocator()->get('Articles');
$this->Article->addBehavior('DebugKit.Timed');
}

Expand Down
7 changes: 3 additions & 4 deletions tests/TestCase/Model/Table/RequestTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Cake\Core\Configure;
use Cake\Database\Driver\Sqlite;
use Cake\Datasource\ConnectionManager;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;

/**
Expand Down Expand Up @@ -54,8 +53,8 @@ public function testInitializeCreatesSchema()
$stmt = $connection->execute('DROP TABLE IF EXISTS requests');
$stmt->closeCursor();

TableRegistry::get('DebugKit.Requests');
TableRegistry::get('DebugKit.Panels');
$this->getTableLocator()->get('DebugKit.Requests');
$this->getTableLocator()->get('DebugKit.Panels');

$schema = $connection->getSchemaCollection();
$this->assertContains('requests', $schema->listTables());
Expand All @@ -69,7 +68,7 @@ public function testInitializeCreatesSchema()
*/
public function testFindRecent()
{
$table = TableRegistry::get('DebugKit.Requests');
$table = $this->getTableLocator()->get('DebugKit.Requests');
$query = $table->find('recent');
$this->assertSame(10, $query->clause('limit'));
$this->assertNotEmpty($query->clause('order'));
Expand Down
5 changes: 2 additions & 3 deletions tests/TestCase/Panel/SqlLogPanelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

use Cake\Core\Configure;
use Cake\Datasource\ConnectionManager;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use DebugKit\Panel\SqlLogPanel;
use ReflectionProperty;
Expand Down Expand Up @@ -106,7 +105,7 @@ public function testData()
$this->panel->initialize();

/** @var Table $articles */
$articles = TableRegistry::get('Articles');
$articles = $this->getTableLocator()->get('Articles');
$articles->findById(1)->first();

$result = $this->panel->data();
Expand All @@ -123,7 +122,7 @@ public function testSummary()
$this->panel->initialize();

/** @var Table $articles */
$articles = TableRegistry::get('Articles');
$articles = $this->getTableLocator()->get('Articles');
$articles->findById(1)->first();

$result = $this->panel->summary();
Expand Down
3 changes: 1 addition & 2 deletions tests/TestCase/Panel/VariablesPanelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
namespace DebugKit\Test\TestCase\Panel;

use Cake\Event\Event;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use Cake\View\ViewVarsTrait;
use DebugKit\Panel\VariablesPanel;
Expand Down Expand Up @@ -62,7 +61,7 @@ public function tearDown(): void
*/
public function testShutdown()
{
$requests = TableRegistry::get('Requests');
$requests = $this->getTableLocator()->get('Requests');
$query = $requests->find('all');
$result = $requests->find()->all();
$unbufferedQuery = $requests->find('all')->enableBufferedResults(false);
Expand Down
3 changes: 1 addition & 2 deletions tests/TestCase/ToolbarServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Cake\Http\Response;
use Cake\Http\ServerRequest as Request;
use Cake\Log\Log;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use DebugKit\Model\Entity\Request as RequestEntity;
use DebugKit\ToolbarService;
Expand Down Expand Up @@ -187,7 +186,7 @@ public function testSaveData()
$row = $bar->saveData($request, $response);
$this->assertNotEmpty($row);

$requests = TableRegistry::get('DebugKit.Requests');
$requests = $this->getTableLocator()->get('DebugKit.Requests');
$result = $requests->find()
->order(['Requests.requested_at' => 'DESC'])
->contain('Panels')
Expand Down

0 comments on commit 1858160

Please sign in to comment.