Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[generate:controller] Error: Does not have a method 'getTestPath' #3998

Closed
reganking opened this issue Feb 7, 2019 · 1 comment
Closed
Milestone

Comments

@reganking
Copy link
Contributor

Problem/Motivation

  • generate:controller results in error and creation of controller file at /.

  • Drupal version: 8.6.7.

  • Console version: 1.8.0.

How to reproduce

From docroot:

../vendor/drupal/console/bin/drupal generate:controller  \
--module="unify_event"  \
--class="MyController"  \
--routes='"title":"ControllerMethod", "name":"unify_event.view_events", "method":"view_event", "path":"/events/{name}"'  \
--test
 [ERROR] <em class="placeholder">Warning</em>: call_user_func_array() expects parameter 1 to be a valid callback,       
         class 'SplFileInfo' does not have a method 'getTestPath' in Drupal\Core\Extension\Extension->__call() (line 155 of core/lib/Drupal/Core/Extension/Extension.php). Drupal\Core\Extension\Extension->__call('getTestPath', Array) (Line: 57)        
         Drupal\Console\Generator\ControllerGenerator->generate(Array) (Line: 156)                                   
         Drupal\Console\Command\Generate\ControllerCommand->execute(Object, Object) (Line: 255)                      
         Symfony\Component\Console\Command\Command->run(Object, Object) (Line: 971)                                  
         Symfony\Component\Console\Application->doRunCommand(Object, Object, Object) (Line: 248)                     
         Symfony\Component\Console\Application->doRun(Object, Object) (Line: 185)                                    
         Drupal\Console\Core\Application->doRun(Object, Object) (Line: 64)                                           
         Drupal\Console\Application->doRun(Object, Object) (Line: 148)                                               
         Symfony\Component\Console\Application->run() (Line: 89)                                                     
         require('[...]/vendor/drupal/console/bin/drupal.php') (Line: 4) 

Notes:

  • Error occurs regardless whether module is enabled or disabled.
  • File MyControllerTest.php is created at / due to missing path expected from getTestPath().
  • drupal/console/src/extension/Manager->getTestPath() is never called. drupal/console/src/extension/Manager->getModule() <- createExtension() is called.

In ControllerGenerator.php (erroneously calls \Drupal\Console\Extension\Extension->getTestPath()):

...
        if ($test) {
            $this->renderFile(
                'module/Tests/Controller/controller.php.twig',
                **$moduleInstance->getTestPath('Controller')** . '/' . $class . 'Test.php',
                $parameters
            );
        }
...

The `Manager->getTestPath()' takes the `testType` argument: 
public function getTestPath($testType, $fullPath = false)
{
    return $this->getPath($fullPath) . '/Tests/' . $testType;
}
Aside: Function `$this->getPath()` is not in the `Manager` class, but the class is in the `Extension` namespace.

A `\Drupal\Console\Extension\Extension->getTest**s**Path()` function exists, but doesn't have a `testType` argument.

### Temporary Solution
`sudo mv /MyControllerTest.php docroot/modules/unify_event/tests/Controller/`

### Solution
Move the `Manager->getTestPath()` `testType' argument over to `Extension->getTestsPath()` and correct `getTestPath` to `getTestsPath` in `ControllerGenerator`.

Note: This needs testing.
reganking added a commit to reganking/drupal-console that referenced this issue Feb 7, 2019
@LOBsTerr LOBsTerr added this to the 1.9.0 milestone Feb 12, 2019
@LOBsTerr
Copy link
Member

@reganking Thank you for your contribution. It has been merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants