1111
1212class GenerateCest extends Base
1313{
14- protected $ template = "<?php \n%s %sCest \n{ \n // the class name you want to test \n public %s = ''; \n\n%s \n} \n" ;
15- protected $ methodTemplate = " // sample test \n public function %s( \\%s %s) { \n \n } " ;
14+ protected $ template = <<<EOF
15+ <?php
16+ %suse Codeception\Util\Stub;
17+
18+ %s %sCest
19+ {
20+ protected $%s = '%s';
21+
22+ protected function _before()
23+ {
24+ }
25+
26+ protected function _after()
27+ {
28+ }
29+
30+ // tests
31+ %s
32+
33+ }
34+ EOF ;
1635
17- const SUFFIX = ' Cest ' ;
36+ protected $ methodTemplate = " public function %s( \\ %s %s) { \n \n } " ;
1837
1938 protected function configure ()
2039 {
2140 $ this ->setDefinition (array (
2241
2342 new \Symfony \Component \Console \Input \InputArgument ('suite ' , InputArgument::REQUIRED , 'suite where tests will be put ' ),
24- new \Symfony \Component \Console \Input \InputArgument ('name ' , InputArgument::REQUIRED , 'test name ' ),
43+ new \Symfony \Component \Console \Input \InputArgument ('class ' , InputArgument::REQUIRED , 'test name ' ),
2544 ));
2645 parent ::configure ();
2746 }
@@ -33,43 +52,28 @@ public function getDescription() {
3352 public function execute (InputInterface $ input , OutputInterface $ output )
3453 {
3554 $ suite = $ input ->getArgument ('suite ' );
36- $ testName = $ input ->getArgument ('name ' );
55+ $ class = $ input ->getArgument ('class ' );
3756
3857 $ config = \Codeception \Configuration::config ();
3958 $ suiteconf = \Codeception \Configuration::suiteSettings ($ suite , $ config );
4059
4160 $ guy = $ suiteconf ['class_name ' ];
4261
43- $ classname = $ this ->getClassName ($ testName );
62+ $ classname = $ this ->getClassName ($ class );
63+ $ path = $ this ->buildPath ($ suiteconf ['path ' ], $ class );
64+ $ ns = $ this ->getNamespaceString ($ class );
4465
45- $ path = $ this ->buildPath ($ suiteconf ['path ' ], $ testName );
46-
47- $ file = pathinfo ($ testName );
48- $ filename = $ file ['filename ' ];
49- // filename already ends with Cest
50- if (strpos ($ filename , $ this ::SUFFIX , strlen ($ filename ) - strlen ($ this ::SUFFIX )) === false ) {
51- $ filename .= $ this ::SUFFIX ;
52- }
53- $ filename .= '. ' . empty ($ file ['extension ' ]) ? '.php ' : $ file ['extension ' ];
54-
55- $ filename = $ path .DIRECTORY_SEPARATOR . $ filename ;
66+ $ filename = $ this ->completeSuffix ($ classname , 'Cest ' );
67+ $ filename = $ path .DIRECTORY_SEPARATOR .$ filename ;
5668
5769 if (file_exists ($ filename )) {
5870 $ output ->writeln ("<error>Test $ filename already exists</error> " );
5971 exit ;
6072 }
6173
62- // $methods = $reflected->getMethods(\ReflectionMethod::IS_PUBLIC);
63- // foreach ($methods as $method) {
64- // if ($method->getDeclaringClass()->name != $class) continue;
65- // if ($method->isConstructor() or $method->isDestructor()) continue;
66- //
67- // $tests[] = sprintf($this->methodTemplate, $classname, $method->name,$method->name, $guy, '$I');
68- // }
69-
7074 $ tests = sprintf ($ this ->methodTemplate , "shouldBe " , $ guy , '$I ' );
7175
72- file_put_contents ($ filename , sprintf ($ this ->template , 'class ' , $ classname ,' $ class ' , $ tests ));
76+ file_put_contents ($ filename , sprintf ($ this ->template , $ ns , 'class ' , $ classname , ' class ', $ class , $ tests ));
7377
7478 $ output ->writeln ("<info>Cest was created in $ filename</info> " );
7579
0 commit comments