RoboFile.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910
  1. <?php
  2. require_once __DIR__.'/vendor/autoload.php';
  3. use Symfony\Component\Finder\Finder;
  4. use \Robo\Task\Development\GenerateMarkdownDoc as Doc;
  5. class RoboFile extends \Robo\Tasks
  6. {
  7. const STABLE_BRANCH = '2.2';
  8. const REPO_BLOB_URL = 'https://github.com/Codeception/Codeception/blob';
  9. public function release()
  10. {
  11. $this->say("CODECEPTION RELEASE: ".\Codeception\Codecept::VERSION);
  12. $this->update();
  13. $this->buildDocs();
  14. $this->publishDocs();
  15. $this->buildPhar54();
  16. $this->buildPhar();
  17. $this->revertComposerJsonChanges();
  18. $this->publishPhar();
  19. $this->publishGit();
  20. $this->publishBase(null, \Codeception\Codecept::VERSION);
  21. $this->versionBump();
  22. }
  23. public function versionBump($version = '')
  24. {
  25. if (!$version) {
  26. $versionParts = explode('.', \Codeception\Codecept::VERSION);
  27. $versionParts[count($versionParts)-1]++;
  28. $version = implode('.', $versionParts);
  29. }
  30. $this->say("Bumping version to $version");
  31. $this->taskReplaceInFile('src/Codeception/Codecept.php')
  32. ->from(\Codeception\Codecept::VERSION)
  33. ->to($version)
  34. ->run();
  35. }
  36. public function update()
  37. {
  38. $this->clean();
  39. $this->taskComposerUpdate()->dir('tests/data/claypit')->run();
  40. $this->taskComposerUpdate()->run();
  41. }
  42. public function changed($change)
  43. {
  44. $this->taskChangelog()
  45. ->version(\Codeception\Codecept::VERSION)
  46. ->change($change)
  47. ->run();
  48. }
  49. protected function server()
  50. {
  51. $this->taskServer(8000)
  52. ->background()
  53. ->dir('tests/data/app')
  54. ->run();
  55. }
  56. public function testPhpbrowser($args = '', $opt = ['test|t' => null])
  57. {
  58. $test = $opt['test'] ? ':'.$opt['test'] : '';
  59. $this->server();
  60. $this->taskCodecept('./codecept')
  61. ->args($args)
  62. ->test('tests/unit/Codeception/Module/PhpBrowserTest.php'.$test)
  63. ->run();
  64. }
  65. public function testRestBrowser($args = '', $opt = ['test|t' => null])
  66. {
  67. $test = $opt['test'] ? ':'.$opt['test'] : '';
  68. $this->taskServer(8010)
  69. ->background()
  70. ->dir('tests/data')
  71. ->run();
  72. $this->taskCodecept('./codecept')
  73. ->test('tests/unit/Codeception/Module/PhpBrowserRestTest.php'.$test)
  74. ->args($args)
  75. ->run();
  76. }
  77. public function testCoverage()
  78. {
  79. $this->server();
  80. $this->taskSymfonyCommand(new \Codeception\Command\Run('run'))
  81. ->arg('suite', 'coverage')
  82. ->run();
  83. }
  84. public function testWebdriver($args = '', $opt = ['test|t' => null])
  85. {
  86. $test = $opt['test'] ? ':'.$opt['test'] : '';
  87. $container = $this->taskDockerRun('davert/selenium-env')
  88. ->detached()
  89. ->publish(4444, 4444)
  90. ->env('APP_PORT', 8000)
  91. ->run();
  92. $this->taskServer(8000)
  93. ->dir('tests/data/app')
  94. ->background()
  95. ->host('0.0.0.0')
  96. ->run();
  97. sleep(3); // wait for selenium to launch
  98. $this->taskCodecept('./codecept')
  99. ->test('tests/web/WebDriverTest.php'.$test)
  100. ->args($args)
  101. ->run();
  102. $this->taskDockerStop($container)->run();
  103. }
  104. public function testLaunchServer($pathToSelenium = '~/selenium-server.jar ')
  105. {
  106. $this->taskExec('java -jar '.$pathToSelenium)
  107. ->background()
  108. ->run();
  109. $this->taskServer(8010)
  110. ->background()
  111. ->dir('tests/data/rest')
  112. ->run();
  113. $this->taskServer(8000)
  114. ->dir('tests/data/app')
  115. ->run();
  116. }
  117. public function testCli()
  118. {
  119. $this->taskSymfonyCommand(new \Codeception\Command\Run('run'))
  120. ->arg('suite', 'cli')
  121. ->run();
  122. $this->taskSymfonyCommand(new \Codeception\Command\Run('run'))
  123. ->arg('suite', 'tests/unit/Codeception/Command')
  124. ->run();
  125. }
  126. private function installDependenciesForPhp54()
  127. {
  128. $this->taskReplaceInFile('composer.json')
  129. ->regex('/"platform": \{.*?\}/')
  130. ->to('"platform": {"php": "5.4.0"}')
  131. ->run();
  132. $this->taskComposerUpdate()->run();
  133. }
  134. private function installDependenciesForPhp56()
  135. {
  136. $this->taskReplaceInFile('composer.json')
  137. ->regex('/"platform": \{.*?\}/')
  138. ->to('"platform": {"php": "5.6.0"}')
  139. ->run();
  140. $this->taskComposerUpdate()->run();
  141. }
  142. private function revertComposerJsonChanges()
  143. {
  144. $this->taskReplaceInFile('composer.json')
  145. ->regex('/"platform": \{.*?\}/')
  146. ->to('"platform": {}')
  147. ->run();
  148. }
  149. /**
  150. * @desc creates codecept.phar
  151. * @throws Exception
  152. */
  153. public function buildPhar()
  154. {
  155. $this->packPhar('package/codecept.phar');
  156. }
  157. /**
  158. * @desc creates codecept.phar with Guzzle 5.3 and Symfony 2.8
  159. * @throws Exception
  160. */
  161. public function buildPhar54()
  162. {
  163. if (!file_exists('package/php54')) {
  164. mkdir('package/php54');
  165. }
  166. $this->installDependenciesForPhp54();
  167. $this->packPhar('package/php54/codecept.phar');
  168. $this->installDependenciesForPhp56();
  169. }
  170. private function packPhar($pharFileName)
  171. {
  172. $pharTask = $this->taskPackPhar($pharFileName)
  173. ->compress()
  174. ->stub('package/stub.php');
  175. $finder = Finder::create()
  176. ->ignoreVCS(true)
  177. ->name('*.php')
  178. ->name('*.tpl.dist')
  179. ->name('*.html.dist')
  180. ->in('src');
  181. foreach ($finder as $file) {
  182. $pharTask->addFile('src/'.$file->getRelativePathname(), $file->getRealPath());
  183. }
  184. $finder = Finder::create()
  185. ->ignoreVCS(true)
  186. ->name('*.php')
  187. ->in('ext');
  188. foreach ($finder as $file) {
  189. $pharTask->addFile('ext/'.$file->getRelativePathname(), $file->getRealPath());
  190. }
  191. $finder = Finder::create()->files()
  192. ->ignoreVCS(true)
  193. ->name('*.php')
  194. ->name('*.css')
  195. ->name('*.png')
  196. ->name('*.js')
  197. ->name('*.css')
  198. ->name('*.eot')
  199. ->name('*.svg')
  200. ->name('*.ttf')
  201. ->name('*.wof')
  202. ->name('*.woff')
  203. ->name('*.woff2')
  204. ->name('*.png')
  205. ->name('*.tpl.dist')
  206. ->name('*.html.dist')
  207. ->exclude('videlalvaro')
  208. ->exclude('php-amqplib')
  209. ->exclude('pheanstalk')
  210. ->exclude('phpseclib')
  211. ->exclude('codegyre')
  212. ->exclude('monolog')
  213. ->exclude('phpspec')
  214. ->exclude('squizlabs')
  215. ->exclude('Tests')
  216. ->exclude('tests')
  217. ->exclude('benchmark')
  218. ->exclude('demo')
  219. ->in('vendor');
  220. foreach ($finder as $file) {
  221. $pharTask->addStripped('vendor/'.$file->getRelativePathname(), $file->getRealPath());
  222. }
  223. $pharTask->addFile('autoload.php', 'autoload.php')
  224. ->addFile('codecept', 'package/bin')
  225. ->addFile('shim.php', 'shim.php')
  226. ->run();
  227. $code = $this->taskExec('php ' . $pharFileName)->run()->getExitCode();
  228. if ($code !== 0) {
  229. throw new Exception("There was problem compiling phar");
  230. }
  231. }
  232. /**
  233. * @desc generates modules reference from source files
  234. */
  235. public function buildDocs()
  236. {
  237. $this->say('generating documentation from source files');
  238. $this->buildDocsModules();
  239. $this->buildDocsUtils();
  240. $this->buildDocsCommands();
  241. $this->buildDocsApi();
  242. $this->buildDocsExtensions();
  243. }
  244. public function buildDocsModules()
  245. {
  246. $this->taskCleanDir('docs/modules')->run();
  247. $this->say("Modules");
  248. $modules = Finder::create()->files()->name('*.php')->in(__DIR__ . '/src/Codeception/Module');
  249. foreach ($modules as $module) {
  250. $moduleName = basename(substr($module, 0, -4));
  251. $className = 'Codeception\Module\\' . $moduleName;
  252. $source = "https://github.com/Codeception/Codeception/tree/"
  253. .self::STABLE_BRANCH."/src/Codeception/Module/$moduleName.php";
  254. $this->taskGenDoc('docs/modules/' . $moduleName . '.md')
  255. ->docClass($className)
  256. ->prepend('# '.$moduleName)
  257. ->append('<p>&nbsp;</p><div class="alert alert-warning">Module reference is taken from the source code. <a href="'.$source.'">Help us to improve documentation. Edit module reference</a></div>')
  258. ->processClassSignature(false)
  259. ->processClassDocBlock(function (\ReflectionClass $c, $text) {
  260. return "$text\n\n## Actions";
  261. })->processProperty(false)
  262. ->filterMethods(function (\ReflectionMethod $method) use ($className) {
  263. if ($method->isConstructor() or $method->isDestructor()) {
  264. return false;
  265. }
  266. if (!$method->isPublic()) {
  267. return false;
  268. }
  269. if (strpos($method->name, '_') === 0) {
  270. $doc = $method->getDocComment();
  271. try {
  272. $doc = $doc . $method->getPrototype()->getDocComment();
  273. } catch (\ReflectionException $e) {
  274. }
  275. if (strpos($doc, '@api') === false) {
  276. return false;
  277. }
  278. };
  279. return true;
  280. })->processMethod(function (\ReflectionMethod $method, $text) use ($className, $moduleName) {
  281. $title = "\n### {$method->name}\n";
  282. if (strpos($method->name, '_') === 0) {
  283. $text = str_replace("@api\n", '', $text);
  284. $text = "\n*hidden API method, expected to be used from Helper classes*\n" . $text;
  285. $text = str_replace("{{MODULE_NAME}}", $moduleName, $text);
  286. };
  287. if (!trim($text)) {
  288. return $title . "__not documented__\n";
  289. }
  290. $text = str_replace(
  291. ['@since', '@version'],
  292. [' * `Available since`', ' * `Available since`'],
  293. $text
  294. );
  295. $text = str_replace('@part ', ' * `[Part]` ', $text);
  296. $text = str_replace("@return mixed\n", '', $text);
  297. $text = preg_replace('~@return (.*?)~', ' * `return` $1', $text);
  298. $text = preg_replace("~^@(.*?)([$\s])~", ' * `$1` $2', $text);
  299. return $title . $text;
  300. })->processMethodSignature(false)
  301. ->reorderMethods('ksort')
  302. ->run();
  303. }
  304. }
  305. public function buildDocsUtils()
  306. {
  307. $this->say("Util Classes");
  308. $utils = ['Autoload', 'Fixtures', 'Stub', 'Locator', 'XmlBuilder', 'JsonType', 'HttpCode'];
  309. foreach ($utils as $utilName) {
  310. $className = '\Codeception\Util\\' . $utilName;
  311. $source = self::REPO_BLOB_URL."/".self::STABLE_BRANCH."/src/Codeception/Util/$utilName.php";
  312. $this->documentApiClass('docs/reference/' . $utilName . '.md', $className, $source);
  313. }
  314. }
  315. public function buildDocsApi()
  316. {
  317. $this->say("API Classes");
  318. $apiClasses = ['Codeception\Module'];
  319. foreach ($apiClasses as $apiClass) {
  320. $name = (new ReflectionClass($apiClass))->getShortName();
  321. $this->documentApiClass('docs/reference/' . $name . '.md', $apiClass, true);
  322. }
  323. }
  324. public function buildDocsCommands()
  325. {
  326. $this->say("Commands");
  327. $commands = Finder::create()->files()->name('*.php')->depth(0)->in(__DIR__ . '/src/Codeception/Command');
  328. $commandGenerator = $this->taskGenDoc('docs/reference/Commands.md');
  329. foreach ($commands as $command) {
  330. $commandName = basename(substr($command, 0, -4));
  331. $className = '\Codeception\Command\\' . $commandName;
  332. $commandGenerator->docClass($className);
  333. }
  334. $commandGenerator
  335. ->prepend("# Console Commands\n")
  336. ->processClassSignature(function ($r, $text) {
  337. return "## ".$r->getShortName();
  338. })
  339. ->filterMethods(function (ReflectionMethod $r) {
  340. return false;
  341. })
  342. ->run();
  343. }
  344. public function buildDocsExtensions()
  345. {
  346. $this->say('Extensions');
  347. $extensions = Finder::create()->files()->sortByName()->name('*.php')->in(__DIR__ . '/ext');
  348. $extGenerator= $this->taskGenDoc(__DIR__.'/ext/README.md');
  349. foreach ($extensions as $command) {
  350. $commandName = basename(substr($command, 0, -4));
  351. $className = '\Codeception\Extension\\' . $commandName;
  352. $extGenerator->docClass($className);
  353. }
  354. $extGenerator
  355. ->prepend("# Official Extensions\n")
  356. ->processClassSignature(function ($r, $text) {
  357. return "## ".$r->getName();
  358. })
  359. ->filterMethods(function (ReflectionMethod $r) {
  360. return false;
  361. })
  362. ->filterProperties(function ($r) {
  363. return false;
  364. })
  365. ->run();
  366. }
  367. /**
  368. * @desc publishes generated phar to codeception.com
  369. */
  370. public function publishPhar()
  371. {
  372. $this->cloneSite();
  373. $version = \Codeception\Codecept::VERSION;
  374. if (strpos($version, self::STABLE_BRANCH) === 0) {
  375. $this->say("publishing to release branch");
  376. copy('../codecept.phar', 'codecept.phar');
  377. if (!is_dir('php54')) {
  378. mkdir('php54');
  379. }
  380. copy('../php54/codecept.phar', 'php54/codecept.phar');
  381. $this->taskExec('git add codecept.phar')->run();
  382. $this->taskExec('git add php54/codecept.phar')->run();
  383. }
  384. $this->taskFileSystemStack()
  385. ->mkdir("releases/$version")
  386. ->mkdir("releases/$version/php54")
  387. ->copy('../codecept.phar', "releases/$version/codecept.phar")
  388. ->copy('../php54/codecept.phar', "releases/$version/php54/codecept.phar")
  389. ->run();
  390. $this->taskGitStack()->add('-A')->run();
  391. $sortByVersion = function (\SplFileInfo $a, \SplFileInfo $b) {
  392. return version_compare($a->getBaseName(), $b->getBaseName());
  393. };
  394. $releases = array_reverse(
  395. iterator_to_array(Finder::create()->depth(0)->directories()->sort($sortByVersion)->in('releases'))
  396. );
  397. $branch = null;
  398. $releaseFile = $this->taskWriteToFile('builds.markdown')
  399. ->line('---')
  400. ->line('layout: page')
  401. ->line('title: Codeception Builds')
  402. ->line('---')
  403. ->line('');
  404. foreach ($releases as $release) {
  405. $releaseName = $release->getBasename();
  406. $downloadUrl = "http://codeception.com/releases/$releaseName/codecept.phar";
  407. list($major, $minor) = explode('.', $releaseName);
  408. if ("$major.$minor" != $branch) {
  409. $branch = "$major.$minor";
  410. $releaseFile->line("\n## $branch");
  411. if ($major < 2) {
  412. $releaseFile->line("*Requires: PHP 5.3 and higher + CURL*\n");
  413. } else {
  414. $releaseFile->line("*Requires: PHP 5.4 and higher + CURL*\n");
  415. }
  416. $releaseFile->line("* **[Download Latest $branch Release]($downloadUrl)**");
  417. }
  418. $versionLine = "* [$releaseName]($downloadUrl)";
  419. if (file_exists("releases/$releaseName/php54/codecept.phar")) {
  420. $downloadUrl = "http://codeception.com/releases/$releaseName/php54/codecept.phar";
  421. $versionLine .= ", [for PHP 5.4 or 5.5]($downloadUrl)";
  422. }
  423. $releaseFile->line($versionLine);
  424. }
  425. $releaseFile->run();
  426. $this->publishSite();
  427. }
  428. /**
  429. * Updates docs on codeception.com
  430. *
  431. */
  432. public function publishDocs()
  433. {
  434. if (strpos(\Codeception\Codecept::VERSION, self::STABLE_BRANCH) !== 0) {
  435. $this->say("The ".\Codeception\Codecept::VERSION." is not in release branch. Site is not build");
  436. return;
  437. }
  438. $this->say('building site...');
  439. $this->cloneSite();
  440. $this->taskCleanDir('docs')
  441. ->run();
  442. $this->taskFileSystemStack()
  443. ->mkdir('docs/reference')
  444. ->mkdir('docs/modules')
  445. ->run();
  446. chdir('../..');
  447. $this->taskWriteToFile('package/site/changelog.markdown')
  448. ->line('---')
  449. ->line('layout: page')
  450. ->line('title: Codeception Changelog')
  451. ->line('---')
  452. ->line('')
  453. ->line(
  454. '<div class="alert alert-warning">Download specific version at <a href="/builds">builds page</a></div>'
  455. )
  456. ->line('')
  457. ->line($this->processChangelog())
  458. ->run();
  459. $docs = Finder::create()->files('*.md')->sortByName()->in('docs');
  460. $modules = [];
  461. $api = [];
  462. $reference = [];
  463. foreach ($docs as $doc) {
  464. $newfile = $doc->getFilename();
  465. $name = substr($doc->getBasename(), 0, -3);
  466. $contents = $doc->getContents();
  467. if (strpos($doc->getPathname(), 'docs'.DIRECTORY_SEPARATOR.'modules') !== false) {
  468. $newfile = 'docs/modules/' . $newfile;
  469. $modules[$name] = '/docs/modules/' . $doc->getBasename();
  470. $contents = str_replace('## ', '### ', $contents);
  471. $buttons = [
  472. 'source' => self::REPO_BLOB_URL."/".self::STABLE_BRANCH."/src/Codeception/Module/$name.php"
  473. ];
  474. // building version switcher
  475. foreach (['master', '2.2', '2.1', '2.0', '1.8'] as $branch) {
  476. $buttons[$branch] = self::REPO_BLOB_URL."/$branch/docs/modules/$name.md";
  477. }
  478. $buttonHtml = "\n\n".'<div class="btn-group" role="group" style="float: right" aria-label="...">';
  479. foreach ($buttons as $link => $url) {
  480. if ($link == self::STABLE_BRANCH) {
  481. $link = "<strong>$link</strong>";
  482. }
  483. $buttonHtml.= '<a class="btn btn-default" href="'.$url.'">'.$link.'</a>';
  484. }
  485. $buttonHtml .= '</div>'."\n\n";
  486. $contents = $buttonHtml . $contents;
  487. } elseif (strpos($doc->getPathname(), 'docs'.DIRECTORY_SEPARATOR.'reference') !== false) {
  488. $newfile = 'docs/reference/' . $newfile;
  489. $reference[$name] = '/docs/reference/' . $doc->getBasename();
  490. } else {
  491. $newfile = 'docs/'.$newfile;
  492. $api[substr($name, 3)] = '/docs/'.$doc->getBasename();
  493. }
  494. copy($doc->getPathname(), 'package/site/' . $newfile);
  495. $highlight_languages = implode('|', ['php', 'html', 'bash', 'yaml', 'json', 'xml', 'sql']);
  496. $contents = preg_replace(
  497. "~```\s?($highlight_languages)\b(.*?)```~ms",
  498. "{% highlight $1 %}\n$2\n{% endhighlight %}",
  499. $contents
  500. );
  501. $contents = str_replace('{% highlight %}', '{% highlight yaml %}', $contents);
  502. $contents = preg_replace("~```\s?(.*?)```~ms", "{% highlight yaml %}\n$1\n{% endhighlight %}", $contents);
  503. // set default language in order not to leave unparsed code inside '```'
  504. $matches = [];
  505. $title = $name;
  506. $contents = "---\nlayout: doc\ntitle: ".($title!="" ? $title." - " : "")
  507. ."Codeception - Documentation\n---\n\n".$contents;
  508. file_put_contents('package/site/' .$newfile, $contents);
  509. }
  510. chdir('package/site');
  511. $guides = array_keys($api);
  512. foreach ($api as $name => $url) {
  513. $filename = substr($url, 6);
  514. $doc = file_get_contents('docs/'.$filename)."\n\n\n";
  515. $i = array_search($name, $guides);
  516. if (isset($guides[$i+1])) {
  517. $next_title = $guides[$i+1];
  518. $next_url = $api[$guides[$i+1]];
  519. $next_url = substr($next_url, 0, -3);
  520. $doc .= "\n* **Next Chapter: [$next_title >]($next_url)**";
  521. }
  522. if (isset($guides[$i-1])) {
  523. $prev_title = $guides[$i-1];
  524. $prev_url = $api[$guides[$i-1]];
  525. $prev_url = substr($prev_url, 0, -3);
  526. $doc .= "\n* **Previous Chapter: [< $prev_title]($prev_url)**";
  527. }
  528. $this->taskWriteToFile('docs/'.$filename)
  529. ->text($doc)
  530. ->run();
  531. }
  532. $guides_list = '';
  533. foreach ($api as $name => $url) {
  534. $url = substr($url, 0, -3);
  535. $name = preg_replace('/([A-Z]+)([A-Z][a-z])/', '\\1 \\2', $name);
  536. $name = preg_replace('/([a-z\d])([A-Z])/', '\\1 \\2', $name);
  537. $guides_list .= '<li><a href="'.$url.'">'.$name.'</a></li>';
  538. }
  539. file_put_contents('_includes/guides.html', $guides_list);
  540. $this->say("Building Guides index");
  541. $this->taskWriteToFile('_includes/guides.html')
  542. ->text($guides_list)
  543. ->run();
  544. $this->taskWriteToFile('docs/index.html')
  545. ->line('---')
  546. ->line('layout: doc')
  547. ->line('title: Codeception Documentation')
  548. ->line('---')
  549. ->line('')
  550. ->line("<h1>Codeception Documentation Guides</h1>")
  551. ->line('')
  552. ->text($guides_list)
  553. ->run();
  554. /**
  555. * Align modules in two columns like this:
  556. * A D
  557. * B E
  558. * C
  559. */
  560. $modules_cols = 2;
  561. $modules_rows = ceil(count($modules) / $modules_cols);
  562. $module_names_chunked = array_chunk(array_keys($modules), $modules_rows);
  563. $modules_list = '';
  564. for ($i = 0; $i < $modules_rows; $i++) {
  565. for ($j = 0; $j < $modules_cols; $j++) {
  566. if (isset($module_names_chunked[$j][$i])) {
  567. $name = $module_names_chunked[$j][$i];
  568. $url = substr($modules[$name], 0, -3);
  569. $modules_list .= '<li><a href="'.$url.'">'.$name.'</a></li>';
  570. }
  571. }
  572. }
  573. file_put_contents('_includes/modules.html', $modules_list);
  574. $reference_list = '';
  575. foreach ($reference as $name => $url) {
  576. if ($name == 'Commands') {
  577. continue;
  578. }
  579. if ($name == 'Configuration') {
  580. continue;
  581. }
  582. $url = substr($url, 0, -3);
  583. $reference_list .= '<li><a href="'.$url.'">'.$name.'</a></li>';
  584. }
  585. file_put_contents('_includes/reference.html', $reference_list);
  586. $this->say("Writing extensions docs");
  587. $this->taskWriteToFile('_includes/extensions.md')
  588. ->textFromFile(__DIR__.'/ext/README.md')
  589. ->run();
  590. $this->publishSite();
  591. $this->taskExec('git add')->args('.')->run();
  592. }
  593. /**
  594. * @desc creates a new version tag and pushes to github
  595. * @param null $branch
  596. * @param array $opt
  597. */
  598. public function publishGit($branch = null, $opt = ['tag|t' => null])
  599. {
  600. $version = isset($opt['tag']) ? $opt['tag'] : \Codeception\Codecept::VERSION;
  601. $this->say('creating new tag for '.$version);
  602. if (!$branch) {
  603. $branch = explode('.', $version);
  604. array_pop($branch);
  605. $branch = implode('.', $branch);
  606. }
  607. $this->taskExec("git tag $version")->run();
  608. $this->taskExec("git push origin $branch --tags")->run();
  609. }
  610. protected function processChangelog()
  611. {
  612. $changelog = file_get_contents('CHANGELOG.md');
  613. //user
  614. $changelog = preg_replace('~\s@(\w+)~', ' **[$1](https://github.com/$1)**', $changelog);
  615. //issue
  616. $changelog = preg_replace(
  617. '~#(\d+)~',
  618. '[#$1](https://github.com/Codeception/Codeception/issues/$1)',
  619. $changelog
  620. );
  621. //module
  622. $changelog = preg_replace('~\s\[(\w+)\]\s~', ' **[$1]** ', $changelog);
  623. return $changelog;
  624. }
  625. /**
  626. * @desc cleans all log and temp directories
  627. */
  628. public function clean()
  629. {
  630. $this->taskCleanDir([
  631. 'tests/log',
  632. 'tests/data/claypit/tests/_output',
  633. 'tests/data/included/_log',
  634. 'tests/data/included/jazz/tests/_log',
  635. 'tests/data/included/shire/tests/_log',
  636. ])->run();
  637. $this->taskDeleteDir([
  638. 'tests/data/claypit/c3tmp',
  639. 'tests/data/sandbox'
  640. ])->run();
  641. }
  642. public function buildActors()
  643. {
  644. $build = 'php codecept build';
  645. $this->taskExec($build)->run();
  646. $this->taskExec($build)->args('-c tests/data/claypit')->run();
  647. $this->taskExec($build)->args('-c tests/data/included')->run();
  648. $this->taskExec($build)->args('-c tests/data/included/jazz')->run();
  649. $this->taskExec($build)->args('-c tests/data/included/shire')->run();
  650. $this->taskExec($build)->args('-c tests/data/included/jazz')->run();
  651. }
  652. protected function cloneSite()
  653. {
  654. @mkdir("package/site");
  655. $this->taskExec('git clone')
  656. ->args('git@github.com:Codeception/codeception.github.com.git')
  657. ->args('package/site/')
  658. ->run();
  659. chdir('package/site');
  660. }
  661. protected function publishSite()
  662. {
  663. $this->taskGitStack()
  664. ->add('-A')
  665. ->commit('auto updated documentation')
  666. ->push()
  667. ->run();
  668. chdir('..');
  669. sleep(2);
  670. $this->taskDeleteDir('site')->run();
  671. chdir('..');
  672. $this->say("Site build succesfully");
  673. }
  674. /**
  675. * Publishes Codeception base
  676. * @param null $branch
  677. * @param null $tag
  678. */
  679. public function publishBase($branch = null, $tag = null)
  680. {
  681. if (!$branch) {
  682. $branch = self::STABLE_BRANCH;
  683. }
  684. $this->say("Updating Codeception Base distribution");
  685. $tempBranch = "tmp".uniqid();
  686. $this->taskGitStack()
  687. ->checkout("-b $tempBranch")
  688. ->run();
  689. $this->taskReplaceInFile('composer.json')
  690. ->from('"codeception/codeception"')
  691. ->to('"codeception/base"')
  692. ->run();
  693. $this->taskReplaceInFile('composer.json')
  694. ->regex('~^\s+"facebook\/webdriver".*$~m')
  695. ->to('')
  696. ->run();
  697. $this->taskReplaceInFile('composer.json')
  698. ->regex('~^\s+"guzzlehttp\/guzzle".*$~m')
  699. ->to('')
  700. ->run();
  701. $this->taskComposerUpdate()->run();
  702. $this->taskGitStack()
  703. ->add('composer.json')
  704. ->commit('auto-update')
  705. ->exec("push -f base $tempBranch:$branch")
  706. ->run();
  707. if ($tag) {
  708. $this->taskGitStack()
  709. ->exec("tag -d $tag")
  710. ->exec("push base :refs/tags/$tag")
  711. ->exec("tag $tag")
  712. ->push('base', $tag)
  713. ->run();
  714. }
  715. $this->taskGitStack()
  716. ->checkout('-- composer.json')
  717. ->checkout($branch)
  718. ->exec("branch -D $tempBranch")
  719. ->run();
  720. }
  721. /**
  722. * Checks Codeception code style
  723. * Most useful values for `report` option: `full`, `summary`, `diff`
  724. *
  725. * @param array $opt
  726. */
  727. public function codestyleCheck($opt = ['report|r' => 'summary'])
  728. {
  729. $this->say("Checking code style");
  730. $this->taskExec('php vendor/bin/phpcs')
  731. ->arg('.')
  732. ->arg('--standard=ruleset.xml')
  733. ->arg('--report=' . $opt['report'])
  734. ->arg('--ignore=tests,vendor,package,docs')
  735. ->run();
  736. }
  737. public function codestyleFix()
  738. {
  739. $this->taskExec('php vendor/bin/phpcbf')
  740. ->arg('.')
  741. ->arg('--standard=ruleset.xml')
  742. ->arg('--ignore=tests,vendor,package,docs')
  743. ->run();
  744. }
  745. /**
  746. * @param $file
  747. * @param $className
  748. * @param $source
  749. */
  750. protected function documentApiClass($file, $className, $all = false)
  751. {
  752. $uri = str_replace('\\', '/', $className);
  753. $source = self::REPO_BLOB_URL."/".self::STABLE_BRANCH."/src/$uri.php";
  754. $this->taskGenDoc($file)
  755. ->docClass($className)
  756. ->filterMethods(function(ReflectionMethod $r) use ($all, $className) {
  757. return $all || $r->isPublic();
  758. })
  759. ->append(
  760. '<p>&nbsp;</p><div class="alert alert-warning">Reference is taken from the source code. '
  761. . '<a href="' . $source . '">Help us to improve documentation. Edit module reference</a></div>'
  762. )
  763. ->processPropertySignature(function($r) {
  764. return "\n#### $" . $r->name. "\n\n";
  765. })
  766. ->processPropertyDocBlock(function($r, $text) {
  767. $modifiers = implode(' ', \Reflection::getModifierNames($r->getModifiers()));
  768. $text = ' *' . $modifiers . '* **$' . $r->name . "**\n" . $text;
  769. $text = preg_replace("~@(.*?)\s(.*)~", 'type `$2`', $text);
  770. return $text;
  771. })
  772. ->processClassDocBlock(
  773. function (ReflectionClass $r, $text) {
  774. return $text . "\n";
  775. }
  776. )
  777. ->processMethodSignature(function($r, $text) {
  778. return "#### {$r->name}()\n\n" . ltrim($text, '#');
  779. })
  780. ->processMethodDocBlock(
  781. function (ReflectionMethod $r, $text) use ($file) {
  782. $file = str_replace(__DIR__, '', $r->getFileName());
  783. $source = self::REPO_BLOB_URL."/".self::STABLE_BRANCH. $file;
  784. $line = $r->getStartLine();
  785. $text = preg_replace("~^\s?@(.*?)\s~m", ' * `$1` $2', $text);
  786. $text .= "\n[See source]($source#L$line)";
  787. return "\n" . $text . "\n";
  788. }
  789. )
  790. ->reorderMethods('ksort')
  791. ->run();
  792. }
  793. }