Issues

ZF-11275: PHPUnit_Framework_AssertionFailedError : Failed asserting last action used <"get-Resume"> was "getResume"

Issue Type: Bug Created: 2011-04-08T18:24:08.000+0000 Last Updated: 2011-05-03T19:10:03.000+0000 Status: Resolved Fix version(s): - 1.11.6 (05/May/11)

Reporter: Alexandr Iline (mecommayou) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_Application

  • Zend_Test_PHPUnit

Related issues: Attachments: - ZF-11275.patch

Description

Some problems with camelCased action in default tests.

STR: 1. Create new app using Zend_Tool. 2. Create some camelCased action (using Zend_Tool) like "getResume". 3. Run generated tests.

Comments

Posted by Adam Lundrigan (adamlundrigan) on 2011-04-29T17:42:13.000+0000

I've reproduced the issue: (Zend_Tool output clipped for brevity)

<pre class="highlight">
[webadmin@spiral ZF-11275]$ zf create project app app
[webadmin@spiral ZF-11275]$ cd app
[webadmin@spiral app]$ zf create controller test
[webadmin@spiral app]$ zf create action myCamelCaseTest Test
[webadmin@spiral app]$ cd tests
[webadmin@spiral tests]$ phpunit
PHPUnit 3.5.13 by Sebastian Bergmann.

.F.

Time: 0 seconds, Memory: 12.00Mb

There was 1 failure:

1) TestControllerTest::testMyCamelCaseTestAction
Failed asserting last action used <"my-Camel-Case-Test"> was "myCamelCaseTest"

/usr/local/apache2/htdocs/lib/ZendFramework-1.11.4/library/Zend/Test/PHPUnit/ControllerTestCase.php:1041
/usr/local/apache2/htdocs/test/zf/ZF-11275/app/tests/application/controllers/TestControllerTest.php:37

FAILURES!
Tests: 3, Assertions: 11, Failures: 1.

Posted by Adam Lundrigan (adamlundrigan) on 2011-04-29T17:53:55.000+0000

The issue is that the test is generated using the controller action function name format (ie: testCamelCase) instead of the url format (ie: test-camel-case). This can be fixed by changing the auto-generated test stub like so:

<pre class="highlight">
31,32c31
<         $urlParams = $this->urlizeOptions($params);
<         $url = $this->url($urlParams);
---
>         $url = $this->url($this->urlizeOptions($params));
36,38c35,37
<         $this->assertModule($urlParams['module']);
<         $this->assertController($urlParams['controller']);
<         $this->assertAction($urlParams['action']);
---
>         $this->assertModule($params['module']);
>         $this->assertController($params['controller']);
>         $this->assertAction($params['action']);

The unit test passes after I make this change.

Posted by Adam Lundrigan (adamlundrigan) on 2011-04-29T18:10:51.000+0000

I've updated Zend_Tool_Project_Context_Zf_TestApplicationActionMethod to reflect the "fixed" action test format and attached a patch against trunk. Here's what happens when I follow the reproduction steps after applying the patch:

<pre class="highlight">
[webadmin@spiral ZF-11275]$ zf.sh show version
Zend Framework Version: 1.11.0dev

[webadmin@spiral ZF-11275]$ zf.sh show version
[webadmin@spiral ZF-11275]$ mkdir app2 ; zf.sh create project app2 app2
Creating project at ZF-11275/app2
Note: This command created a web project, for more information setting up your VHOST, please see docs/README

[webadmin@spiral ZF-11275]$ cd app2
[webadmin@spiral app2]$ zf.sh create controller CamelCaseTest
Creating a controller at ZF-11275/app2/application/controllers/CamelCaseTestController.php
Creating an index action method in controller CamelCaseTest
Creating a view script for the index action method at ZF-11275/app2/application/views/scripts/camel-case-test/index.phtml
Creating a controller test file at ZF-11275/app2/tests/application/controllers/CamelCaseTestControllerTest.php
Updating project profile 'ZF-11275/app2/.zfproject.xml'

[webadmin@spiral app2]$ zf.sh create action camelCaseTest CamelCaseTest
Creating an action named camelCaseTest inside controller at ZF-11275/app2/application/controllers/CamelCaseTestController.php
Creating an action test in ZF-11275/app2/tests/application/controllers/CamelCaseTestControllerTest.php
Updating project profile 'ZF-11275/app2/.zfproject.xml'
Creating a view script for the camelCaseTest action method at ZF-11275/app2/application/views/scripts/camel-case-test/camel-case-test.phtml
Updating project profile 'ZF-11275/app2/.zfproject.xml'

[webadmin@spiral app2]$ less ZF-11275/app2/tests/application/controllers/CamelCaseTestControllerTest.php
[webadmin@spiral app2]$ cd tests
[webadmin@spiral tests]$ phpunit
PHPUnit 3.5.13 by Sebastian Bergmann.

...

Time: 0 seconds, Memory: 12.00Mb

OK (3 tests, 12 assertions)

Comments?

Posted by Adam Lundrigan (adamlundrigan) on 2011-05-02T22:32:39.000+0000

Fixed in trunk r23943

Posted by Ralph Schindler (ralph) on 2011-05-03T19:10:03.000+0000

Fixed in 1.11 at r23982

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts