32
1
mirror of https://github.com/joomla-extensions/weblinks.git synced 2024-11-17 01:45:10 +00:00
weblinks/RoboFile.php

247 lines
6.7 KiB
PHP
Raw Normal View History

<?php
/**
* This is project's console commands configuration for Robo task runner.
*
* Download robo.phar from http://robo.li/robo.phar and type in the root of the repo: $ php robo.phar
* Or do: $ composer update, and afterwards you will be able to execute robo like $ php vendor/bin/robo
*
* @see http://robo.li/
*/
2015-05-30 20:11:54 +00:00
require_once 'vendor/autoload.php';
class RoboFile extends \Robo\Tasks
{
2015-05-30 20:11:54 +00:00
// Load tasks from composer, see composer.json
use \joomla_projects\robo\loadTasks;
2015-05-30 19:31:14 +00:00
private $extension = '';
2015-05-30 20:11:54 +00:00
/**
* Set the Execute extension for Windows Operating System
2015-05-30 20:11:54 +00:00
*
* @return void
*/
private function setExecExtension()
2015-05-30 20:11:54 +00:00
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
{
2015-05-30 19:31:14 +00:00
$this->extension = '.exe';
}
}
2015-05-30 20:11:54 +00:00
/**
* Executes all the Selenium System Tests in a suite on your machine
2015-05-30 20:11:54 +00:00
*
* @param string $seleniumPath Optional path to selenium-standalone-server-x.jar
* @param string $suite Optional, the name of the tests suite
2015-05-30 20:11:54 +00:00
*
* @return mixed
*/
public function runTests($seleniumPath = null, $suite = 'acceptance')
2015-05-30 20:11:54 +00:00
{
2015-05-30 19:31:14 +00:00
$this->setExecExtension();
2015-05-30 20:11:54 +00:00
// Get Joomla Clean Testing sites
if (is_dir('tests/joomla-cms3'))
{
$this->taskDeleteDir('tests/joomla-cms3')->run();
}
$this->_exec('git' . $this->extension . ' clone -b staging --single-branch --depth 1 https://github.com/joomla/joomla-cms.git tests/joomla-cms3');
$this->say('Joomla CMS site created at tests/joomla-cms3');
if (!$seleniumPath)
{
if (!file_exists('selenium-server-standalone.jar'))
{
$this->say('Downloading Selenium Server, this may take a while.');
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
{
2015-05-30 19:31:14 +00:00
$this->_exec('curl.exe -sS http://selenium-release.storage.googleapis.com/2.45/selenium-server-standalone-2.45.0.jar > selenium-server-standalone.jar');
2015-05-30 20:11:54 +00:00
}
else
{
2015-05-30 19:31:14 +00:00
$this->taskExec('wget')
2015-05-30 20:11:54 +00:00
->arg('http://selenium-release.storage.googleapis.com/2.45/selenium-server-standalone-2.45.0.jar')
->arg('-O selenium-server-standalone.jar')
->printed(false)
->run();
2015-05-30 19:31:14 +00:00
}
2015-05-30 20:11:54 +00:00
}
$seleniumPath = 'selenium-server-standalone.jar';
}
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')
{
2015-05-30 19:31:14 +00:00
$seleniumPath = "java -jar $seleniumPath >> selenium.log 2>&1 &";
2015-05-30 20:11:54 +00:00
}
else
{
2015-05-30 19:31:14 +00:00
$seleniumPath = "START java.exe -jar .\\" . $seleniumPath;
}
2015-05-30 20:11:54 +00:00
// Make sure we have Composer
if (!file_exists('./composer.phar'))
{
$this->_exec('curl' . $this->extension . ' -sS https://getcomposer.org/installer | php');
2015-05-30 20:11:54 +00:00
}
$this->taskComposerUpdate()->run();
2015-05-30 20:11:54 +00:00
// Running Selenium server
$this->_exec($seleniumPath);
2015-05-30 20:11:54 +00:00
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
{
2015-05-30 19:31:14 +00:00
sleep(10);
2015-05-30 20:11:54 +00:00
}
else
{
2015-05-30 19:31:14 +00:00
$this->taskWaitForSeleniumStandaloneServer()
2015-05-30 20:11:54 +00:00
->run()
->stopOnFail();
2015-05-30 19:31:14 +00:00
}
2015-05-30 20:11:54 +00:00
// Loading Symfony Command and running with passed argument
$this->_exec('php' . $this->extension . ' vendor/bin/codecept build');
2015-05-30 20:11:54 +00:00
$this->taskCodecept()
->suite($suite)
2015-05-30 20:11:54 +00:00
->arg('--steps')
->arg('--debug')
->run()
->stopOnFail();
// Kill selenium server
// $this->_exec('curl http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer');
/*
// Uncomment this lines if you need to debug selenium errors
$seleniumErrors = file_get_contents('selenium.log');
if ($seleniumErrors) {
$this->say('Printing Selenium Log files');
$this->say('------ selenium.log (start) ---------');
$this->say($seleniumErrors);
$this->say('------ selenium.log (end) -----------');
}
*/
}
/**
* Executes a specific Selenium System Tests in your machine
*
* @param string $seleniumPath Optional path to selenium-standalone-server-x.jar
* @param string $pathToTestFile Optional name of the test to be run
* @param string $suite Optional name of the suite containing the tests, Acceptance by default.
*
* @return mixed
*/
public function runTest($seleniumPath = null, $pathToTestFile = null, $suite = 'acceptance')
{
2015-06-09 17:10:05 +00:00
if (!$seleniumPath)
{
if (!file_exists('selenium-server-standalone.jar'))
{
$this->say('Downloading Selenium Server, this may take a while.');
$this->taskExec('wget')
->arg('http://selenium-release.storage.googleapis.com/2.45/selenium-server-standalone-2.45.0.jar')
->arg('-O selenium-server-standalone.jar')
->printed(false)
->run();
}
2015-06-09 17:10:05 +00:00
$seleniumPath = 'selenium-server-standalone.jar';
}
// Make sure we have Composer
2015-06-09 17:10:05 +00:00
if (!file_exists('./composer.phar'))
{
$this->_exec('curl -sS https://getcomposer.org/installer | php');
}
$this->taskComposerUpdate()->run();
// Running Selenium server
$this->_exec("java -jar $seleniumPath > selenium-errors.log 2>selenium.log &");
$this->taskWaitForSeleniumStandaloneServer()
->run()
->stopOnFail();
// Make sure to Run the Build Command to Generate AcceptanceTester
$this->_exec("php vendor/bin/codecept build");
if (!$pathToTestFile)
{
$tests = array();
$this->say('Available tests in the system:');
$filesInSuite = scandir(getcwd() . '/tests/' . $suite);
$i = 1;
2015-06-09 17:10:05 +00:00
foreach ($filesInSuite as $file)
{
// Make sure the file is a Test file
if (strripos($file, 'cept.php') || strripos($file, 'cest.php'))
{
$tests[$i] = $file;
$this->say('[' . $i . '] ' . $file);
$i++;
}
}
2015-06-09 17:10:05 +00:00
$this->say('');
2015-06-09 17:10:05 +00:00
$testNumber = $this->ask('Type the number of the test in the list that you want to run...');
$pathToTestFile = "tests/$suite/" . $tests[$testNumber];
}
$this->taskCodecept()
->test($pathToTestFile)
->arg('--steps')
->arg('--debug')
->run()
->stopOnFail();
// Kill selenium server
// $this->_exec('curl http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer');
$this->say('Printing Selenium Log files');
$this->say('------ selenium-errors.log (start) ---------');
$seleniumErrors = file_get_contents('selenium-errors.log');
2015-06-09 17:10:05 +00:00
if ($seleniumErrors)
{
$this->say(file_get_contents('selenium-errors.log'));
}
2015-06-09 17:10:05 +00:00
else
{
$this->say('no errors were found');
}
$this->say('------ selenium-errors.log (end) -----------');
/*
// Uncomment if you need to debug issues in selenium
$this->say('');
$this->say('------ selenium.log (start) -----------');
$this->say(file_get_contents('selenium.log'));
$this->say('------ selenium.log (end) -----------');
*/
}
/**
* Creates a testing Joomla site for running the tests (use it before run:test)
*/
public function createTestingSite()
{
// Get Joomla Clean Testing sites
if (is_dir('tests/joomla-cms3'))
{
$this->taskDeleteDir('tests/joomla-cms3')->run();
}
$this->_exec('git' . $this->extension . ' clone -b staging --single-branch --depth 1 https://github.com/joomla/joomla-cms.git tests/joomla-cms3');
$this->say('Joomla CMS site created at tests/joomla-cms3');
}
2015-06-09 17:10:05 +00:00
}