Browse Source

Fix usage of deprecated features across the framework.

Mark Story 8 years ago
parent
commit
3d6592547a

+ 2 - 2
src/Core/ObjectRegistry.php

@@ -318,7 +318,7 @@ abstract class ObjectRegistry implements Countable, IteratorAggregate
             $this->unload($objectName);
         }
         if ($this instanceof EventDispatcherInterface && $object instanceof EventListenerInterface) {
-            $this->eventManager()->on($object);
+            $this->getEventManager()->on($object);
         }
         $this->_loaded[$name] = $object;
 
@@ -342,7 +342,7 @@ abstract class ObjectRegistry implements Countable, IteratorAggregate
 
         $object = $this->_loaded[$objectName];
         if ($this instanceof EventDispatcherInterface && $object instanceof EventListenerInterface) {
-            $this->eventManager()->off($object);
+            $this->getEventManager()->off($object);
         }
         unset($this->_loaded[$objectName]);
 

+ 1 - 1
src/View/ViewVarsTrait.php

@@ -117,7 +117,7 @@ trait ViewVarsTrait
             $this->viewVars,
             isset($this->request) ? $this->request : null,
             isset($this->response) ? $this->response : null,
-            $this instanceof EventDispatcherInterface ? $this->eventManager() : null
+            $this instanceof EventDispatcherInterface ? $this->getEventManager() : null
         );
     }
 

+ 1 - 1
tests/TestCase/Controller/Component/PaginatorComponentTest.php

@@ -263,7 +263,7 @@ class PaginatorComponentTest extends TestCase
         $tags = TableRegistry::get('Tags');
         $tags->belongsToMany('Authors');
 
-        $articles->eventManager()->on('Model.beforeFind', function ($event, $query) {
+        $articles->getEventManager()->on('Model.beforeFind', function ($event, $query) {
             $query ->matching('Tags', function ($q) {
                 return $q->matching('Authors', function ($q) {
                     return $q->where(['Authors.name' => 'larry']);

+ 1 - 1
tests/TestCase/Controller/Component/RequestHandlerComponentTest.php

@@ -741,7 +741,7 @@ class RequestHandlerComponentTest extends TestCase
     public function testRenderAsCalledTwice()
     {
         $this->Controller->getEventManager()->on('Controller.beforeRender', function (\Cake\Event\Event $e) {
-            return $e->subject()->response;
+            return $e->getSubject()->response;
         });
         $this->Controller->render();
 

+ 3 - 3
tests/TestCase/Controller/ControllerTest.php

@@ -928,7 +928,7 @@ class ControllerTest extends TestCase
         $response = $this->getMockBuilder('Cake\Http\Response')->getMock();
         $Controller = new \TestApp\Controller\Admin\PostsController($request, $response);
         $Controller->getEventManager()->on('Controller.beforeRender', function (Event $e) {
-            return $e->subject()->response;
+            return $e->getSubject()->response;
         });
         $Controller->render();
         $this->assertEquals('Admin' . DS . 'Posts', $Controller->viewBuilder()->templatePath());
@@ -939,7 +939,7 @@ class ControllerTest extends TestCase
         $response = $this->getMockBuilder('Cake\Http\Response')->getMock();
         $Controller = new \TestApp\Controller\Admin\PostsController($request, $response);
         $Controller->getEventManager()->on('Controller.beforeRender', function (Event $e) {
-            return $e->subject()->response;
+            return $e->getSubject()->response;
         });
         $Controller->render();
         $this->assertEquals('Admin' . DS . 'Super' . DS . 'Posts', $Controller->viewBuilder()->templatePath());
@@ -950,7 +950,7 @@ class ControllerTest extends TestCase
         ]);
         $Controller = new \TestApp\Controller\PagesController($request, $response);
         $Controller->getEventManager()->on('Controller.beforeRender', function (Event $e) {
-            return $e->subject()->response;
+            return $e->getSubject()->response;
         });
         $Controller->render();
         $this->assertEquals('Pages', $Controller->viewBuilder()->templatePath());

+ 1 - 1
tests/TestCase/Datasource/PaginatorTest.php

@@ -199,7 +199,7 @@ class PaginatorTest extends TestCase
         $articles->belongsToMany('Tags');
         $tags = TableRegistry::get('Tags');
         $tags->belongsToMany('Authors');
-        $articles->eventManager()->on('Model.beforeFind', function ($event, $query) {
+        $articles->getEventManager()->on('Model.beforeFind', function ($event, $query) {
             $query ->matching('Tags', function ($q) {
                 return $q->matching('Authors', function ($q) {
                     return $q->where(['Authors.name' => 'larry']);

+ 4 - 4
tests/TestCase/Error/ExceptionRendererTest.php

@@ -931,8 +931,8 @@ class ExceptionRendererTest extends TestCase
             $fired[] = $event->getName();
         };
         $events = EventManager::instance();
-        $events->attach($listener, 'Controller.shutdown');
-        $events->attach($listener, 'Dispatcher.afterDispatch');
+        $events->on('Controller.shutdown', $listener);
+        $events->on('Dispatcher.afterDispatch', $listener);
 
         $exception = new Exception('Terrible');
         $renderer = new ExceptionRenderer($exception);
@@ -976,8 +976,8 @@ class ExceptionRendererTest extends TestCase
             $fired[] = $event->getName();
         };
         $events = EventManager::instance();
-        $events->attach($listener, 'Controller.shutdown');
-        $events->attach($listener, 'Dispatcher.afterDispatch');
+        $events->on('Controller.shutdown', $listener);
+        $events->on('Dispatcher.afterDispatch', $listener);
 
         $exception = new MissingWidgetThingException('Widget not found');
         $renderer = $this->_mockResponse(new MyCustomExceptionRenderer($exception));

+ 2 - 2
tests/TestCase/ORM/Association/BelongsToTest.php

@@ -373,7 +373,7 @@ class BelongsToTest extends TestCase
         $listener = $this->getMockBuilder('stdClass')
             ->setMethods(['__invoke'])
             ->getMock();
-        $this->company->getEventManager()->attach($listener, 'Model.beforeFind');
+        $this->company->getEventManager()->on('Model.beforeFind', $listener);
         $association = new BelongsTo('Companies', $config);
         $listener->expects($this->once())->method('__invoke')
             ->with(
@@ -401,7 +401,7 @@ class BelongsToTest extends TestCase
         $listener = $this->getMockBuilder('stdClass')
             ->setMethods(['__invoke'])
             ->getMock();
-        $this->company->getEventManager()->attach($listener, 'Model.beforeFind');
+        $this->company->getEventManager()->on('Model.beforeFind', $listener);
         $association = new BelongsTo('Companies', $config);
         $options = new \ArrayObject(['something' => 'more']);
         $listener->expects($this->once())->method('__invoke')

+ 3 - 3
tests/TestCase/ORM/MarshallerTest.php

@@ -380,7 +380,7 @@ class MarshallerTest extends TestCase
         $users->hasOne('Articles', [
             'foreignKey' => 'author_id'
         ]);
-        $articles->eventManager()->on('Model.beforeMarshal', function ($event, $data, $options) {
+        $articles->getEventManager()->on('Model.beforeMarshal', function ($event, $data, $options) {
             // Blank the association, so it doesn't become dirty.
             unset($data['not_a_real_field']);
         });
@@ -1805,11 +1805,11 @@ class MarshallerTest extends TestCase
         $entity->clean();
 
         // Adding a forced join to have another table with the same column names
-        $this->articles->Tags->getEventManager()->attach(function ($e, $query) {
+        $this->articles->Tags->getEventManager()->on('Model.beforeFind', function ($e, $query) {
             $left = new IdentifierExpression('Tags.id');
             $right = new IdentifierExpression('a.id');
             $query->leftJoin(['a' => 'tags'], $query->newExpr()->eq($left, $right));
-        }, 'Model.beforeFind');
+        });
 
         $marshall = new Marshaller($this->articles);
         $result = $marshall->merge($entity, $data, ['associated' => ['Tags']]);

+ 1 - 1
tests/TestCase/ORM/QueryRegressionTest.php

@@ -760,7 +760,7 @@ class QueryRegressionTest extends TestCase
         ]));
         $this->assertNotFalse($result);
 
-        $table->eventManager()
+        $table->getEventManager()
             ->on('Model.beforeFind', function (Event $event, $query) {
                 $query->contain(['Authors']);
             });

+ 8 - 8
tests/TestCase/ORM/QueryTest.php

@@ -2569,14 +2569,14 @@ class QueryTest extends TestCase
         }]);
         $this->assertFalse($query->eagerLoaded());
 
-        $table->getEventManager()->attach(function ($e, $q, $o, $primary) {
+        $table->getEventManager()->on('Model.beforeFind', function ($e, $q, $o, $primary) {
             $this->assertTrue($primary);
-        }, 'Model.beforeFind');
+        });
 
         TableRegistry::get('articles')
-            ->getEventManager()->attach(function ($e, $q, $o, $primary) {
+            ->getEventManager()->on('Model.beforeFind', function ($e, $q, $o, $primary) {
                 $this->assertFalse($primary);
-            }, 'Model.beforeFind');
+            });
         $query->all();
     }
 
@@ -2597,14 +2597,14 @@ class QueryTest extends TestCase
         }]);
         $this->assertFalse($query->isEagerLoaded());
 
-        $table->getEventManager()->attach(function ($e, $q, $o, $primary) {
+        $table->getEventManager()->on('Model.beforeFind', function ($e, $q, $o, $primary) {
             $this->assertTrue($primary);
-        }, 'Model.beforeFind');
+        });
 
         TableRegistry::get('articles')
-            ->getEventManager()->attach(function ($e, $q, $o, $primary) {
+            ->getEventManager()->on('Model.beforeFind', function ($e, $q, $o, $primary) {
                 $this->assertFalse($primary);
-            }, 'Model.beforeFind');
+            });
         $query->all();
     }
 

+ 3 - 3
tests/TestCase/View/ViewTest.php

@@ -942,8 +942,8 @@ class ViewTest extends TestCase
             $count++;
         };
         $events = $this->View->getEventManager();
-        $events->attach($callback, 'View.beforeRender');
-        $events->attach($callback, 'View.afterRender');
+        $events->on('View.beforeRender', $callback);
+        $events->on('View.afterRender', $callback);
 
         $this->View->element('test_element', [], ['callbacks' => true]);
         $this->assertEquals(2, $count);
@@ -1048,7 +1048,7 @@ class ViewTest extends TestCase
         $View->autoLayout = false;
         $listener = new TestViewEventListenerInterface();
 
-        $View->getEventManager()->attach($listener);
+        $View->getEventManager()->on($listener);
 
         $View->render('index');
         $this->assertEquals(View::TYPE_VIEW, $listener->beforeRenderViewType);

+ 2 - 2
tests/test_app/TestApp/Controller/Component/TestAuthComponent.php

@@ -33,10 +33,10 @@ class TestAuthComponent extends AuthComponent
     public function authCheck(Event $event)
     {
         if (isset($this->earlyAuthTest)) {
-            if ($this->_config['checkAuthIn'] !== $event->name()) {
+            if ($this->_config['checkAuthIn'] !== $event->getName()) {
                 return null;
             }
-            $this->authCheckCalledFrom = $event->name();
+            $this->authCheckCalledFrom = $event->getName();
 
             return null;
         }