Skip to content

Commit

Permalink
Remove deprecated method usage in tests. Make typehinting possible wh…
Browse files Browse the repository at this point in the history
…ich reveals coding errors.
  • Loading branch information
dereuromark committed Dec 22, 2016
1 parent 256b2e0 commit 9df5f57
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 55 deletions.
7 changes: 6 additions & 1 deletion tests/TestCase/View/HelperRegistryTest.php
Expand Up @@ -43,6 +43,11 @@ class HelperRegistryTest extends TestCase
*/
public $Helpers;

/**
* @var \Cake\Event\EventManager
*/
public $Events;

/**
* setUp
*
Expand Down Expand Up @@ -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'));
Expand Down
22 changes: 6 additions & 16 deletions tests/TestCase/View/HelperTest.php
Expand Up @@ -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);
}
}

/**
Expand All @@ -65,6 +52,11 @@ public function parseAttributes($options, $exclude = null, $insertBefore = ' ',
class HelperTest extends TestCase
{

/**
* @var \Cake\View\View
*/
public $View;

/**
* setUp method
*
Expand All @@ -76,8 +68,6 @@ public function setUp()

Router::reload();
$this->View = new View();
$this->Helper = new Helper($this->View);
$this->Helper->request = new Request();
}

/**
Expand All @@ -91,7 +81,7 @@ public function tearDown()
Configure::delete('Asset');

Plugin::unload();
unset($this->Helper, $this->View);
unset($this->View);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase/View/JsonViewTest.php
Expand Up @@ -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);

Expand All @@ -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();

Expand All @@ -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);

Expand Down Expand Up @@ -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');
Expand Down
15 changes: 10 additions & 5 deletions tests/TestCase/View/StringTemplateTraitTest.php
Expand Up @@ -41,6 +41,11 @@ class TestStringTemplate
class StringTemplateTraitTest extends TestCase
{

/**
* @var TestStringTemplate
*/
public $Template;

/**
* setUp method
*
Expand All @@ -62,13 +67,13 @@ public function testInitStringTemplates()
$templates = [
'text' => '<p>{{text}}</p>',
];
$this->Template->templates($templates);
$this->Template->setTemplates($templates);

$this->assertEquals(
[
'text' => '<p>{{text}}</p>'
],
$this->Template->templates(),
$this->Template->getTemplates(),
'newly added template should be included in template list'
);
}
Expand All @@ -89,7 +94,7 @@ public function testInitStringTemplatesArrayForm()
[
'text' => '<p>{{text}}</p>'
],
$this->Template->templates(),
$this->Template->getTemplates(),
'Configured templates should be included in template list'
);
}
Expand All @@ -104,7 +109,7 @@ public function testFormatStringTemplate()
$templates = [
'text' => '<p>{{text}}</p>',
];
$this->Template->templates($templates);
$this->Template->setTemplates($templates);
$result = $this->Template->formatTemplate('text', [
'text' => 'CakePHP'
]);
Expand All @@ -124,7 +129,7 @@ public function testGetTemplater()
$templates = [
'text' => '<p>{{text}}</p>',
];
$this->Template->templates($templates);
$this->Template->setTemplates($templates);
$result = $this->Template->templater();
$this->assertInstanceOf('Cake\View\StringTemplate', $result);
}
Expand Down
44 changes: 22 additions & 22 deletions tests/TestCase/View/ViewBuilderTest.php
Expand Up @@ -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,
Expand Down Expand Up @@ -180,7 +180,7 @@ public function testBuildAppViewPresent()
public function testBuildMissingViewClass()
{
$builder = new ViewBuilder();
$builder->className('Foo');
$builder->setClassName('Foo');
$builder->build();
}

Expand All @@ -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);

Expand All @@ -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());
}
}
10 changes: 10 additions & 0 deletions tests/TestCase/View/ViewTest.php
Expand Up @@ -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
*
Expand Down
19 changes: 12 additions & 7 deletions tests/TestCase/View/ViewVarsTraitTest.php
Expand Up @@ -22,6 +22,11 @@
class ViewVarsTraitTest extends TestCase
{

/**
* @var \Cake\Controller\Controller;
*/
public $subject;

/**
* setup
*
Expand Down Expand Up @@ -79,7 +84,7 @@ public function testSetChained()
*
* @return void
*/
public function testSetTwoParamCombind()
public function testSetTwoParamCombined()
{
$keys = ['one', 'key'];
$vals = ['two', 'val'];
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 9df5f57

Please sign in to comment.