diff --git a/.stickler.yml b/.stickler.yml index 5ae707825..de3028b0e 100644 --- a/.stickler.yml +++ b/.stickler.yml @@ -1,7 +1,7 @@ --- linters: phpcs: - standard: CakePHP + standard: CakePHP3 extensions: 'php,ctp' fixer: true diff --git a/docs/listeners/api-query-log.rst b/docs/listeners/api-query-log.rst index b58614f73..8426477b1 100644 --- a/docs/listeners/api-query-log.rst +++ b/docs/listeners/api-query-log.rst @@ -29,7 +29,7 @@ you want to attach it only to specific controllers and actions } -Attach it using components array, this is recommended if you want to +Attach it in :code:`AppController::initialize()`, this is recommended if you want to attach it to all controllers, application wide @@ -88,3 +88,23 @@ Paginated results will include a } } } + + +Configuration +------------- + +By default this listener will log all defined connections. + +If you need to select specific connections to log, you can use the :code:`connections` configuration: + +.. code-block:: php + + $this->loadComponent('Crud.Crud', [ + 'listeners' => [ + 'Crud.Api', + 'ApiQueryLog' => [ + 'className' => 'Crud.ApiQueryLog', + 'connections' => ['default', 'elastic'] + ] + ] + ]); diff --git a/src/Action/BaseAction.php b/src/Action/BaseAction.php index 328b1455c..fd25ae7c6 100644 --- a/src/Action/BaseAction.php +++ b/src/Action/BaseAction.php @@ -8,6 +8,7 @@ use Cake\Utility\Text; use Crud\Core\BaseObject; use Crud\Event\Subject; +use Exception; /** * Base Crud class @@ -129,7 +130,7 @@ public function disable() public function message($type, array $replacements = []) { if (empty($type)) { - throw new \Exception('Missing message type'); + throw new Exception('Missing message type'); } $crud = $this->_crud(); @@ -138,7 +139,7 @@ public function message($type, array $replacements = []) if (empty($config)) { $config = $crud->getConfig('messages.' . $type); if (empty($config)) { - throw new \Exception(sprintf('Invalid message type "%s"', $type)); + throw new Exception(sprintf('Invalid message type "%s"', $type)); } } @@ -155,7 +156,7 @@ public function message($type, array $replacements = []) ], $config); if (!isset($config['text'])) { - throw new \Exception(sprintf('Invalid message config for "%s" no text key found', $type)); + throw new Exception(sprintf('Invalid message config for "%s" no text key found', $type)); } $config['params']['original'] = ucfirst(str_replace('{name}', $config['name'], $config['text'])); diff --git a/src/Controller/ControllerTrait.php b/src/Controller/ControllerTrait.php index 891d01764..d39da768d 100644 --- a/src/Controller/ControllerTrait.php +++ b/src/Controller/ControllerTrait.php @@ -2,6 +2,7 @@ namespace Crud\Controller; use Cake\Controller\Exception\MissingActionException; +use LogicException; /** * Enable Crud to catch MissingActionException and attempt to generate response @@ -47,7 +48,7 @@ public function invokeAction() { $request = $this->request; if (!isset($request)) { - throw new \LogicException('No Request object configured. Cannot invoke action'); + throw new LogicException('No Request object configured. Cannot invoke action'); } if (!$this->isAction($request->getParam('action'))) { throw new MissingActionException([ diff --git a/src/Error/Exception/CrudException.php b/src/Error/Exception/CrudException.php index d8c0d8f97..276e2db47 100644 --- a/src/Error/Exception/CrudException.php +++ b/src/Error/Exception/CrudException.php @@ -1,6 +1,8 @@ action, $actions); default: - throw new \Exception('Invalid mode'); + throw new Exception('Invalid mode'); } } } diff --git a/src/Listener/ApiQueryLogListener.php b/src/Listener/ApiQueryLogListener.php index 421a6d7e5..7379e90ca 100644 --- a/src/Listener/ApiQueryLogListener.php +++ b/src/Listener/ApiQueryLogListener.php @@ -21,6 +21,15 @@ class ApiQueryLogListener extends BaseListener { + /** + * {@inheritDoc} + * + * `connections` List of connection names to log. Empty means all defined connections. + */ + protected $_defaultConfig = [ + 'connections' => [], + ]; + /** * Returns a list of all events that will fire in the controller during its lifecycle. * You can override this function to add you own listener callbacks @@ -49,7 +58,9 @@ public function implementedEvents() */ public function setupLogging(Event $event) { - foreach ($this->_getSources() as $connectionName) { + $connections = $this->getConfig('connections') ?: $this->_getSources(); + + foreach ($connections as $connectionName) { try { $connection = $this->_getSource($connectionName); diff --git a/src/Template/Bake/Controller/controller.ctp b/src/Template/Bake/Controller/controller.ctp index 4854947ab..2ececd8c5 100644 --- a/src/Template/Bake/Controller/controller.ctp +++ b/src/Template/Bake/Controller/controller.ctp @@ -4,9 +4,9 @@ use Cake\Utility\Inflector; $defaultModel = $name; %> \Controller<%= $prefix %>; +namespace <%= $namespace %>Controller<%= $prefix %>; -use <%= $namespace %>\Controller\AppController; +use use const Controller\AppController;<%= $namespace %>AppController; /** * <%= $name %> Controller diff --git a/tests/App/Model/Entity/Blog.php b/tests/App/Model/Entity/Blog.php index f9cb71d12..ba6aba43a 100644 --- a/tests/App/Model/Entity/Blog.php +++ b/tests/App/Model/Entity/Blog.php @@ -1,7 +1,9 @@ toArray() as $k => $v) { - echo "
" . \Cake\Utility\Inflector::humanize($k) . "
"; + echo "
" . Inflector::humanize($k) . "
"; echo "
"; echo $v; echo "
"; diff --git a/tests/TestCase/Action/AddActionTest.php b/tests/TestCase/Action/AddActionTest.php index 7cc101488..02209dbd1 100644 --- a/tests/TestCase/Action/AddActionTest.php +++ b/tests/TestCase/Action/AddActionTest.php @@ -1,6 +1,7 @@ 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -147,7 +148,7 @@ public function testActionPostWithAddRedirect() 'Controller.initialize', ['priority' => 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -192,7 +193,7 @@ public function testActionPostWithEditRedirect() 'Controller.initialize', ['priority' => 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -236,7 +237,7 @@ public function testActionPostErrorSave() 'Controller.initialize', ['priority' => 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -289,7 +290,7 @@ public function testActionPostValidationErrors() 'Controller.initialize', ['priority' => 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -397,7 +398,7 @@ public function testApiCreate($method) 'Controller.initialize', ['priority' => 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -444,7 +445,7 @@ function ($event) { return; } - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -496,7 +497,7 @@ function ($event) { return; } - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -542,7 +543,7 @@ public function testStopAddWithDefaultSubjectSuccess() 'Controller.initialize', ['priority' => 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -596,7 +597,7 @@ public function testStopAddWithManuallySetSubjectSuccess() 'Controller.initialize', ['priority' => 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/TestCase/Action/BaseActionTest.php b/tests/TestCase/Action/BaseActionTest.php index dea3bebc8..588d52d80 100644 --- a/tests/TestCase/Action/BaseActionTest.php +++ b/tests/TestCase/Action/BaseActionTest.php @@ -1,12 +1,19 @@ Request = $this->getMockBuilder(ServerRequest::class) ->getMock(); - $this->Controller = $this->getMockBuilder('Cake\Controller\Controller') + $this->Controller = $this->getMockBuilder(Controller::class) ->setMethods(['set']) ->setConstructorArgs([ $this->Request, - new \Cake\Network\Response(), + new Response(), 'CrudExamples', - \Cake\Event\EventManager::instance(), + EventManager::instance(), ]) ->getMock(); $this->Registry = $this->Controller->components(); - $this->Crud = $this->getMockBuilder('Crud\Controller\Component\CrudComponent') + $this->Crud = $this->getMockBuilder(CrudComponent::class) ->setConstructorArgs([$this->Registry]) ->setMethods(['foobar']) ->getMock(); $this->Controller->Crud = $this->Crud; $this->Controller->modelClass = 'CrudExamples'; - $this->Controller->CrudExamples = \Cake\ORM\TableRegistry::get('Crud.CrudExamples'); + $this->Controller->CrudExamples = TableRegistry::get('Crud.CrudExamples'); $this->Controller->CrudExamples->setAlias('MyModel'); $this->actionClassName = $this->getMockClass('Crud\Action\BaseAction', ['_handle']); @@ -145,7 +152,7 @@ public function testEnabledActionWorks() ->method('getMethod') ->will($this->returnValue('GET')); - $Action = $this->getMockBuilder('Crud\Action\BaseAction') + $Action = $this->getMockBuilder(BaseAction::class) ->setMethods(['_request', '_get']) ->setConstructorArgs([$this->Controller]) ->getMock(); @@ -183,7 +190,7 @@ public function testDisable() { $i = 0; - $Action = $this->getMockBuilder('Crud\Action\BaseAction') + $Action = $this->getMockBuilder(BaseAction::class) ->setMethods(['setConfig']) ->setConstructorArgs([$this->Controller]) ->getMock(); @@ -207,7 +214,7 @@ public function testEnable() { $i = 0; - $Action = $this->getMockBuilder('Crud\Action\BaseAction') + $Action = $this->getMockBuilder(BaseAction::class) ->setMethods(['setConfig']) ->setConstructorArgs([$this->Controller]) ->getMock(); @@ -240,7 +247,7 @@ public function testSetFlash() $Subject = new Subject(); - $this->Controller->Crud = $this->getMockBuilder('Crud\Controller\Component\CrudComponent') + $this->Controller->Crud = $this->getMockBuilder(CrudComponent::class) ->setMethods(['trigger']) ->setConstructorArgs([$this->Registry]) ->getMock(); @@ -248,9 +255,9 @@ public function testSetFlash() ->expects($this->once()) ->method('trigger') ->with('setFlash', $Subject) - ->will($this->returnValue(new \Cake\Event\Event('Crud.setFlash'))); + ->will($this->returnValue(new Event('Crud.setFlash'))); - $this->Controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->Controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->setConstructorArgs([$this->Registry]) ->getMock(); @@ -522,7 +529,7 @@ public function testBadRequestMethodMessage() */ public function testHandle() { - $Action = $this->getMockBuilder('Crud\Action\BaseAction') + $Action = $this->getMockBuilder(BaseAction::class) ->setMethods(['_request', '_get', 'getConfig']) ->setConstructorArgs([$this->Controller]) ->getMock(); @@ -562,7 +569,7 @@ public function testHandle() */ public function testHandleDisabled() { - $Action = $this->getMockBuilder('Crud\Action\BaseAction') + $Action = $this->getMockBuilder(BaseAction::class) ->setMethods(['_handle', '_get', 'getConfig']) ->setConstructorArgs([$this->Controller]) ->getMock(); @@ -590,7 +597,7 @@ public function testHandleDisabled() */ public function testGenericHandle() { - $Action = $this->getMockBuilder('Crud\Action\BaseAction') + $Action = $this->getMockBuilder(BaseAction::class) ->setMethods(['_handle', '_request', 'getConfig']) ->setConstructorArgs([$this->Controller]) ->getMock(); @@ -631,7 +638,7 @@ public function testGenericHandle() */ public function testHandleException() { - $Action = $this->getMockBuilder('Crud\Action\BaseAction') + $Action = $this->getMockBuilder(BaseAction::class) ->setMethods(['_request', 'getConfig']) ->setConstructorArgs([$this->Controller]) ->getMock(); diff --git a/tests/TestCase/Action/Bulk/DeleteActionTest.php b/tests/TestCase/Action/Bulk/DeleteActionTest.php index 58a9ecfe5..3b68cea50 100644 --- a/tests/TestCase/Action/Bulk/DeleteActionTest.php +++ b/tests/TestCase/Action/Bulk/DeleteActionTest.php @@ -1,6 +1,7 @@ 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -110,7 +111,7 @@ public function testStopBeforeBulk() 'Controller.initialize', ['priority' => 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -158,7 +159,7 @@ public function testUuidRequestData() 'Controller.initialize', ['priority' => 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/TestCase/Action/Bulk/SetValueActionTest.php b/tests/TestCase/Action/Bulk/SetValueActionTest.php index e85d95656..7408fccb0 100644 --- a/tests/TestCase/Action/Bulk/SetValueActionTest.php +++ b/tests/TestCase/Action/Bulk/SetValueActionTest.php @@ -1,6 +1,7 @@ 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -110,7 +111,7 @@ public function testStopBeforeBulk() 'Controller.initialize', ['priority' => 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -158,7 +159,7 @@ public function testUuidRequestData() 'Controller.initialize', ['priority' => 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/TestCase/Action/Bulk/ToggleActionTest.php b/tests/TestCase/Action/Bulk/ToggleActionTest.php index 9afa13c26..2fb5b4277 100644 --- a/tests/TestCase/Action/Bulk/ToggleActionTest.php +++ b/tests/TestCase/Action/Bulk/ToggleActionTest.php @@ -1,6 +1,7 @@ 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -110,7 +111,7 @@ public function testStopBeforeBulk() 'Controller.initialize', ['priority' => 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -158,7 +159,7 @@ public function testUuidRequestData() 'Controller.initialize', ['priority' => 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/TestCase/Action/DeleteActionTest.php b/tests/TestCase/Action/DeleteActionTest.php index 2a10e6c0d..91b7fa17b 100644 --- a/tests/TestCase/Action/DeleteActionTest.php +++ b/tests/TestCase/Action/DeleteActionTest.php @@ -1,6 +1,7 @@ 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -118,7 +119,7 @@ public function testStopDelete() 'Controller.initialize', ['priority' => 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -172,7 +173,7 @@ public function testStopBeforeRedirect() 'Controller.initialize', ['priority' => 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/TestCase/Action/EditActionTest.php b/tests/TestCase/Action/EditActionTest.php index 90ec594a7..60c7dc558 100644 --- a/tests/TestCase/Action/EditActionTest.php +++ b/tests/TestCase/Action/EditActionTest.php @@ -1,6 +1,7 @@ 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -165,7 +166,7 @@ public function testActionPostErrorSave() 'Controller.initialize', ['priority' => 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -218,7 +219,7 @@ public function testActionPostValidationErrors() 'Controller.initialize', ['priority' => 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -278,7 +279,7 @@ public function testActionPatch() 'Controller.initialize', ['priority' => 11], function ($event) { - $this->_controller->Flash = $this->getMockBuilder('Cake\Controller\Component\FlashComponent') + $this->_controller->Flash = $this->getMockBuilder(FlashComponent::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/TestCase/Controller/Component/CrudComponentTest.php b/tests/TestCase/Controller/Component/CrudComponentTest.php index c67a67d32..03ee65f39 100644 --- a/tests/TestCase/Controller/Component/CrudComponentTest.php +++ b/tests/TestCase/Controller/Component/CrudComponentTest.php @@ -1,6 +1,7 @@ request->expects($this->any())->method('is')->will($this->returnValue(true)); $response = new Response(); - $this->controller = $this->getMockBuilder('Crud\TestCase\Controller\Crud\CrudExamplesController') + $this->controller = $this->getMockBuilder(CrudExamplesController::class) ->setMethods(['header', 'redirect', 'render', '_stop']) ->setConstructorArgs([$this->request, $response, 'CrudExamples', EventManager::instance()]) ->getMock(); @@ -252,7 +255,7 @@ public function testConfigNormalization() 'Crud.Related', ], ]; - $Crud = $this->getMockBuilder('Crud\Controller\Component\CrudComponent') + $Crud = $this->getMockBuilder(CrudComponent::class) ->setMethods(['_loadListeners', 'trigger']) ->setConstructorArgs([$this->Registry, $config]) ->getMock(); @@ -306,7 +309,7 @@ public function testExecuteActionToExecute() { $config = ['actions' => ['Crud.Index']]; - $Crud = $this->getMockBuilder('Crud\Controller\Component\CrudComponent') + $Crud = $this->getMockBuilder(CrudComponent::class) ->setMethods(['execute']) ->setConstructorArgs([$this->Registry, $config]) ->getMock(); diff --git a/tests/TestCase/Error/ExceptionRendererTest.php b/tests/TestCase/Error/ExceptionRendererTest.php index 0045150a4..aca1eecf5 100644 --- a/tests/TestCase/Error/ExceptionRendererTest.php +++ b/tests/TestCase/Error/ExceptionRendererTest.php @@ -1,15 +1,17 @@ getMockBuilder('Cake\Controller\Controller') + $Controller = $this->getMockBuilder(Controller::class) ->setMethods(['render']) ->getMock(); $Controller->request = new ServerRequest(); $Controller->response = new Response(); - $Renderer = $this->getMockBuilder('Crud\Error\ExceptionRenderer') + $Renderer = $this->getMockBuilder(ExceptionRenderer::class) ->setMethods(['_getController']) ->disableOriginalConstructor() ->getMock(); @@ -88,7 +90,7 @@ public function testNormalExceptionRenderingQueryLog() { $Exception = new Exception('Hello World'); - $QueryLogger = $this->getMockBuilder('Crud\Log\QueryLogger') + $QueryLogger = $this->getMockBuilder(QueryLogger::class) ->setMethods(['getLogs']) ->getMock(); $currentLogger = ConnectionManager::get('test')->getLogger(); @@ -100,13 +102,13 @@ public function testNormalExceptionRenderingQueryLog() ->with() ->will($this->returnValue(['query'])); - $Controller = $this->getMockBuilder('Cake\Controller\Controller') + $Controller = $this->getMockBuilder(Controller::class) ->setMethods(['render']) ->getMock(); $Controller->request = new ServerRequest(); $Controller->response = new Response(); - $Renderer = $this->getMockBuilder('Crud\Error\ExceptionRenderer') + $Renderer = $this->getMockBuilder(ExceptionRenderer::class) ->setMethods(['_getController']) ->disableOriginalConstructor() ->getMock(); @@ -170,13 +172,13 @@ public function testNormalNestedExceptionRendering() { $Exception = new Exception('Hello World'); - $Controller = $this->getMockBuilder('Cake\Controller\Controller') + $Controller = $this->getMockBuilder(Controller::class) ->setMethods(['render']) ->getMock(); $Controller->request = new ServerRequest(); $Controller->response = new Response(); - $Renderer = $this->getMockBuilder('Crud\Error\ExceptionRenderer') + $Renderer = $this->getMockBuilder(ExceptionRenderer::class) ->setMethods(['_getController']) ->disableOriginalConstructor() ->getMock(); @@ -232,7 +234,7 @@ public function testMissingViewExceptionDuringRendering() { $Exception = new Exception('Hello World'); - $Controller = $this->getMockBuilder('Cake\Controller\Controller') + $Controller = $this->getMockBuilder(Controller::class) ->setMethods(['render']) ->getMock(); $Controller->request = new ServerRequest(); @@ -240,7 +242,7 @@ public function testMissingViewExceptionDuringRendering() ->setMethods(['send']) ->getMock(); - $Renderer = $this->getMockBuilder('Crud\Error\ExceptionRenderer') + $Renderer = $this->getMockBuilder(ExceptionRenderer::class) ->setMethods(['_getController']) ->disableOriginalConstructor() ->getMock(); @@ -299,14 +301,14 @@ public function testGenericExceptionDuringRendering() $Exception = new Exception('Hello World'); $NestedException = new Exception('Generic Exception Description'); - $Controller = $this->getMockBuilder('Cake\Controller\Controller') + $Controller = $this->getMockBuilder(Controller::class) ->setMethods(['render']) ->getMock(); $Controller->request = new ServerRequest(); $Controller->response = $this->getMockBuilder(Response::class) ->getMock(); - $Renderer = $this->getMockBuilder('Crud\Error\ExceptionRenderer') + $Renderer = $this->getMockBuilder(ExceptionRenderer::class) ->setMethods(['_getController']) ->disableOriginalConstructor() ->getMock(); @@ -366,13 +368,13 @@ public function testValidationErrorSingleKnownError() $Exception = new ValidationException($entity); - $Controller = $this->getMockBuilder('Cake\Controller\Controller') + $Controller = $this->getMockBuilder(Controller::class) ->setMethods(['render']) ->getMock(); $Controller->request = new ServerRequest(); $Controller->response = new Response(); - $Renderer = $this->getMockBuilder('Crud\Error\ExceptionRenderer') + $Renderer = $this->getMockBuilder(ExceptionRenderer::class) ->setMethods(['_getController']) ->disableOriginalConstructor() ->getMock(); @@ -408,13 +410,13 @@ public function testValidationErrorSingleKnownErrorWithDebug() $Exception = new ValidationException($entity); - $Controller = $this->getMockBuilder('Cake\Controller\Controller') + $Controller = $this->getMockBuilder(Controller::class) ->setMethods(['render']) ->getMock(); $Controller->request = new ServerRequest(); $Controller->response = new Response(); - $Renderer = $this->getMockBuilder('Crud\Error\ExceptionRenderer') + $Renderer = $this->getMockBuilder(ExceptionRenderer::class) ->setMethods(['_getController']) ->disableOriginalConstructor() ->getMock(); @@ -459,13 +461,13 @@ public function testValidationErrorMultipleMessages() $Exception = new ValidationException($entity); - $Controller = $this->getMockBuilder('Cake\Controller\Controller') + $Controller = $this->getMockBuilder(Controller::class) ->setMethods(['render']) ->getMock(); $Controller->request = new ServerRequest(); $Controller->response = new Response(); - $Renderer = $this->getMockBuilder('Crud\Error\ExceptionRenderer') + $Renderer = $this->getMockBuilder(ExceptionRenderer::class) ->setMethods(['_getController']) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/TestCase/Listener/ApiListenerTest.php b/tests/TestCase/Listener/ApiListenerTest.php index 98233a4e6..55c3cd0d0 100644 --- a/tests/TestCase/Listener/ApiListenerTest.php +++ b/tests/TestCase/Listener/ApiListenerTest.php @@ -1,10 +1,21 @@ getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->setMethods(['setupDetectors', '_checkRequestType']) ->disableOriginalConstructor() ->getMock(); @@ -53,7 +64,7 @@ public function testImplementedEvents() public function testImplementedEventsWithoutApi() { $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->setMethods(['setupDetectors', '_checkRequestType']) ->disableOriginalConstructor() ->getMock(); @@ -79,7 +90,7 @@ public function testImplementedEventsWithoutApi() public function testBeforeHandle() { $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->setMethods(['_checkRequestMethods']) ->disableOriginalConstructor() ->getMock(); @@ -87,7 +98,7 @@ public function testBeforeHandle() ->expects($this->nextCounter($listener)) ->method('_checkRequestMethods'); - $listener->beforeHandle(new \Cake\Event\Event('Crud.beforeHandle')); + $listener->beforeHandle(new Event('Crud.beforeHandle')); } /** @@ -98,7 +109,7 @@ public function testBeforeHandle() public function testResponse() { $action = $this - ->getMockBuilder('\Crud\Action\IndexAction') + ->getMockBuilder(IndexAction::class) ->disableOriginalConstructor() ->setMethods(['getConfig']) ->getMock(); @@ -109,14 +120,14 @@ public function testResponse() ->getMock(); $subject = $this - ->getMockBuilder('\Crud\Event\Subject') + ->getMockBuilder(Subject::class) ->getMock(); $subject->success = true; - $event = new \Cake\Event\Event('Crud.afterSave', $subject); + $event = new Event('Crud.afterSave', $subject); $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->disableOriginalConstructor() ->setMethods(['_action', 'render']) ->getMock(); @@ -152,7 +163,7 @@ public function testResponse() public function testResponseWithStatusCodeNotSpecified() { $action = $this - ->getMockBuilder('\Crud\Action\ViewAction') + ->getMockBuilder(ViewAction::class) ->disableOriginalConstructor() ->setMethods(['getConfig']) ->getMock(); @@ -163,14 +174,14 @@ public function testResponseWithStatusCodeNotSpecified() ->getMock(); $subject = $this - ->getMockBuilder('\Crud\Event\Subject') + ->getMockBuilder(Subject::class) ->getMock(); $subject->success = true; - $event = new \Cake\Event\Event('Crud.afterSave', $subject); + $event = new Event('Crud.afterSave', $subject); $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->disableOriginalConstructor() ->setMethods(['_action', 'render']) ->getMock(); @@ -204,21 +215,21 @@ public function testResponseWithStatusCodeNotSpecified() public function testResponseWithExceptionConfig() { $action = $this - ->getMockBuilder('\Crud\Action\IndexAction') + ->getMockBuilder(IndexAction::class) ->disableOriginalConstructor() ->setMethods(['getConfig']) ->getMock(); - $subject = $this->getMockBuilder('\Crud\Event\Subject') + $subject = $this->getMockBuilder(Subject::class) ->getMock(); $subject->success = true; - $event = new \Cake\Event\Event('Crud.afterSave', $subject); + $event = new Event('Crud.afterSave', $subject); $i = 0; $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->disableOriginalConstructor() ->setMethods(['_action', 'render', '_exceptionResponse']) ->getMock(); @@ -251,7 +262,7 @@ public function testResponseWithExceptionConfig() public function testDefaultConfiguration() { $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->disableOriginalConstructor() ->setMethods(null) ->getMock(); @@ -358,16 +369,16 @@ public function testExceptionResponse( $validationErrors = [] ) { $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->disableOriginalConstructor() ->setMethods(null) ->getMock(); - $event = new \Cake\Event\Event('Crud.Exception', new \Crud\Event\Subject()); + $event = new Event('Crud.Exception', new Subject()); if (isset($apiConfig['type']) && $apiConfig['type'] === 'validate') { $event->getSubject()->set([ - 'entity' => $this->getMockBuilder('\Cake\ORM\Entity') + 'entity' => $this->getMockBuilder(Entity::class) ->setMethods(['errors']) ->getMock(), ]); @@ -392,19 +403,19 @@ public function testExceptionResponse( public function testEnsureSerializeWithViewVar() { $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->setMethods(['_action', '_controller']) ->disableOriginalConstructor() ->getMock(); $controller = $this - ->getMockBuilder('\Cake\Controller\Controller') + ->getMockBuilder(Controller::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); $action = $this - ->getMockBuilder('\Crud\Action\IndexAction') + ->getMockBuilder(IndexAction::class) ->setMethods(['config', 'viewVar']) ->disableOriginalConstructor() ->getMock(); @@ -455,7 +466,7 @@ public function dataSerializeTraitActions() public function testEnsureSerializeWithSerializeTrait($action) { $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->setMethods(['_action', '_controller']) ->disableOriginalConstructor() ->getMock(); @@ -467,7 +478,7 @@ public function testEnsureSerializeWithSerializeTrait($action) ->getMock(); $controller = $this - ->getMockBuilder('\Cake\Controller\Controller') + ->getMockBuilder(Controller::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -515,13 +526,13 @@ public function testEnsureSerializeWithSerializeTrait($action) public function testEnsureSerializeAlreadySet() { $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->setMethods(['_action', '_controller']) ->disableOriginalConstructor() ->getMock(); $controller = $this - ->getMockBuilder('\Cake\Controller\Controller') + ->getMockBuilder(Controller::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -529,7 +540,7 @@ public function testEnsureSerializeAlreadySet() $controller->viewVars['_serialize'] = 'hello world'; $action = $this - ->getMockBuilder('\Crud\Action\IndexAction') + ->getMockBuilder(IndexAction::class) ->setMethods(['config', 'viewVar']) ->disableOriginalConstructor() ->getMock(); @@ -561,19 +572,19 @@ public function testEnsureSerializeAlreadySet() public function testEnsureSerializeWithViewVarChanged() { $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->setMethods(['_action', '_controller']) ->disableOriginalConstructor() ->getMock(); $controller = $this - ->getMockBuilder('\Cake\Controller\Controller') + ->getMockBuilder(Controller::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); $action = $this - ->getMockBuilder('\Crud\Action\IndexAction') + ->getMockBuilder(IndexAction::class) ->setMethods(['config', 'viewVar']) ->disableOriginalConstructor() ->getMock(); @@ -608,19 +619,19 @@ public function testEnsureSerializeWithViewVarChanged() public function testEnsureSerializeWithoutViewVar() { $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->setMethods(['_action', '_controller']) ->disableOriginalConstructor() ->getMock(); $controller = $this - ->getMockBuilder('\Crud\Test\App\Controller\BlogsController') + ->getMockBuilder(BlogsController::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); $action = $this - ->getMockBuilder('\Crud\Action\AddAction') + ->getMockBuilder(AddAction::class) ->setMethods(['config', 'scope', '_controller']) ->disableOriginalConstructor() ->getMock(); @@ -657,15 +668,15 @@ public function testEnsureSerializeWithoutViewVar() public function testEnsureSuccess() { $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->setMethods(['_controller']) ->disableOriginalConstructor() ->getMock(); - $subject = new \Crud\Event\Subject(['success' => true]); + $subject = new Subject(['success' => true]); $controller = $this - ->getMockBuilder('\Cake\Controller\Controller') + ->getMockBuilder(Controller::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -692,24 +703,24 @@ public function testEnsureSuccess() public function testEnsureData() { $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->setMethods(['_controller', '_action']) ->disableOriginalConstructor() ->getMock(); $controller = $this - ->getMockBuilder('\Cake\Controller\Controller') + ->getMockBuilder(Controller::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); $action = $this - ->getMockBuilder('Crud\Action\BaseAction') + ->getMockBuilder(BaseAction::class) ->setMethods(['getConfig']) ->disableOriginalConstructor() ->getMock(); - $subject = new \Crud\Event\Subject(['success' => true]); + $subject = new Subject(['success' => true]); $config = []; @@ -744,24 +755,24 @@ public function testEnsureData() public function testEnsureDataSubject() { $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->setMethods(['_controller', '_action']) ->disableOriginalConstructor() ->getMock(); $controller = $this - ->getMockBuilder('\Cake\Controller\Controller') + ->getMockBuilder(Controller::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); $action = $this - ->getMockBuilder('Crud\Action\BaseAction') + ->getMockBuilder(BaseAction::class) ->setMethods(['getConfig']) ->disableOriginalConstructor() ->getMock(); - $subject = new \Crud\Event\Subject(['success' => true, 'id' => 1, 'modelClass' => 'MyModel']); + $subject = new Subject(['success' => true, 'id' => 1, 'modelClass' => 'MyModel']); $config = ['data' => [ 'subject' => [ @@ -801,24 +812,24 @@ public function testEnsureDataSubject() public function testEnsureDataRaw() { $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->setMethods(['_controller', '_action']) ->disableOriginalConstructor() ->getMock(); $controller = $this - ->getMockBuilder('\Cake\Controller\Controller') + ->getMockBuilder(Controller::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); $action = $this - ->getMockBuilder('\Crud\Action\BaseAction') + ->getMockBuilder(BaseAction::class) ->setMethods(['getConfig']) ->disableOriginalConstructor() ->getMock(); - $subject = new \Crud\Event\Subject(['success' => true, 'id' => 1, 'modelClass' => 'MyModel']); + $subject = new Subject(['success' => true, 'id' => 1, 'modelClass' => 'MyModel']); $config = ['data' => ['raw' => ['{modelClass}.id' => 1]]]; @@ -853,24 +864,24 @@ public function testEnsureDataRaw() public function testEnsureDataError() { $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->setMethods(['_controller', '_action']) ->disableOriginalConstructor() ->getMock(); $controller = $this - ->getMockBuilder('\Cake\Controller\Controller') + ->getMockBuilder(Controller::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); $action = $this - ->getMockBuilder('\Crud\Action\BaseAction') + ->getMockBuilder(BaseAction::class) ->setMethods(['getConfig']) ->disableOriginalConstructor() ->getMock(); - $subject = new \Crud\Event\Subject(['success' => false]); + $subject = new Subject(['success' => false]); $config = []; @@ -905,15 +916,15 @@ public function testEnsureDataError() public function testEnsureSuccessAlreadySet() { $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->setMethods(['_controller']) ->disableOriginalConstructor() ->getMock(); - $subject = new \Crud\Event\Subject(['success' => true]); + $subject = new Subject(['success' => true]); $controller = $this - ->getMockBuilder('\Cake\Controller\Controller') + ->getMockBuilder(Controller::class) ->setMethods(['set']) ->disableOriginalConstructor() ->getMock(); @@ -948,15 +959,15 @@ public function testFlashMessageSupressed() return true; }]); - $subject = new \Crud\Event\Subject(['request' => $Request]); + $subject = new Subject(['request' => $Request]); $apiListener = $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->setMethods(null) ->disableOriginalConstructor() ->getMock(); - $event = new \Cake\Event\Event('Crud.setFlash', $subject); + $event = new Event('Crud.setFlash', $subject); $apiListener->setFlash($event); $stopped = $event->isStopped(); @@ -978,15 +989,15 @@ public function testFlashMessageEnabled() return true; }]); - $subject = new \Crud\Event\Subject(['request' => $Request]); + $subject = new Subject(['request' => $Request]); $apiListener = $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->setMethods(null) ->disableOriginalConstructor() ->getMock(); - $event = new \Cake\Event\Event('Crud.setFlash', $subject); + $event = new Event('Crud.setFlash', $subject); $apiListener->setConfig(['setFlash' => true]); $apiListener->setFlash($event); @@ -1003,19 +1014,19 @@ public function dataExpandPath() { return [ 'simple string' => [ - new \Crud\Event\Subject(['modelClass' => 'MyModel']), + new Subject(['modelClass' => 'MyModel']), '{modelClass}.id', 'MyModel.id', ], 'string and integer' => [ - new \Crud\Event\Subject(['modelClass' => 'MyModel', 'id' => 1]), + new Subject(['modelClass' => 'MyModel', 'id' => 1]), '{modelClass}.{id}', 'MyModel.1', ], 'ignore non scalar' => [ - new \Crud\Event\Subject(['modelClass' => 'MyModel', 'complex' => new \StdClass()]), + new Subject(['modelClass' => 'MyModel', 'complex' => new StdClass()]), '{modelClass}.{id}', 'MyModel.{id}', ], @@ -1031,7 +1042,7 @@ public function dataExpandPath() public function testExpandPath($subject, $path, $expected) { $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->disableOriginalConstructor() ->setMethods(null) ->getMock(); @@ -1053,7 +1064,7 @@ public function testSetupDetectors() $detectors = ['xml' => [], 'json' => []]; $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->setMethods(['_request', 'config']) ->disableOriginalConstructor() ->getMock(); @@ -1105,7 +1116,7 @@ public function testSetupDetectorsIntigration() ]; $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->setMethods(['_request', 'getConfig']) ->disableOriginalConstructor() ->getMock(); @@ -1221,13 +1232,13 @@ public function dataCheckRequestMethods() public function testCheckRequestMethods($apiConfig, $exception, $requestMethods) { $listener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->setMethods(['_action', '_request']) ->disableOriginalConstructor() ->getMock(); $action = $this - ->getMockBuilder('\Crud\Action\IndexAction') + ->getMockBuilder(IndexAction::class) ->setMethods(['getConfig']) ->disableOriginalConstructor() ->getMock(); @@ -1290,7 +1301,7 @@ public function testCheckRequestMethods($apiConfig, $exception, $requestMethods) public function testViewClass() { $apiListener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->disableOriginalConstructor() ->setMethods(null) ->getMock(); @@ -1312,7 +1323,7 @@ public function testViewClass() public function testViewClassDefaults() { $apiListener = $this - ->getMockBuilder('\Crud\Listener\ApiListener') + ->getMockBuilder(ApiListener::class) ->disableOriginalConstructor() ->setMethods(null) ->getMock(); @@ -1333,12 +1344,12 @@ public function testViewClassDefaults() public function testInjectViewClasses() { $controller = $this - ->getMockBuilder('\Cake\Controller\Controller') + ->getMockBuilder(Controller::class) ->setMethods(['foobar']) ->disableOriginalConstructor() ->getMock(); - $controller->RequestHandler = $this->getMockBuilder('\Cake\Controller\Component\RequestHandlerComponent') + $controller->RequestHandler = $this->getMockBuilder(RequestHandlerComponent::class) ->setMethods(['setConfig']) ->disableOriginalConstructor() ->getMock(); @@ -1351,7 +1362,7 @@ public function testInjectViewClasses() ->method('setConfig') ->with('viewClassMap', ['xml' => 'Xml']); - $apiListener = $this->getMockBuilder('\Crud\Listener\ApiListener') + $apiListener = $this->getMockBuilder(ApiListener::class) ->disableOriginalConstructor() ->setMethods(['_controller']) ->getMock(); diff --git a/tests/TestCase/Listener/ApiPaginationListenerTest.php b/tests/TestCase/Listener/ApiPaginationListenerTest.php index 1c379de2d..248e5db58 100644 --- a/tests/TestCase/Listener/ApiPaginationListenerTest.php +++ b/tests/TestCase/Listener/ApiPaginationListenerTest.php @@ -1,6 +1,8 @@ getMockBuilder('\Crud\Listener\ApiPaginationListener') + ->getMockBuilder(ApiPaginationListener::class) ->disableOriginalConstructor() ->setMethods(['_checkRequestType']) ->getMock(); @@ -52,13 +54,13 @@ public function testBeforeRenderNoPaginationData() $Request = $Request->withParam('paging', ['MyModel' => []]); $Controller = $this - ->getMockBuilder('\Cake\Controller\Controller') + ->getMockBuilder(Controller::class) ->disableOriginalConstructor() ->setMethods(null) ->getMock(); $Instance = $this - ->getMockBuilder('\Crud\Listener\ApiPaginationListener') + ->getMockBuilder(ApiPaginationListener::class) ->disableOriginalConstructor() ->setMethods(['_request', '_controller']) ->getMock(); @@ -73,7 +75,7 @@ public function testBeforeRenderNoPaginationData() $Controller->modelClass = 'MyModel'; - $Instance->beforeRender(new \Cake\Event\Event('something')); + $Instance->beforeRender(new Event('something')); } /** @@ -90,7 +92,7 @@ public function testBeforeRenderPaginationDataIsNull() ->getMock(); $Instance = $this - ->getMockBuilder('\Crud\Listener\ApiPaginationListener') + ->getMockBuilder(ApiPaginationListener::class) ->disableOriginalConstructor() ->setMethods(['_request', '_controller']) ->getMock(); @@ -104,7 +106,7 @@ public function testBeforeRenderPaginationDataIsNull() $Request = $Request->withParam('paging', null); - $Instance->beforeRender(new \Cake\Event\Event('something')); + $Instance->beforeRender(new Event('something')); } /** @@ -140,7 +142,7 @@ public function testBeforeRenderWithPaginationData() ]; $Controller = $this - ->getMockBuilder('\Cake\Controller\Controller') + ->getMockBuilder(Controller::class) ->disableOriginalConstructor() ->setMethods(['set']) ->getMock(); @@ -150,7 +152,7 @@ public function testBeforeRenderWithPaginationData() ->with('pagination', $expected); $Action = $this - ->getMockBuilder('\Crud\Action\BaseAction') + ->getMockBuilder(BaseAction::class) ->disableOriginalConstructor() ->setMethods(['setConfig']) ->getMock(); @@ -160,7 +162,7 @@ public function testBeforeRenderWithPaginationData() ->with('serialize.pagination', 'pagination'); $Instance = $this - ->getMockBuilder('\Crud\Listener\ApiPaginationListener') + ->getMockBuilder(ApiPaginationListener::class) ->disableOriginalConstructor() ->setMethods(['_request', '_controller', '_action']) ->getMock(); @@ -179,7 +181,7 @@ public function testBeforeRenderWithPaginationData() $Controller->modelClass = 'MyModel'; - $Instance->beforeRender(new \Cake\Event\Event('something')); + $Instance->beforeRender(new Event('something')); } /** @@ -214,7 +216,7 @@ public function testBeforeRenderWithPaginationDataForPluginModel() ]; $Controller = $this - ->getMockBuilder('\Cake\Controller\Controller') + ->getMockBuilder(Controller::class) ->disableOriginalConstructor() ->setMethods(['set']) ->getMock(); @@ -224,7 +226,7 @@ public function testBeforeRenderWithPaginationDataForPluginModel() ->with('pagination', $expected); $Action = $this - ->getMockBuilder('\Crud\Action\BaseAction') + ->getMockBuilder(BaseAction::class) ->disableOriginalConstructor() ->setMethods(['setConfig']) ->getMock(); @@ -234,7 +236,7 @@ public function testBeforeRenderWithPaginationDataForPluginModel() ->with('serialize.pagination', 'pagination'); $Instance = $this - ->getMockBuilder('\Crud\Listener\ApiPaginationListener') + ->getMockBuilder(ApiPaginationListener::class) ->disableOriginalConstructor() ->setMethods(['_request', '_controller', '_action']) ->getMock(); @@ -253,7 +255,7 @@ public function testBeforeRenderWithPaginationDataForPluginModel() $Controller->modelClass = 'MyPlugin.MyModel'; - $Instance->beforeRender(new \Cake\Event\Event('something')); + $Instance->beforeRender(new Event('something')); } /** @@ -288,7 +290,7 @@ public function testBeforeRenderMakeSurePaginationDataIsSetToBeSerialized() ]; $Controller = $this - ->getMockBuilder('\Cake\Controller\Controller') + ->getMockBuilder(Controller::class) ->disableOriginalConstructor() ->setMethods(['set']) ->getMock(); @@ -298,13 +300,13 @@ public function testBeforeRenderMakeSurePaginationDataIsSetToBeSerialized() ->with('pagination', $expected); $Action = $this - ->getMockBuilder('\Crud\Action\BaseAction') + ->getMockBuilder(BaseAction::class) ->disableOriginalConstructor() ->setMethods(null) ->getMock(); $Instance = $this - ->getMockBuilder('\Crud\Listener\ApiPaginationListener') + ->getMockBuilder(ApiPaginationListener::class) ->disableOriginalConstructor() ->setMethods(['_request', '_controller', '_action']) ->getMock(); @@ -323,7 +325,7 @@ public function testBeforeRenderMakeSurePaginationDataIsSetToBeSerialized() $Controller->modelClass = 'MyModel'; - $Instance->beforeRender(new \Cake\Event\Event('something')); + $Instance->beforeRender(new Event('something')); $this->assertSame('pagination', $Action->getConfig('serialize.pagination')); } diff --git a/tests/TestCase/Listener/ApiQueryLogListenerTest.php b/tests/TestCase/Listener/ApiQueryLogListenerTest.php index 018d4539a..6069e8788 100644 --- a/tests/TestCase/Listener/ApiQueryLogListenerTest.php +++ b/tests/TestCase/Listener/ApiQueryLogListenerTest.php @@ -3,8 +3,11 @@ use Cake\Controller\Controller; use Cake\Core\Configure; +use Cake\Database\Connection; use Cake\Event\Event; +use Crud\Action\BaseAction; use Crud\Listener\ApiQueryLogListener; +use Crud\Log\QueryLogger; use Crud\TestSuite\TestCase; /** @@ -37,7 +40,7 @@ public function tearDown() public function testImplementedEvents() { $Instance = $this - ->getMockBuilder('\Crud\Listener\ApiQueryLogListener') + ->getMockBuilder(ApiQueryLogListener::class) ->disableOriginalConstructor() ->setMethods(['_checkRequestType']) ->getMock(); @@ -64,7 +67,7 @@ public function testImplementedEvents() public function testImplementedEventsNotApiRequest() { $Instance = $this - ->getMockBuilder('\Crud\Listener\ApiQueryLogListener') + ->getMockBuilder(ApiQueryLogListener::class) ->disableOriginalConstructor() ->setMethods(['_checkRequestType']) ->getMock(); @@ -91,7 +94,7 @@ public function testBeforeRenderDebugFalse() Configure::write('debug', false); $Instance = $this - ->getMockBuilder('\Crud\Listener\ApiQueryLogListener') + ->getMockBuilder(ApiQueryLogListener::class) ->disableOriginalConstructor() ->setMethods(['_getQueryLogs']) ->getMock(); @@ -114,7 +117,7 @@ public function testBeforeRenderDebugTrue() Configure::write('debug', true); $Action = $this - ->getMockBuilder('\Crud\Action\BaseAction') + ->getMockBuilder(BaseAction::class) ->disableOriginalConstructor() ->setMethods(['setConfig']) ->getMock(); @@ -124,7 +127,7 @@ public function testBeforeRenderDebugTrue() ->with('serialize.queryLog', 'queryLog'); $Controller = $this - ->getMockBuilder('\Cake\Controller\Controller') + ->getMockBuilder(Controller::class) ->disableOriginalConstructor() ->setMethods(['set']) ->getMock(); @@ -134,7 +137,7 @@ public function testBeforeRenderDebugTrue() ->with('queryLog', []); $Instance = $this - ->getMockBuilder('\Crud\Listener\ApiQueryLogListener') + ->getMockBuilder(ApiQueryLogListener::class) ->disableOriginalConstructor() ->setMethods(['_getQueryLogs', '_action', '_controller']) ->getMock(); @@ -167,7 +170,7 @@ public function testSetupLogging() } $DefaultSource = $this - ->getMockBuilder('\Cake\Database\Connection') + ->getMockBuilder(Connection::class) ->disableOriginalConstructor() ->setMethods([$methodName, 'setLogger']) ->getMock(); @@ -178,10 +181,10 @@ public function testSetupLogging() $DefaultSource ->expects($this->once()) ->method('setLogger') - ->with($this->isInstanceOf('\Crud\Log\QueryLogger')); + ->with($this->isInstanceOf(QueryLogger::class)); $Instance = $this - ->getMockBuilder('\Crud\Listener\ApiQueryLogListener') + ->getMockBuilder(ApiQueryLogListener::class) ->disableOriginalConstructor() ->setMethods(['_getSources', '_getSource']) ->getMock(); @@ -198,6 +201,71 @@ public function testSetupLogging() $Instance->setupLogging(new Event('something')); } + /** + * Test setting up only specific query loggers + * + * @return void + */ + public function testSetupLoggingConfiguredSources() + { + $methodName = 'enableQueryLogging'; + if (version_compare(Configure::version(), '3.7.0RC', '<')) { + $methodName = 'logQueries'; + } + + $DefaultSource = $this + ->getMockBuilder(Connection::class) + ->disableOriginalConstructor() + ->setMethods([$methodName, 'setLogger']) + ->getMock(); + $DefaultSource + ->expects($this->once()) + ->method($methodName) + ->with(true); + $DefaultSource + ->expects($this->once()) + ->method('setLogger') + ->with($this->isInstanceOf(QueryLogger::class)); + + $TestSource = $this + ->getMockBuilder(Connection::class) + ->disableOriginalConstructor() + ->setMethods([$methodName, 'setLogger']) + ->getMock(); + $TestSource + ->expects($this->once()) + ->method($methodName) + ->with(true); + $TestSource + ->expects($this->once()) + ->method('setLogger') + ->with($this->isInstanceOf(QueryLogger::class)); + + $Instance = $this + ->getMockBuilder(ApiQueryLogListener::class) + ->disableOriginalConstructor() + ->setMethods(['_getSources', '_getSource']) + ->getMock(); + $Instance + ->expects($this->never()) + ->method('_getSources'); + + $Instance + ->expects($this->at(0)) + ->method('_getSource') + ->with('default') + ->will($this->returnValue($DefaultSource)); + + $Instance + ->expects($this->at(1)) + ->method('_getSource') + ->with('test') + ->will($this->returnValue($TestSource)); + + $Instance->setConfig('connections', ['default', 'test']); + $Instance->setupLogging(new Event('something')); + } + /** * Test getting query logs using protected method * diff --git a/tests/TestCase/Listener/RedirectListenerTest.php b/tests/TestCase/Listener/RedirectListenerTest.php index 454a02e5d..f1263aad3 100644 --- a/tests/TestCase/Listener/RedirectListenerTest.php +++ b/tests/TestCase/Listener/RedirectListenerTest.php @@ -1,8 +1,12 @@ getMockBuilder('\Crud\Listener\RedirectListener') + ->getMockBuilder(RedirectListener::class) ->setMethods(null) ->disableoriginalConstructor() ->getMock(); @@ -40,7 +44,7 @@ public function testImplementedEvents() public function testSetup() { $listener = $this - ->getMockBuilder('\Crud\Listener\RedirectListener') + ->getMockBuilder(RedirectListener::class) ->setMethods(null) ->disableoriginalConstructor() ->getMock(); @@ -77,7 +81,7 @@ public function testSetup() public function testReaderGetWorks() { $listener = $this - ->getMockBuilder('\Crud\Listener\RedirectListener') + ->getMockBuilder(RedirectListener::class) ->setMethods(null) ->disableoriginalConstructor() ->getMock(); @@ -98,7 +102,7 @@ public function testReaderGetWorks() public function testReaderGetFails() { $listener = $this - ->getMockBuilder('\Crud\Listener\RedirectListener') + ->getMockBuilder(RedirectListener::class) ->setMethods(null) ->disableoriginalConstructor() ->getMock(); @@ -118,7 +122,7 @@ public function testReaderGetFails() public function testReaderSetWorks() { $listener = $this - ->getMockBuilder('\Crud\Listener\RedirectListener') + ->getMockBuilder(RedirectListener::class) ->setMethods(null) ->disableoriginalConstructor() ->getMock(); @@ -143,14 +147,14 @@ public function testReaderSetWorks() public function testReaderRequestKey() { $listener = $this - ->getMockBuilder('\Crud\Listener\RedirectListener') + ->getMockBuilder(RedirectListener::class) ->setMethods(['_request']) ->disableoriginalConstructor() ->getMock(); $listener->setup(); - $subject = new \Crud\Event\Subject(); + $subject = new Subject(); $request = (new ServerRequest())->withParam('action', 'index'); $listener->expects($this->any())->method('_request')->will($this->returnValue($request)); @@ -171,14 +175,14 @@ public function testReaderRequestKey() public function testReaderRequestData() { $listener = $this - ->getMockBuilder('\Crud\Listener\RedirectListener') + ->getMockBuilder(RedirectListener::class) ->setMethods(['_request']) ->disableoriginalConstructor() ->getMock(); $listener->setup(); - $subject = new \Crud\Event\Subject(); + $subject = new Subject(); $request = (new ServerRequest())->withData('hello', 'world'); $listener->expects($this->any())->method('_request')->will($this->returnValue($request)); @@ -199,14 +203,14 @@ public function testReaderRequestData() public function testReaderRequestQuery() { $listener = $this - ->getMockBuilder('\Crud\Listener\RedirectListener') + ->getMockBuilder(RedirectListener::class) ->setMethods(['_request']) ->disableoriginalConstructor() ->getMock(); $listener->setup(); - $subject = new \Crud\Event\Subject(); + $subject = new Subject(); $request = (new ServerRequest())->withQueryParams(['hello' => 'world']); $listener->expects($this->any())->method('_request')->will($this->returnValue($request)); @@ -227,16 +231,16 @@ public function testReaderRequestQuery() public function testReaderEntityField() { $listener = $this - ->getMockBuilder('\Crud\Listener\RedirectListener') + ->getMockBuilder(RedirectListener::class) ->setMethods(null) ->disableoriginalConstructor() ->getMock(); $listener->setup(); - $subject = new \Crud\Event\Subject(); + $subject = new Subject(); $subject->entity = $this - ->getMockBuilder('\Cake\ORM\Entity') + ->getMockBuilder(Entity::class) ->setMethods(['get']) ->disableoriginalConstructor() ->getMock(); @@ -259,14 +263,14 @@ public function testReaderEntityField() public function testReaderSubjectKey() { $listener = $this - ->getMockBuilder('\Crud\Listener\RedirectListener') + ->getMockBuilder(RedirectListener::class) ->setMethods(null) ->disableoriginalConstructor() ->getMock(); $listener->setup(); - $subject = new \Crud\Event\Subject(); + $subject = new Subject(); $subject->welcome = 'hello world'; $reader = $listener->reader('subject.key'); @@ -286,13 +290,13 @@ public function testReaderSubjectKey() public function testRedirectWithNoConfig() { $action = $this - ->getMockBuilder('\Crud\Action\BaseAction') + ->getMockBuilder(BaseAction::class) ->setMethods(null) ->disableoriginalConstructor() ->getMock(); $listener = $this - ->getMockBuilder('\Crud\Listener\RedirectListener') + ->getMockBuilder(RedirectListener::class) ->setMethods(['_action', '_getKey']) ->disableoriginalConstructor() ->getMock(); @@ -304,9 +308,9 @@ public function testRedirectWithNoConfig() ->expects($this->never()) ->method('_getKey'); - $subject = new \Crud\Event\Subject(); + $subject = new Subject(); - $listener->beforeRedirect(new \Cake\Event\Event('Crud.beforeRedirect', $subject)); + $listener->beforeRedirect(new Event('Crud.beforeRedirect', $subject)); } /** @@ -318,17 +322,17 @@ public function testRedirectWithNoConfig() public function testRedirectWithConfigButNoValidKey() { $action = $this - ->getMockBuilder('\Crud\Action\BaseAction') + ->getMockBuilder(BaseAction::class) ->setMethods(null) ->disableoriginalConstructor() ->getMock(); $action->redirectConfig('add', ['reader' => 'request.key', 'key' => 'hello']); - $subject = new \Crud\Event\Subject(); + $subject = new Subject(); $listener = $this - ->getMockBuilder('\Crud\Listener\RedirectListener') + ->getMockBuilder(RedirectListener::class) ->setMethods(['_action', '_getKey', '_getUrl']) ->disableoriginalConstructor() ->getMock(); @@ -345,7 +349,7 @@ public function testRedirectWithConfigButNoValidKey() ->expects($this->never()) ->method('_getUrl'); - $listener->beforeRedirect(new \Cake\Event\Event('Crud.beforeRedirect', $subject)); + $listener->beforeRedirect(new Event('Crud.beforeRedirect', $subject)); } /** @@ -357,7 +361,7 @@ public function testRedirectWithConfigButNoValidKey() public function testRedirectWithConfigAndValidKey() { $action = $this - ->getMockBuilder('\Crud\Action\BaseAction') + ->getMockBuilder(BaseAction::class) ->setMethods(null) ->disableoriginalConstructor() ->getMock(); @@ -368,10 +372,10 @@ public function testRedirectWithConfigAndValidKey() 'url' => ['action' => 'index'], ]); - $subject = new \Crud\Event\Subject(); + $subject = new Subject(); $listener = $this - ->getMockBuilder('\Crud\Listener\RedirectListener') + ->getMockBuilder(RedirectListener::class) ->setMethods(['_action', '_getKey', '_getUrl']) ->disableoriginalConstructor() ->getMock(); @@ -390,7 +394,7 @@ public function testRedirectWithConfigAndValidKey() ->with($subject, ['action' => 'index']) ->will($this->returnValue(['action' => 'index'])); - $listener->beforeRedirect(new \Cake\Event\Event('Crud.beforeRedirect', $subject)); + $listener->beforeRedirect(new Event('Crud.beforeRedirect', $subject)); $this->assertSame(['action' => 'index'], $subject->url); } @@ -407,39 +411,39 @@ public function dataProviderGetUrl() ->withQueryParams(['parent_id' => 10]) ->withData('epic', 'jippi'); - $Model = new \Cake\ORM\Entity(); + $Model = new Entity(); $Model->id = 69; $Model->slug = 'jippi-is-awesome'; $Model->data = ['name' => 'epic', 'slug' => 'epic']; return [ [ - new \Crud\Event\Subject(), + new Subject(), ['action' => 'index'], ['action' => 'index'], ], [ - new \Crud\Event\Subject(), + new Subject(), ['controller' => 'posts', 'action' => 'index'], ['controller' => 'posts', 'action' => 'index'], ], [ - new \Crud\Event\Subject(['request' => $Request]), + new Subject(['request' => $Request]), ['action' => ['request.key', 'action']], ['action' => 'index'], ], [ - new \Crud\Event\Subject(['request' => $Request]), + new Subject(['request' => $Request]), ['action' => ['request.data', 'epic']], ['action' => 'jippi'], ], [ - new \Crud\Event\Subject(['request' => $Request]), + new Subject(['request' => $Request]), ['action' => ['request.query', 'parent_id']], ['action' => 10], ], [ - new \Crud\Event\Subject(['id' => 69]), + new Subject(['id' => 69]), ['action' => 'edit', ['subject.key', 'id']], ['action' => 'edit', 69], ], @@ -452,10 +456,10 @@ public function dataProviderGetUrl() * @dataProvider dataProviderGetUrl * @return void */ - public function testGetUrl(\Crud\Event\Subject $subject, $url, $expected) + public function testGetUrl(Subject $subject, $url, $expected) { $listener = $this - ->getMockBuilder('\Crud\Listener\RedirectListener') + ->getMockBuilder(RedirectListener::class) ->setMethods(['_request']) ->disableoriginalConstructor() ->getMock(); diff --git a/tests/TestCase/Listener/RelatedModelsListenerTest.php b/tests/TestCase/Listener/RelatedModelsListenerTest.php index 1319cccad..2e4a2b269 100644 --- a/tests/TestCase/Listener/RelatedModelsListenerTest.php +++ b/tests/TestCase/Listener/RelatedModelsListenerTest.php @@ -1,11 +1,17 @@ getMockBuilder('\Crud\Listener\RelatedModelsListener') + ->getMockBuilder(RelatedModelsListener::class) ->disableOriginalConstructor() ->setMethods(['relatedModels']) ->getMock(); @@ -52,7 +58,7 @@ public function testModels() public function testModelsEmpty() { $listener = $this - ->getMockBuilder('\Crud\Listener\RelatedModelsListener') + ->getMockBuilder(RelatedModelsListener::class) ->disableOriginalConstructor() ->setMethods(['relatedModels']) ->getMock(); @@ -78,7 +84,7 @@ public function testModelsEmpty() public function testModelsString() { $listener = $this - ->getMockBuilder('\Crud\Listener\RelatedModelsListener') + ->getMockBuilder(RelatedModelsListener::class) ->disableOriginalConstructor() ->setMethods(['relatedModels', 'getAssociatedByName']) ->getMock(); @@ -105,7 +111,7 @@ public function testModelsString() public function testModelsTrue() { $listener = $this - ->getMockBuilder('\Crud\Listener\RelatedModelsListener') + ->getMockBuilder(RelatedModelsListener::class) ->disableOriginalConstructor() ->setMethods(['relatedModels', 'getAssociatedByType']) ->getMock(); @@ -132,22 +138,22 @@ public function testModelsTrue() public function testGetAssociatedByTypeReturnValue() { $listener = $this - ->getMockBuilder('\Crud\Listener\RelatedModelsListener') + ->getMockBuilder(RelatedModelsListener::class) ->disableOriginalConstructor() ->setMethods(['relatedModels', '_table']) ->getMock(); $table = $this - ->getMockBuilder('\Cake\ORM\Table') + ->getMockBuilder(Table::class) ->disableOriginalConstructor() ->setMethods(['associations']) ->getMock(); $associationCollection = $this - ->getMockBuilder('\Cake\ORM\AssociationCollection') + ->getMockBuilder(AssociationCollection::class) ->disableOriginalConstructor() ->setMethods(['get', 'keys']) ->getMock(); $association = $this - ->getMockBuilder('\Cake\ORM\Association') + ->getMockBuilder(Association::class) ->disableOriginalConstructor() ->setMethods(['type', 'getName', 'eagerLoader', 'cascadeDelete', 'isOwningSide', 'saveAssociated']) ->getMock(); @@ -195,22 +201,22 @@ public function testGetAssociatedByTypeReturnValue() public function testGetAssociatedByNameReturnValue() { $listener = $this - ->getMockBuilder('\Crud\Listener\RelatedModelsListener') + ->getMockBuilder(RelatedModelsListener::class) ->disableOriginalConstructor() ->setMethods(['relatedModels', '_table']) ->getMock(); $table = $this - ->getMockBuilder('\Cake\ORM\Table') + ->getMockBuilder(Table::class) ->disableOriginalConstructor() ->setMethods(['associations']) ->getMock(); $associationCollection = $this - ->getMockBuilder('\Cake\ORM\AssociationCollection') + ->getMockBuilder(AssociationCollection::class) ->disableOriginalConstructor() ->setMethods(['get']) ->getMock(); $association = $this - ->getMockBuilder('\Cake\ORM\Association') + ->getMockBuilder(Association::class) ->disableOriginalConstructor() ->setMethods(['type', 'getName', 'eagerLoader', 'cascadeDelete', 'isOwningSide', 'saveAssociated']) ->getMock(); @@ -251,7 +257,7 @@ public function testListFinder() $model->addBehavior('Tree'); $association = $this - ->getMockBuilder('\Cake\ORM\Association\BelongsTo') + ->getMockBuilder(BelongsTo::class) ->disableOriginalConstructor() ->setMethods(['getTarget']) ->getMock(); @@ -262,7 +268,7 @@ public function testListFinder() ->will($this->returnValue($model)); $listener = $this - ->getMockBuilder('\Crud\Listener\RelatedModelsListener') + ->getMockBuilder(RelatedModelsListener::class) ->disableOriginalConstructor() ->setMethods(['publishRelatedModels']) ->getMock(); @@ -279,12 +285,12 @@ public function testListFinder() public function testbeforePaginate() { $listener = $this - ->getMockBuilder('\Crud\Listener\RelatedModelsListener') + ->getMockBuilder(RelatedModelsListener::class) ->disableOriginalConstructor() ->setMethods(['models']) ->getMock(); $table = $this - ->getMockBuilder('\Cake\ORM\Table') + ->getMockBuilder(Table::class) ->disableOriginalConstructor() ->setMethods(['associations', 'findAssociation', 'association', 'getSchema']) ->getMock(); @@ -299,7 +305,7 @@ public function testbeforePaginate() ->method('models') ->will($this->returnValue(['Users' => 'manyToOne'])); - $db = $this->getMockBuilder('\Cake\Database\Connection') + $db = $this->getMockBuilder(Connection::class) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/TestCase/Listener/SearchListenerTest.php b/tests/TestCase/Listener/SearchListenerTest.php index bfd611259..8cb54222c 100644 --- a/tests/TestCase/Listener/SearchListenerTest.php +++ b/tests/TestCase/Listener/SearchListenerTest.php @@ -7,11 +7,14 @@ use Cake\Event\EventManager; use Cake\Http\Response; use Cake\Http\ServerRequest; +use Cake\ORM\BehaviorRegistry; +use Cake\ORM\Table; use Cake\ORM\TableRegistry; use Crud\Event\Subject; use Crud\Listener\SearchListener; use Crud\TestSuite\TestCase; use Muffin\Webservice\Model\EndpointRegistry; +use Muffin\Webservice\Query; /** * Licensed under The MIT License @@ -36,7 +39,7 @@ public function tearDown() public function testImplementedEvents() { $listener = $this - ->getMockBuilder('\Crud\Listener\SearchListener') + ->getMockBuilder(SearchListener::class) ->setMethods(null) ->disableoriginalConstructor() ->getMock(); @@ -66,14 +69,14 @@ public function testInjectSearchException() $eventManager = new EventManager(); $controller = new Controller($request, $response, 'Search', $eventManager); - $behaviorRegistryMock = $this->getMockBuilder('\Cake\ORM\BehaviorRegistry') + $behaviorRegistryMock = $this->getMockBuilder(BehaviorRegistry::class) ->setMockClassName('BehaviorRegistry') ->getMock(); $behaviorRegistryMock->expects($this->once()) ->method('has') ->will($this->returnValue(false)); - $tableMock = $this->getMockBuilder('\Cake\ORM\Table') + $tableMock = $this->getMockBuilder(Table::class) ->setMockClassName('SearchTables') ->setMethods(['behaviors', 'filterParams']) ->getMock(); @@ -83,7 +86,7 @@ public function testInjectSearchException() TableRegistry::set('Search', $tableMock); - $queryMock = $this->getMockBuilder('\Cake\ORM\Query') + $queryMock = $this->getMockBuilder(\Cake\ORM\Query::class) ->disableOriginalConstructor() ->getMock(); @@ -123,7 +126,7 @@ public function testInjectSearch() $eventManager = new EventManager(); $controller = new Controller($request, $response, 'Search', $eventManager); - $behaviorRegistryMock = $this->getMockBuilder('\Cake\ORM\BehaviorRegistry') + $behaviorRegistryMock = $this->getMockBuilder(BehaviorRegistry::class) ->setMockClassName('BehaviorRegistry') ->setMethods(['hasMethod', 'has']) ->getMock(); @@ -134,7 +137,7 @@ public function testInjectSearch() ->method('hasMethod') ->will($this->returnValue(false)); - $tableMock = $this->getMockBuilder('\Cake\ORM\Table') + $tableMock = $this->getMockBuilder(Table::class) ->setMockClassName('SearchTables') ->setMethods(['behaviors']) ->getMock(); @@ -144,7 +147,7 @@ public function testInjectSearch() TableRegistry::set('Search', $tableMock); - $queryMock = $this->getMockBuilder('\Cake\ORM\Query') + $queryMock = $this->getMockBuilder(\Cake\ORM\Query::class) ->disableOriginalConstructor() ->getMock(); $queryMock->expects($this->once()) @@ -193,7 +196,7 @@ public function testInjectSearchWebserviceEndpoint() $controller->modelFactory('Endpoint', ['Muffin\Webservice\Model\EndpointRegistry', 'get']); $controller->setModelType('Endpoint'); - $queryMock = $this->getMockBuilder('\Muffin\Webservice\Query') + $queryMock = $this->getMockBuilder(Query::class) ->disableOriginalConstructor() ->getMock(); $queryMock->expects($this->once()) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 348e7db36..9e95d324b 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,6 +1,8 @@ 'Crud\Test\App']); Cake\Core\Configure::write('debug', true); -$TMP = new \Cake\Filesystem\Folder(TMP); +$TMP = new Folder(TMP); $TMP->create(TMP . 'cache/models', 0777); $TMP->create(TMP . 'cache/persistent', 0777); $TMP->create(TMP . 'cache/views', 0777);