Permalink
Browse files

[#2286] Test cleanup

- Used data provider instead of foreach loop in test case
  • Loading branch information...
1 parent 1b15784 commit 67bc76fa8f7b7829d968d514948c9cdc4c0b5f34 @weierophinney weierophinney committed Sep 10, 2012
Showing with 31 additions and 29 deletions.
  1. +31 −29 tests/ZendTest/Mvc/View/RouteNotFoundStrategyTest.php
@@ -31,41 +31,43 @@ public function setUp()
$this->strategy = new RouteNotFoundStrategy();
}
- public function testMessageParamsInViewModel()
+ public function notFoundResponseProvider()
+ {
+ return array(
+ array('bar', 'assertEquals'),
+ array(null, 'assertTrue'),
+ array(new ViewModel(array('message' => 'bar')), 'assertEquals'),
+ array(new ViewModel(), 'assertTrue'),
+ );
+ }
+
+ /**
+ * @dataProvider notFoundResponseProvider
+ */
+ public function testLeavesReturnedMessageIntact($result, $assertion)
{
$response = new Response();
$event = new MvcEvent();
- $event->setResponse($response);
$response->setStatusCode(404);
+ $event->setResponse($response);
- $event->setResult(null);
+ $event->setResult($result);
+ $this->strategy->prepareNotFoundViewModel($event);
- $testCase = array(
- 'assertEquals' => array (
- 'bar',
- new ViewModel(array('message' => 'bar')),
- ),
- 'assertTrue' => array (
- null,
- new ViewModel(),
- )
- );
- foreach ($testCase as $type => $results) {
- foreach ($results as $resultEvent) {
- $event->setResult($resultEvent);
- $this->strategy->prepareNotFoundViewModel($event);
- $viewModel = $event->getResult();
- $this->assertInstanceOf('Zend\View\Model\ModelInterface', $viewModel);
- $variables = $viewModel->getVariables();
- switch ($type) {
- case 'assertEquals':
- $this->assertEquals('bar', $variables['message']);
- break;
- case 'assertTrue':
- $this->assertTrue(isset($variables['message']));
- break;
- }
- }
+ $viewModel = $event->getResult();
+ $this->assertInstanceOf('Zend\View\Model\ModelInterface', $viewModel);
+
+ $variables = $viewModel->getVariables();
+ switch ($assertion) {
+ case 'assertEquals':
+ // Testing if we returned a message in the result
+ $this->assertEquals('bar', $variables['message']);
+ break;
+ case 'assertTrue':
+ // Testing if no message was returned in the result; in that
+ // case, default message is used from strategy
+ $this->assertTrue(isset($variables['message']));
+ break;
}
}

0 comments on commit 67bc76f

Please sign in to comment.