Issues

ZF-11472: "zf create action" can cause malformed PHP when other action methods already exist

Issue Type: Bug Created: 2011-06-13T09:44:54.000+0000 Last Updated: 2011-10-17T15:38:43.000+0000 Status: Closed Fix version(s): Reporter: Włodzimierz Gajda (gajdaw) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_Tool

  • zf-caretaker-adamlundrigan

Related issues: - ZF-9018

Attachments:

Description

When controller contains some non-empty methods, e.g.:

<pre class="highlight">
public function editAction()
{
    if ($obj === null) {
        ...
    } else {
        ...
    }
}

then command:

zf create action lorem

eats closing braces. editAction() method will be converted to

<pre class="highlight">
public function editAction()
{
    if ($obj === null) {
        ...
    } else {
        ...
    }

(without ending brace).

This is annoying if you have large number of action methods.

Comments

Posted by Kim Blomqvist (kblomqvist) on 2011-06-13T10:01:56.000+0000

Add code tags

Posted by Włodzimierz Gajda (gajdaw) on 2011-06-13T16:47:53.000+0000

Thanks.

Posted by Adam Lundrigan (adamlundrigan) on 2011-06-14T00:57:25.000+0000

Reproduced successfully against trunk 1. zf create controller Foo 2. zf create action testOne Foo 3. Edit FooController, change testOneAction to:

<pre class="highlight">
public function testOneAction()
{
    if ( true )
    {
        echo "True!";
    }
    else
    {
        echo "False!";
    }
}
  1. zf create action testTwo Foo

The controller will now look like this:

<pre class="highlight">
public function testOneAction()
{
    if ( true )
    {
        echo "True!";
    }
    else
    {
        echo "False!";

}

public function testTwoAction()
{
    // action body
}

Posted by Adam Lundrigan (adamlundrigan) on 2011-10-17T14:55:00.000+0000

Reproducing test case:

<pre class="highlight">
Index: tests/Zend/CodeGenerator/Php/FileTest.php
===================================================================
--- tests/Zend/CodeGenerator/Php/FileTest.php   (revision 24511)
+++ tests/Zend/CodeGenerator/Php/FileTest.php   (working copy)
@@ -378,4 +378,47 @@

         $this->assertEquals($target, $codeGenFile->generate());
     }
+
+    /**
+     * @group ZF-11472
+     */
+    public function testClassMethodDoesNotGetTruncated()
+    {
+        $codeGenFile = Zend_CodeGenerator_Php_File::fromReflectedFileName(dirname(__FILE__) . "/_files/Zf11472TestController.php");
+        $codeGenFileClasses = $codeGenFile->getClasses();
+        $classCodeGen = array_shift($codeGenFileClasses);
+        $classCodeGen->setMethod(array('name' => 'testAction', 'body' => '        // action body here'));
+
+        $expected = <<assertEquals($expected,$classCodeGen->generate());
+    }
 }
\ No newline at end of file
Index: tests/Zend/CodeGenerator/Php/_files/Zf11472TestController.php
===================================================================
--- tests/Zend/CodeGenerator/Php/_files/Zf11472TestController.php       (revision 0)
+++ tests/Zend/CodeGenerator/Php/_files/Zf11472TestController.php       (revision 0)
@@ -0,0 +1,23 @@
+<?php
+
+class IndexController extends Zend_Controller_Action
+{
+
+    public function init()
+    {
+        /* Initialize action controller here */
+    }
+
+    public function indexAction()
+    {
+        if ( true )
+        {
+            echo "True";
+        }
+        else
+        {
+            echo "False";
+        }
+    }
+}
+

Property changes on: tests/Zend/CodeGenerator/Php/_files/Zf11472TestController.php
___________________________________________________________________
Added: svn:keywords
   + Id

Result:

<pre class="highlight">
++ phpunit --verbose --group ZF-11472 AllTests
PHPUnit 3.5.14 by Sebastian Bergmann.

F

Time: 8 seconds, Memory: 424.75Mb

There was 1 failure:

1) Zend_CodeGenerator_Php_FileTest::testClassMethodDoesNotGetTruncated
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
             echo "False";
-        }
+
     }

     public function testAction()
     {
         // action body here
     }


 }

/usr/local/apache2/htdocs/lib/zfdev/trunk/tests/Zend/CodeGenerator/Php/FileTest.php:422

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

Working on a fix now.

Posted by Adam Lundrigan (adamlundrigan) on 2011-10-17T15:37:10.000+0000

This is actually an issue with Zend_Reflection_Method which was reported in ZF-9018

Posted by Adam Lundrigan (adamlundrigan) on 2011-10-17T15:38:43.000+0000

Duplicate of ZF-9501

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