From 9df5f574fe816459a969f4d2fcb44e17bea45d99 Mon Sep 17 00:00:00 2001 From: dereuromark Date: Thu, 24 Nov 2016 01:47:17 +0100 Subject: [PATCH] Remove deprecated method usage in tests. Make typehinting possible which reveals coding errors. --- tests/TestCase/View/HelperRegistryTest.php | 7 ++- tests/TestCase/View/HelperTest.php | 22 +++------- tests/TestCase/View/JsonViewTest.php | 8 ++-- .../TestCase/View/StringTemplateTraitTest.php | 15 ++++--- tests/TestCase/View/ViewBuilderTest.php | 44 +++++++++---------- tests/TestCase/View/ViewTest.php | 10 +++++ tests/TestCase/View/ViewVarsTraitTest.php | 19 +++++--- 7 files changed, 70 insertions(+), 55 deletions(-) diff --git a/tests/TestCase/View/HelperRegistryTest.php b/tests/TestCase/View/HelperRegistryTest.php index d61b3883f8d..4c0b1fc20b4 100644 --- a/tests/TestCase/View/HelperRegistryTest.php +++ b/tests/TestCase/View/HelperRegistryTest.php @@ -43,6 +43,11 @@ class HelperRegistryTest extends TestCase */ public $Helpers; + /** + * @var \Cake\Event\EventManager + */ + public $Events; + /** * setUp * @@ -241,7 +246,7 @@ public function testReset() ); $this->assertCount(1, $this->Events->listeners('View.beforeRender')); - $this->assertNull($this->Helpers->reset(), 'No return expected'); + $this->Helpers->reset(); $this->assertCount(0, $this->Events->listeners('View.beforeRender')); $this->assertNotSame($instance, $this->Helpers->load('EventListenerTest')); diff --git a/tests/TestCase/View/HelperTest.php b/tests/TestCase/View/HelperTest.php index 9077ae5fc99..38b84436433 100644 --- a/tests/TestCase/View/HelperTest.php +++ b/tests/TestCase/View/HelperTest.php @@ -44,19 +44,6 @@ class TestHelper extends Helper */ public $helpers = ['Html', 'TestPlugin.OtherHelper']; - /** - * expose a method as public - * - * @param string $options - * @param string $exclude - * @param string $insertBefore - * @param string $insertAfter - * @return void - */ - public function parseAttributes($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) - { - return $this->_parseAttributes($options, $exclude, $insertBefore, $insertAfter); - } } /** @@ -65,6 +52,11 @@ public function parseAttributes($options, $exclude = null, $insertBefore = ' ', class HelperTest extends TestCase { + /** + * @var \Cake\View\View + */ + public $View; + /** * setUp method * @@ -76,8 +68,6 @@ public function setUp() Router::reload(); $this->View = new View(); - $this->Helper = new Helper($this->View); - $this->Helper->request = new Request(); } /** @@ -91,7 +81,7 @@ public function tearDown() Configure::delete('Asset'); Plugin::unload(); - unset($this->Helper, $this->View); + unset($this->View); } /** diff --git a/tests/TestCase/View/JsonViewTest.php b/tests/TestCase/View/JsonViewTest.php index f06b43b5c26..994be78ca8c 100644 --- a/tests/TestCase/View/JsonViewTest.php +++ b/tests/TestCase/View/JsonViewTest.php @@ -241,7 +241,7 @@ public function testRenderWithoutView($data, $serialize, $jsonOptions, $expected $Controller->set($data); $Controller->set('_serialize', $serialize); $Controller->set('_jsonOptions', $jsonOptions); - $Controller->viewBuilder()->className('Json'); + $Controller->viewBuilder()->setClassName('Json'); $View = $Controller->createView(); $output = $View->render(false); @@ -264,7 +264,7 @@ public function testRenderSerializeNoHelpers() 'tags' => ['cakephp', 'framework'], '_serialize' => 'tags' ]); - $Controller->viewBuilder()->className('Json'); + $Controller->viewBuilder()->setClassName('Json'); $View = $Controller->createView(); $View->render(); @@ -288,7 +288,7 @@ public function testJsonpResponse() '_serialize' => 'data', '_jsonp' => true ]); - $Controller->viewBuilder()->className('Json'); + $Controller->viewBuilder()->setClassName('Json'); $View = $Controller->createView(); $output = $View->render(false); @@ -330,7 +330,7 @@ public function testRenderWithView() ] ]; $Controller->set('user', $data); - $Controller->viewBuilder()->className('Json'); + $Controller->viewBuilder()->setClassName('Json'); $View = $Controller->createView(); $View->viewPath = $Controller->name; $output = $View->render('index'); diff --git a/tests/TestCase/View/StringTemplateTraitTest.php b/tests/TestCase/View/StringTemplateTraitTest.php index 9b1057f14ad..45af8716b16 100644 --- a/tests/TestCase/View/StringTemplateTraitTest.php +++ b/tests/TestCase/View/StringTemplateTraitTest.php @@ -41,6 +41,11 @@ class TestStringTemplate class StringTemplateTraitTest extends TestCase { + /** + * @var TestStringTemplate + */ + public $Template; + /** * setUp method * @@ -62,13 +67,13 @@ public function testInitStringTemplates() $templates = [ 'text' => '

{{text}}

', ]; - $this->Template->templates($templates); + $this->Template->setTemplates($templates); $this->assertEquals( [ 'text' => '

{{text}}

' ], - $this->Template->templates(), + $this->Template->getTemplates(), 'newly added template should be included in template list' ); } @@ -89,7 +94,7 @@ public function testInitStringTemplatesArrayForm() [ 'text' => '

{{text}}

' ], - $this->Template->templates(), + $this->Template->getTemplates(), 'Configured templates should be included in template list' ); } @@ -104,7 +109,7 @@ public function testFormatStringTemplate() $templates = [ 'text' => '

{{text}}

', ]; - $this->Template->templates($templates); + $this->Template->setTemplates($templates); $result = $this->Template->formatTemplate('text', [ 'text' => 'CakePHP' ]); @@ -124,7 +129,7 @@ public function testGetTemplater() $templates = [ 'text' => '

{{text}}

', ]; - $this->Template->templates($templates); + $this->Template->setTemplates($templates); $result = $this->Template->templater(); $this->assertInstanceOf('Cake\View\StringTemplate', $result); } diff --git a/tests/TestCase/View/ViewBuilderTest.php b/tests/TestCase/View/ViewBuilderTest.php index ddf9b631ed3..f1f91f0f275 100644 --- a/tests/TestCase/View/ViewBuilderTest.php +++ b/tests/TestCase/View/ViewBuilderTest.php @@ -114,15 +114,15 @@ public function testBuildComplete() $events = $this->getMockBuilder('Cake\Event\EventManager')->getMock(); $builder = new ViewBuilder(); - $builder->name('Articles') - ->className('Ajax') - ->template('edit') - ->layout('default') - ->templatePath('Articles/') - ->helpers(['Form', 'Html']) - ->layoutPath('Admin/') - ->theme('TestTheme') - ->plugin('TestPlugin'); + $builder->setName('Articles') + ->setClassName('Ajax') + ->setTemplate('edit') + ->setLayout('default') + ->setTemplatePath('Articles/') + ->setHelpers(['Form', 'Html']) + ->setLayoutPath('Admin/') + ->setTheme('TestTheme') + ->setPlugin('TestPlugin'); $view = $builder->build( ['one' => 'value'], $request, @@ -180,7 +180,7 @@ public function testBuildAppViewPresent() public function testBuildMissingViewClass() { $builder = new ViewBuilder(); - $builder->className('Foo'); + $builder->setClassName('Foo'); $builder->build(); } @@ -194,10 +194,10 @@ public function testJsonSerialize() $builder = new ViewBuilder(); $builder - ->template('default') - ->layout('test') - ->helpers(['Html']) - ->className('JsonView'); + ->setTemplate('default') + ->setLayout('test') + ->setHelpers(['Html']) + ->setClassName('JsonView'); $result = json_decode(json_encode($builder), true); @@ -223,19 +223,19 @@ public function testCreateFromArray() $builder = new ViewBuilder(); $builder - ->template('default') - ->layout('test') - ->helpers(['Html']) - ->className('JsonView'); + ->setTemplate('default') + ->setLayout('test') + ->setHelpers(['Html']) + ->setClassName('JsonView'); $result = json_encode($builder); $builder = new ViewBuilder(); $builder->createFromArray(json_decode($result, true)); - $this->assertEquals('default', $builder->template()); - $this->assertEquals('test', $builder->layout()); - $this->assertEquals(['Html'], $builder->helpers()); - $this->assertEquals('JsonView', $builder->className()); + $this->assertEquals('default', $builder->getTemplate()); + $this->assertEquals('test', $builder->getLayout()); + $this->assertEquals(['Html'], $builder->getHelpers()); + $this->assertEquals('JsonView', $builder->getClassName()); } } diff --git a/tests/TestCase/View/ViewTest.php b/tests/TestCase/View/ViewTest.php index 9b900b1ce4f..a8df1d5e339 100644 --- a/tests/TestCase/View/ViewTest.php +++ b/tests/TestCase/View/ViewTest.php @@ -279,6 +279,16 @@ class ViewTest extends TestCase */ public $fixtures = ['core.posts', 'core.users']; + /** + * @var \Cake\View\View + */ + public $View; + + /** + * @var ViewPostsController + */ + public $PostsController; + /** * setUp method * diff --git a/tests/TestCase/View/ViewVarsTraitTest.php b/tests/TestCase/View/ViewVarsTraitTest.php index 3580ae35a58..c0586f24604 100644 --- a/tests/TestCase/View/ViewVarsTraitTest.php +++ b/tests/TestCase/View/ViewVarsTraitTest.php @@ -22,6 +22,11 @@ class ViewVarsTraitTest extends TestCase { + /** + * @var \Cake\Controller\Controller; + */ + public $subject; + /** * setup * @@ -79,7 +84,7 @@ public function testSetChained() * * @return void */ - public function testSetTwoParamCombind() + public function testSetTwoParamCombined() { $keys = ['one', 'key']; $vals = ['two', 'val']; @@ -183,7 +188,7 @@ public function testViewOptionsGetsToBuilder() { $this->subject->passedArgs = 'test'; $this->subject->createView(); - $result = $this->subject->viewbuilder()->options(); + $result = $this->subject->viewBuilder()->getOptions(); $this->assertEquals(['passedArgs' => 'test'], $result); } @@ -196,7 +201,7 @@ public function testCreateViewViewClass() { $this->subject->viewClass = 'Json'; $view = $this->subject->createView(); - $this->assertInstanceof('Cake\View\JsonView', $view); + $this->assertInstanceOf('Cake\View\JsonView', $view); } /** @@ -206,10 +211,10 @@ public function testCreateViewViewClass() */ public function testCreateViewViewBuilder() { - $this->subject->viewBuilder()->className('Xml'); + $this->subject->viewBuilder()->setClassName('Xml'); $this->subject->viewClass = 'Json'; $view = $this->subject->createView(); - $this->assertInstanceof('Cake\View\XmlView', $view); + $this->assertInstanceOf('Cake\View\XmlView', $view); } /** @@ -219,10 +224,10 @@ public function testCreateViewViewBuilder() */ public function testCreateViewParameter() { - $this->subject->viewBuilder()->className('View'); + $this->subject->viewBuilder()->setClassName('View'); $this->subject->viewClass = 'Json'; $view = $this->subject->createView('Xml'); - $this->assertInstanceof('Cake\View\XmlView', $view); + $this->assertInstanceOf('Cake\View\XmlView', $view); } /**