generateConstructor() публичный Метод

Generate a constructor code snippet for the type and class name
public generateConstructor ( string $type, string $fullClassName ) : array
$type string The Type of object you are generating tests for eg. controller
$fullClassName string The full classname of the class the test is being generated for.
Результат array Constructor snippets for the thing you are building.
Пример #1
0
 /**
  * test Constructor generation ensure that constructClasses is called for controllers
  *
  * @return void
  */
 public function testGenerateConstructor()
 {
     $result = $this->Task->generateConstructor('controller', 'PostsController');
     $expected = ['', '', ''];
     $this->assertEquals($expected, $result);
     $result = $this->Task->generateConstructor('table', 'App\\Model\\Table\\PostsTable');
     $expected = ["\$config = TableRegistry::exists('Posts') ? [] : ['className' => 'App\\Model\\Table\\PostsTable'];", "TableRegistry::get('Posts', \$config);", ''];
     $this->assertEquals($expected, $result);
     $result = $this->Task->generateConstructor('helper', 'FormHelper');
     $expected = ["\$view = new View();", "new FormHelper(\$view);", ''];
     $this->assertEquals($expected, $result);
     $result = $this->Task->generateConstructor('entity', 'TestBake\\Model\\Entity\\Article');
     $expected = ["", "new Article();", ''];
     $this->assertEquals($expected, $result);
     $result = $this->Task->generateConstructor('shell_helper', 'TestBake\\Shell\\Helper\\ExampleHelper');
     $expected = ["\$this->stub = new ConsoleOutput();\n        \$this->io = new ConsoleIo(\$this->stub);", "new ExampleHelper(\$this->io);", ''];
     $this->assertEquals($expected, $result);
     $result = $this->Task->generateConstructor('form', 'TestBake\\Form\\ExampleForm');
     $expected = ['', "new ExampleForm();", ''];
     $this->assertEquals($expected, $result);
 }