first commit
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"name": "wpdesk\/wp-codeception",
|
||||
"description": "Library for WP Desk Codeception tests.",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"wordpress",
|
||||
"codeception",
|
||||
"admin"
|
||||
],
|
||||
"homepage": "https:\/\/gitlab.com\/wpdesk\/wp-codeception",
|
||||
"type": "composer-plugin",
|
||||
"minimum-stability": "stable",
|
||||
"authors": [
|
||||
{
|
||||
"name": "grola",
|
||||
"email": "grola@wpdesk.net"
|
||||
}
|
||||
],
|
||||
"config": {
|
||||
"sort-packages": true,
|
||||
"platform": {
|
||||
"php": "7.0.8"
|
||||
},
|
||||
"allow-plugins": {
|
||||
"kylekatarnls\/update-helper": true
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.0.8",
|
||||
"ext-json": "*",
|
||||
"composer-plugin-api": "^1.1|^2",
|
||||
"albertofem\/rsync-lib": "^1.0",
|
||||
"bordoni\/phpass": "^0.3.5",
|
||||
"codeception\/module-asserts": "^1.3",
|
||||
"codeception\/module-cli": "^1.0",
|
||||
"codeception\/module-db": "^1.0",
|
||||
"codeception\/module-filesystem": "^1.0",
|
||||
"codeception\/module-phpbrowser": "^1.0",
|
||||
"codeception\/module-rest": "^1.2",
|
||||
"codeception\/module-webdriver": "^1.0",
|
||||
"codeception\/util-universalframework": "^1.0",
|
||||
"lucatume\/codeception-steppify": "^1.0",
|
||||
"lucatume\/wp-browser": "^2.4",
|
||||
"phpunit\/php-code-coverage": "^5.3",
|
||||
"symfony\/yaml": "^v3.4.47",
|
||||
"vlucas\/phpdotenv": "^4.2.0",
|
||||
"wp-cli\/admin-command": "^2.0",
|
||||
"wp-cli\/wp-cli-bundle": "^2.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"10up\/wp_mock": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"FcfVendor\\WPDesk\\Codeception\\": "src\/WPDesk\/Codeception",
|
||||
"FcfVendor\\Codeception\\Module\\": "src\/Codeception\/Module",
|
||||
"FcfVendor\\WPDesk\\Composer\\Codeception\\": "src\/WPDesk\/Composer"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {},
|
||||
"scripts": {
|
||||
"phpcs": "phpcs"
|
||||
},
|
||||
"extra": {
|
||||
"class": "WPDesk\\Composer\\Codeception\\Plugin"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\Codeception\Command;
|
||||
|
||||
use FcfVendor\Codeception\Lib\Generator\Test;
|
||||
/**
|
||||
* Class code for codeception example test for WP Desk plugin activation.
|
||||
*
|
||||
* @package WPDesk\Codeception\Command
|
||||
*/
|
||||
class AcceptanceTestGenerator extends \FcfVendor\Codeception\Lib\Generator\Test
|
||||
{
|
||||
protected $template = <<<EOF
|
||||
<?php {{namespace}}
|
||||
|
||||
use WPDesk\\Codeception\\Tests\\Acceptance\\Cest\\AbstractCestForPluginActivation;
|
||||
|
||||
class {{name}} extends AbstractCestForPluginActivation {
|
||||
|
||||
\t/**
|
||||
\t * Deactivate plugins before tests.
|
||||
\t *
|
||||
\t * @param AcceptanceTester \$i .
|
||||
\t *
|
||||
\t * @throws \\Codeception\\Exception\\ModuleException .
|
||||
\t */
|
||||
\tpublic function _before( \$i ) {
|
||||
\t\t\$i->loginAsAdministrator();
|
||||
\t\t\$i->amOnPluginsPage();
|
||||
\t\t\$i->deactivatePlugin( \$this->getPluginSlug() );
|
||||
\t\t\$i->amOnPluginsPage();
|
||||
\t\t\$i->seePluginDeactivated( \$this->getPluginSlug() );
|
||||
\t\t\$i->amOnPluginsPage();
|
||||
\t\t\$i->deactivatePlugin( self::WOOCOMMERCE_PLUGIN_SLUG );
|
||||
\t\t\$i->amOnPluginsPage();
|
||||
\t\t\$i->seePluginDeactivated( self::WOOCOMMERCE_PLUGIN_SLUG );
|
||||
\t}
|
||||
|
||||
\t/**
|
||||
\t * Plugin activation.
|
||||
\t *
|
||||
\t * @param AcceptanceTester \$i .
|
||||
\t *
|
||||
\t * @throws \\Codeception\\Exception\\ModuleException .
|
||||
\t */
|
||||
\tpublic function pluginActivation( \$i ) {
|
||||
|
||||
\t\t\$i->loginAsAdministrator();
|
||||
|
||||
\t\t\$i->amOnPluginsPage();
|
||||
\t\t\$i->seePluginDeactivated( \$this->getPluginSlug() );
|
||||
|
||||
\t\t// This is an example and you should change it to current plugin.
|
||||
\t\t\$i->activateWPDeskPlugin(
|
||||
\t\t\t\$this->getPluginSlug(),
|
||||
\t\t\tarray( 'woocommerce' ),
|
||||
\t\t\tarray( 'The “WooCommerce Fakturownia” plugin cannot run without WooCommerce active. Please install and activate WooCommerce plugin.' )
|
||||
\t\t);
|
||||
|
||||
\t}
|
||||
}
|
||||
EOF;
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\Codeception\Command;
|
||||
|
||||
use FcfVendor\Codeception\Command\GenerateTest;
|
||||
use FcfVendor\Codeception\CustomCommandInterface;
|
||||
use FcfVendor\Symfony\Component\Console\Input\InputInterface;
|
||||
use FcfVendor\Symfony\Component\Console\Output\OutputInterface;
|
||||
/**
|
||||
* Generates codeception example test for WP Desk plugin activation.
|
||||
*
|
||||
* @package WPDesk\Codeception\Command
|
||||
*/
|
||||
class GeneratePluginActivation extends \FcfVendor\Codeception\Command\GenerateTest implements \FcfVendor\Codeception\CustomCommandInterface
|
||||
{
|
||||
/**
|
||||
* Get codeception command description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return 'Generates plugin activation tests.';
|
||||
}
|
||||
/**
|
||||
* Returns the name of the command.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getCommandName()
|
||||
{
|
||||
return 'generate:activation';
|
||||
}
|
||||
/**
|
||||
* Get generator class.
|
||||
*
|
||||
* @param array $config .
|
||||
* @param string $class .
|
||||
* @return AcceptanceTestGenerator
|
||||
*/
|
||||
protected function getGenerator($config, $class)
|
||||
{
|
||||
return new \FcfVendor\WPDesk\Codeception\Command\AcceptanceTestGenerator($config, $class);
|
||||
}
|
||||
/**
|
||||
* Execute command.
|
||||
*
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute(\FcfVendor\Symfony\Component\Console\Input\InputInterface $input, \FcfVendor\Symfony\Component\Console\Output\OutputInterface $output)
|
||||
{
|
||||
$suite = $input->getArgument('suite');
|
||||
$class = $input->getArgument('class');
|
||||
$config = $this->getSuiteConfig($suite);
|
||||
$className = $this->getShortClassName($class);
|
||||
$path = $this->createDirectoryFor($config['path'], $class);
|
||||
$filename = $this->completeSuffix($className, 'Cest');
|
||||
$filename = $path . $filename;
|
||||
$gen = $this->getGenerator($config, $class);
|
||||
$res = $this->createFile($filename, $gen->produce());
|
||||
if (!$res) {
|
||||
$output->writeln("<error>Test {$filename} already exists</error>");
|
||||
return;
|
||||
}
|
||||
$output->writeln("<info>Test was created in {$filename}</info>");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\Codeception\Command;
|
||||
|
||||
use FcfVendor\Codeception\Command\GenerateTest;
|
||||
use FcfVendor\Codeception\CustomCommandInterface;
|
||||
use FcfVendor\Symfony\Component\Console\Input\InputInterface;
|
||||
use FcfVendor\Symfony\Component\Console\Output\OutputInterface;
|
||||
/**
|
||||
* Generates codeception example test for WP Desk plugin activation.
|
||||
*
|
||||
* @package WPDesk\Codeception\Command
|
||||
*/
|
||||
class GenerateWooCommerce extends \FcfVendor\Codeception\Command\GenerateTest implements \FcfVendor\Codeception\CustomCommandInterface
|
||||
{
|
||||
/**
|
||||
* Get codeception command description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return 'Generates woocommerce tests.';
|
||||
}
|
||||
/**
|
||||
* Returns the name of the command.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getCommandName()
|
||||
{
|
||||
return 'generate:woocommerce';
|
||||
}
|
||||
/**
|
||||
* Get generator class.
|
||||
*
|
||||
* @param array $config .
|
||||
* @param string $class .
|
||||
* @return WooCommerceTestGenerator
|
||||
*/
|
||||
protected function getGenerator($config, $class)
|
||||
{
|
||||
return new \FcfVendor\WPDesk\Codeception\Command\WooCommerceTestGenerator($config, $class);
|
||||
}
|
||||
/**
|
||||
* Execute command.
|
||||
*
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute(\FcfVendor\Symfony\Component\Console\Input\InputInterface $input, \FcfVendor\Symfony\Component\Console\Output\OutputInterface $output)
|
||||
{
|
||||
$suite = $input->getArgument('suite');
|
||||
$class = $input->getArgument('class');
|
||||
$config = $this->getSuiteConfig($suite);
|
||||
$className = $this->getShortClassName($class);
|
||||
$path = $this->createDirectoryFor($config['path'], $class);
|
||||
$filename = $this->completeSuffix($className, 'Cest');
|
||||
$filename = $path . $filename;
|
||||
$gen = $this->getGenerator($config, $class);
|
||||
$res = $this->createFile($filename, $gen->produce());
|
||||
if (!$res) {
|
||||
$output->writeln("<error>Test {$filename} already exists</error>");
|
||||
return;
|
||||
}
|
||||
$output->writeln("<info>Test was created in {$filename}</info>");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\Codeception\Command;
|
||||
|
||||
use FcfVendor\Codeception\Lib\Generator\Test;
|
||||
/**
|
||||
* Class code for codeception example test for WP Desk plugin activation.
|
||||
*
|
||||
* @package WPDesk\Codeception\Command
|
||||
*/
|
||||
class WooCommerceTestGenerator extends \FcfVendor\Codeception\Lib\Generator\Test
|
||||
{
|
||||
protected $template = <<<EOF
|
||||
<?php {{namespace}}
|
||||
|
||||
use WPDesk\\Codeception\\Tests\\Acceptance\\Cest\\AbstractCestForWooCommerce;
|
||||
|
||||
/**
|
||||
* Common WooCommerce tests.
|
||||
*/
|
||||
class {{name}} extends AbstractCestForWooCommerce {
|
||||
|
||||
}
|
||||
EOF;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\Composer\Codeception;
|
||||
|
||||
use FcfVendor\WPDesk\Composer\Codeception\Commands\CreateCodeceptionTests;
|
||||
use FcfVendor\WPDesk\Composer\Codeception\Commands\PrepareCodeceptionDb;
|
||||
use FcfVendor\WPDesk\Composer\Codeception\Commands\PrepareLocalCodeceptionTests;
|
||||
use FcfVendor\WPDesk\Composer\Codeception\Commands\PrepareLocalCodeceptionTestsWithCoverage;
|
||||
use FcfVendor\WPDesk\Composer\Codeception\Commands\PrepareParallelCodeceptionTests;
|
||||
use FcfVendor\WPDesk\Composer\Codeception\Commands\PrepareWordpressForCodeception;
|
||||
use FcfVendor\WPDesk\Composer\Codeception\Commands\RunCodeceptionTests;
|
||||
use FcfVendor\WPDesk\Composer\Codeception\Commands\RunLocalCodeceptionTests;
|
||||
use FcfVendor\WPDesk\Composer\Codeception\Commands\RunLocalCodeceptionTestsWithCoverage;
|
||||
/**
|
||||
* Links plugin commands handlers to composer.
|
||||
*/
|
||||
class CommandProvider implements \FcfVendor\Composer\Plugin\Capability\CommandProvider
|
||||
{
|
||||
public function getCommands()
|
||||
{
|
||||
return [new \FcfVendor\WPDesk\Composer\Codeception\Commands\CreateCodeceptionTests(), new \FcfVendor\WPDesk\Composer\Codeception\Commands\RunCodeceptionTests(), new \FcfVendor\WPDesk\Composer\Codeception\Commands\RunLocalCodeceptionTests(), new \FcfVendor\WPDesk\Composer\Codeception\Commands\RunLocalCodeceptionTestsWithCoverage(), new \FcfVendor\WPDesk\Composer\Codeception\Commands\PrepareCodeceptionDb(), new \FcfVendor\WPDesk\Composer\Codeception\Commands\PrepareWordpressForCodeception(), new \FcfVendor\WPDesk\Composer\Codeception\Commands\PrepareLocalCodeceptionTests(), new \FcfVendor\WPDesk\Composer\Codeception\Commands\PrepareLocalCodeceptionTestsWithCoverage(), new \FcfVendor\WPDesk\Composer\Codeception\Commands\PrepareParallelCodeceptionTests()];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\Composer\Codeception\Commands;
|
||||
|
||||
use FcfVendor\Composer\Command\BaseCommand as CodeceptionBaseCommand;
|
||||
use FcfVendor\Symfony\Component\Console\Output\OutputInterface;
|
||||
/**
|
||||
* Base for commands - declares common methods.
|
||||
*
|
||||
* @package WPDesk\Composer\Codeception\Commands
|
||||
*/
|
||||
abstract class BaseCommand extends \FcfVendor\Composer\Command\BaseCommand
|
||||
{
|
||||
/**
|
||||
* @param string $command
|
||||
* @param OutputInterface $output
|
||||
*/
|
||||
protected function execAndOutput($command, \FcfVendor\Symfony\Component\Console\Output\OutputInterface $output)
|
||||
{
|
||||
\passthru($command);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,375 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class Env
|
||||
* @package WPDesk\Composer\Codeception\Commands
|
||||
*/
|
||||
namespace FcfVendor\WPDesk\Composer\Codeception\Commands;
|
||||
|
||||
use FcfVendor\Dotenv\Dotenv;
|
||||
/**
|
||||
* Env.
|
||||
*/
|
||||
class Configuration
|
||||
{
|
||||
const MYSQL_IP = 'MYSQL_IP';
|
||||
const MYSQL_DBNAME = 'MYSQL_DBNAME';
|
||||
const MYSQL_DBUSER = 'MYSQL_DBUSER';
|
||||
const MYSQL_DBPASSWORD = 'MYSQL_DBPASSWORD';
|
||||
const APACHE_DOCUMENT_ROOT = 'APACHE_DOCUMENT_ROOT';
|
||||
const WOOTESTS_IP = 'WOOTESTS_IP';
|
||||
const DEPENDENT_PLUGINS_DIR = 'DEPENDENT_PLUGINS_DIR';
|
||||
const TEST_SITE_WP_URL = 'TEST_SITE_WP_URL';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $apache_document_root;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $wptests_ip;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $wptests_url;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $dbhost;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $dbname;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $dbuser;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $dbpassword;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $dependent_plugins_dir;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $plugin_slug;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $plugin_dir;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $plugin_file;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $plugin_title;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $plugin_product_id;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $repository_plugins;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $local_plugins;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $activate_plugins;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $prepare_database;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $theme_files;
|
||||
/**
|
||||
* Configuration constructor.
|
||||
*
|
||||
* @param $apache_document_root
|
||||
* @param $wptests_ip
|
||||
* @param $wptests_url
|
||||
* @param $dbhost
|
||||
* @param $dbname
|
||||
* @param $dbuser
|
||||
* @param $dbpassword
|
||||
* @param $dependent_plugins_dir
|
||||
* @param $plugin_slug
|
||||
* @param $plugin_dir
|
||||
* @param $plugin_file
|
||||
* @param $plugin_title
|
||||
* @param $plugin_product_id
|
||||
* @param $repository_plugins
|
||||
* @param $local_plugins
|
||||
* @param $activate_plugins
|
||||
* @param $prepare_database
|
||||
* @param $theme_files
|
||||
*/
|
||||
public function __construct($apache_document_root, $wptests_ip, $wptests_url, $dbhost, $dbname, $dbuser, $dbpassword, $dependent_plugins_dir, $plugin_slug, $plugin_dir, $plugin_file, $plugin_title, $plugin_product_id, $repository_plugins, $local_plugins, $activate_plugins, $prepare_database, $theme_files)
|
||||
{
|
||||
$this->apache_document_root = $apache_document_root;
|
||||
$this->wptests_ip = $wptests_ip;
|
||||
$this->wptests_url = $wptests_url;
|
||||
$this->dbhost = $dbhost;
|
||||
$this->dbname = $dbname;
|
||||
$this->dbuser = $dbuser;
|
||||
$this->dbpassword = $dbpassword;
|
||||
$this->dependent_plugins_dir = $dependent_plugins_dir;
|
||||
$this->plugin_slug = $plugin_slug;
|
||||
$this->plugin_dir = $plugin_dir;
|
||||
$this->plugin_file = $plugin_file;
|
||||
$this->plugin_title = $plugin_title;
|
||||
$this->plugin_product_id = $plugin_product_id;
|
||||
$this->repository_plugins = $repository_plugins;
|
||||
$this->local_plugins = $local_plugins;
|
||||
$this->activate_plugins = $activate_plugins;
|
||||
$this->prepare_database = $prepare_database;
|
||||
$this->theme_files = $theme_files;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getApacheDocumentRoot()
|
||||
{
|
||||
return $this->apache_document_root;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getWptestsIp()
|
||||
{
|
||||
return $this->wptests_ip;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getWptestsUrl()
|
||||
{
|
||||
return $this->wptests_url;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDbhost()
|
||||
{
|
||||
return $this->dbhost;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDbname()
|
||||
{
|
||||
return $this->dbname;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDbuser()
|
||||
{
|
||||
return $this->dbuser;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDbpassword()
|
||||
{
|
||||
return $this->dbpassword;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDependentPluginsDir()
|
||||
{
|
||||
return $this->dependent_plugins_dir;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPluginSlug()
|
||||
{
|
||||
return $this->plugin_slug;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPluginDir()
|
||||
{
|
||||
return $this->plugin_dir;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPluginFile()
|
||||
{
|
||||
return $this->plugin_file;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPluginTitle()
|
||||
{
|
||||
return $this->plugin_title;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPluginProductId()
|
||||
{
|
||||
return $this->plugin_product_id;
|
||||
}
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getRepositoryPlugins()
|
||||
{
|
||||
return $this->repository_plugins;
|
||||
}
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getLocalPlugins()
|
||||
{
|
||||
return $this->local_plugins;
|
||||
}
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getActivatePlugins()
|
||||
{
|
||||
return $this->activate_plugins;
|
||||
}
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getPrepareDatabase()
|
||||
{
|
||||
return $this->prepare_database;
|
||||
}
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getThemeFiles()
|
||||
{
|
||||
return $this->theme_files;
|
||||
}
|
||||
/**
|
||||
* Set env variables from configuration.
|
||||
*/
|
||||
public function prepareEnvForConfiguration()
|
||||
{
|
||||
$this->putEnv('WPDESK_PLUGIN_SLUG', $this->getPluginSlug());
|
||||
$this->putEnv('WPDESK_PLUGIN_FILE', $this->getPluginFile());
|
||||
$this->putEnv('WPDESK_PLUGIN_TITLE', $this->getPluginTitle());
|
||||
$this->putEnv('WPDESK_PLUGIN_PRODUCT_ID', $this->getPluginProductId());
|
||||
}
|
||||
/**
|
||||
* @param string $env_variable
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function putEnv($env_variable, $value)
|
||||
{
|
||||
\putenv($env_variable . '=' . $value);
|
||||
}
|
||||
/**
|
||||
* @param array $configuration .
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public static function createFromEnvAndConfiguration(array $configuration)
|
||||
{
|
||||
$dotenv = \FcfVendor\Dotenv\Dotenv::createImmutable(\getcwd() . '/../');
|
||||
$dotenv->safeLoad();
|
||||
$apache_document_root = self::prepareFromEnv(self::APACHE_DOCUMENT_ROOT, self::prepareApacheDocumentRoot());
|
||||
$wptests_ip = self::prepareFromEnv(self::WOOTESTS_IP, 'wptests.lh');
|
||||
$dbhost = self::prepareFromEnv(self::MYSQL_IP, 'mysqltests');
|
||||
$dbname = self::prepareFromEnv(self::MYSQL_DBNAME, 'wptest');
|
||||
$dbuser = self::prepareFromEnv(self::MYSQL_DBUSER, 'mysql');
|
||||
$dbpassword = self::prepareFromEnv(self::MYSQL_DBPASSWORD, 'mysql');
|
||||
$wptest_url = self::prepareFromEnv(self::TEST_SITE_WP_URL, 'http://wptests.lh');
|
||||
$dependent_plugins_dir = self::prepareFromEnv(self::DEPENDENT_PLUGINS_DIR, '../');
|
||||
if (isset($configuration['plugin-slug'])) {
|
||||
$plugin_slug = $configuration['plugin-slug'];
|
||||
} else {
|
||||
throw new \FcfVendor\WPDesk\Composer\Codeception\Commands\SettingsException('Missing plugin-slug setting!');
|
||||
}
|
||||
if (isset($configuration['plugin-file'])) {
|
||||
$plugin_file = $configuration['plugin-file'];
|
||||
} else {
|
||||
throw new \FcfVendor\WPDesk\Composer\Codeception\Commands\SettingsException('Missing plugin-file setting!');
|
||||
}
|
||||
$plugin_file_exploded = \explode('/', $plugin_file);
|
||||
$plugin_dir = $plugin_file_exploded[0];
|
||||
if (isset($configuration['plugin-title'])) {
|
||||
$plugin_title = $configuration['plugin-title'];
|
||||
} else {
|
||||
throw new \FcfVendor\WPDesk\Composer\Codeception\Commands\SettingsException('Missing plugin-title setting!');
|
||||
}
|
||||
if (isset($configuration['plugin-product-id'])) {
|
||||
$plugin_product_id = $configuration['plugin-product-id'];
|
||||
} else {
|
||||
$plugin_product_id = '';
|
||||
}
|
||||
$prepare_database = array();
|
||||
if (isset($configuration['prepare-database']) && \is_array($configuration['prepare-database'])) {
|
||||
$prepare_database = $configuration['prepare-database'];
|
||||
}
|
||||
$theme_files = array();
|
||||
if (isset($configuration['theme-files']) && \is_array($configuration['theme-files'])) {
|
||||
$theme_files = $configuration['theme-files'];
|
||||
}
|
||||
$repository_plugins = self::getPluginsSettings($configuration, 'repository');
|
||||
$local_plugins = self::getPluginsSettings($configuration, 'local');
|
||||
$activate_plugins = self::getPluginsSettings($configuration, 'activate');
|
||||
return new self($apache_document_root, $wptests_ip, $wptest_url, $dbhost, $dbname, $dbuser, $dbpassword, $dependent_plugins_dir, $plugin_slug, $plugin_dir, $plugin_file, $plugin_title, $plugin_product_id, $repository_plugins, $local_plugins, $activate_plugins, $prepare_database, $theme_files);
|
||||
}
|
||||
/**
|
||||
* @param string $env_variable .
|
||||
* @param string $default_value .
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function prepareFromEnv($env_variable, $default_value)
|
||||
{
|
||||
$value = \getenv($env_variable);
|
||||
$value = $value ? $value : $default_value;
|
||||
return $value;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private static function prepareApacheDocumentRoot()
|
||||
{
|
||||
return self::isWindows() ? 'c:\\xampp\\htdocs\\wptests' : '/tmp/wptests';
|
||||
}
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function isWindows()
|
||||
{
|
||||
return \false !== \stristr(\PHP_OS, 'WIN') && \false === \stristr(\PHP_OS, 'DARWIN');
|
||||
}
|
||||
/**
|
||||
* @param array $configuration .
|
||||
* @param string $plugins_section .
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function getPluginsSettings(array $configuration, $plugins_section)
|
||||
{
|
||||
if (\is_array($configuration) && isset($configuration['plugins'], $configuration['plugins'][$plugins_section]) && \is_array($configuration['plugins'][$plugins_section])) {
|
||||
return $configuration['plugins'][$plugins_section];
|
||||
}
|
||||
return array();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\Composer\Codeception\Commands;
|
||||
|
||||
use FcfVendor\Composer\Downloader\FilesystemException;
|
||||
use FcfVendor\Symfony\Component\Console\Input\InputInterface;
|
||||
use FcfVendor\Symfony\Component\Console\Output\OutputInterface;
|
||||
/**
|
||||
* Codeception tests creator command.
|
||||
*
|
||||
* @package WPDesk\Composer\Codeception\Commands
|
||||
*/
|
||||
class CreateCodeceptionTests extends \FcfVendor\WPDesk\Composer\Codeception\Commands\BaseCommand
|
||||
{
|
||||
use SedTrait;
|
||||
/**
|
||||
* Configure command.
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
$this->setName('create-codeception-tests')->setDescription('Create codeception tests directories and files.');
|
||||
}
|
||||
/**
|
||||
* Copy file.
|
||||
*
|
||||
* @param string $source
|
||||
* @param string $dest
|
||||
* @param string $exceptionMessage
|
||||
* @throws FilesystemException
|
||||
*/
|
||||
private function copy($source, $dest, $exceptionMessage)
|
||||
{
|
||||
if (!\copy($source, $dest)) {
|
||||
throw new \FcfVendor\Composer\Downloader\FilesystemException($exceptionMessage);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copy configuration files.
|
||||
*
|
||||
* @param $codeceptionDir
|
||||
* @param $testsDir
|
||||
* @param $codeceptionYml
|
||||
* @param $envConfig
|
||||
* @param $acceptanceYml
|
||||
* @param $bootstrapScript
|
||||
* @return void
|
||||
* @throws FilesystemException
|
||||
*/
|
||||
private function copyConfigurationFiles($codeceptionDir, $testsDir, $codeceptionYml, $envConfig, $acceptanceYml, $bootstrapScript)
|
||||
{
|
||||
if (!\file_exists('./' . $codeceptionYml)) {
|
||||
$this->copy('./vendor/wpdesk/wp-codeception/configuration/' . $codeceptionYml, './' . $codeceptionYml, 'Error copying codeception configuration file!');
|
||||
}
|
||||
if (!\file_exists('./' . $envConfig)) {
|
||||
$this->copy('./vendor/wpdesk/wp-codeception/configuration/' . $envConfig, './' . $envConfig, 'Error copying codeception env configuration file!');
|
||||
}
|
||||
if (\file_exists($testsDir . '/' . $acceptanceYml)) {
|
||||
\unlink($testsDir . '/' . $acceptanceYml);
|
||||
}
|
||||
$this->copy('./vendor/wpdesk/wp-codeception/configuration/' . $acceptanceYml, $testsDir . '/' . $acceptanceYml, 'Error copying codeception acceptance configuration file!');
|
||||
if (!\file_exists($codeceptionDir . '/' . $bootstrapScript)) {
|
||||
$this->copy('./vendor/wpdesk/wp-codeception/scripts/' . $bootstrapScript, $codeceptionDir . '/' . $bootstrapScript, 'Error copying codeception bootstrap script file!');
|
||||
}
|
||||
if (!@\file_exists($testsDir . '/_output')) {
|
||||
\mkdir($testsDir . '/_output', 0777, \true);
|
||||
}
|
||||
if (!\file_exists($testsDir . '/_output/.gitignore')) {
|
||||
$this->copy('./vendor/wpdesk/wp-codeception/configuration/_output.gitignore', $testsDir . '/_output/.gitignore', 'Error copying codeception acceptance output .gitignore file!');
|
||||
}
|
||||
if (!@\file_exists($testsDir . '/_support/_generated')) {
|
||||
\mkdir($testsDir . '/_support/_generated', 0777, \true);
|
||||
}
|
||||
if (!\file_exists($testsDir . '/_support/_generated/.gitignore')) {
|
||||
$this->copy('./vendor/wpdesk/wp-codeception/configuration/_generated.gitignore', $testsDir . '/_support/_generated/.gitignore', 'Error copying codeception acceptance output .gitignore file!');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Inject traits into tester class.
|
||||
*
|
||||
* @param string $testsDir
|
||||
* @return void
|
||||
*/
|
||||
private function injectTraitsIntoTesterClass($testsDir)
|
||||
{
|
||||
$file_pattern = $testsDir . '/_support/AcceptanceTester.php';
|
||||
$pattern = "/use _generated\\\\AcceptanceTesterActions;/";
|
||||
$replace = "use _generated\\AcceptanceTesterActions;\n" . "\n\tuse \\WPDesk\\Codeception\\Tests\\Acceptance\\Tester\\TesterWordpressActions;" . "\n\tuse \\WPDesk\\Codeception\\Tests\\Acceptance\\Tester\\TesterWooCommerceActions;" . "\n\tuse \\WPDesk\\Codeception\\Tests\\Acceptance\\Tester\\TesterWPDeskActions;";
|
||||
$this->wpdeskSed($file_pattern, $pattern, $replace);
|
||||
}
|
||||
/**
|
||||
* Execute command.
|
||||
*
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @return void
|
||||
* @throws FilesystemException
|
||||
*/
|
||||
protected function execute(\FcfVendor\Symfony\Component\Console\Input\InputInterface $input, \FcfVendor\Symfony\Component\Console\Output\OutputInterface $output)
|
||||
{
|
||||
$codeceptionDir = './tests/codeception';
|
||||
$testsDir = $codeceptionDir . '/tests';
|
||||
$codeceptionYml = 'codeception.dist.yml';
|
||||
$envConfig = '.env.testing';
|
||||
$acceptanceYml = 'acceptance.suite.yml';
|
||||
$bootstrapScript = 'bootstrap.sh';
|
||||
if (!@\file_exists($testsDir)) {
|
||||
\mkdir($testsDir, 0777, \true);
|
||||
}
|
||||
$this->copyConfigurationFiles($codeceptionDir, $testsDir, $codeceptionYml, $envConfig, $acceptanceYml, $bootstrapScript);
|
||||
$this->execAndOutput('./vendor/bin/codecept bootstrap ' . $codeceptionDir, $output);
|
||||
$this->execAndOutput('./vendor/bin/codecept generate:activation acceptance ActivationCest', $output);
|
||||
$this->execAndOutput('./vendor/bin/codecept generate:woocommerce acceptance WooCommerceCest', $output);
|
||||
$this->injectTraitsIntoTesterClass($testsDir);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\Composer\Codeception\Commands;
|
||||
|
||||
use FcfVendor\Composer\Downloader\FilesystemException;
|
||||
use FcfVendor\Symfony\Component\Console\Input\InputInterface;
|
||||
use FcfVendor\Symfony\Component\Console\Output\OutputInterface;
|
||||
use FcfVendor\Symfony\Component\Yaml\Exception\ParseException;
|
||||
use FcfVendor\Symfony\Component\Yaml\Yaml;
|
||||
/**
|
||||
* Common methods for local Codeception tests.
|
||||
*/
|
||||
trait LocalCodeceptionTrait
|
||||
{
|
||||
private function getWpDeskConfiguration()
|
||||
{
|
||||
try {
|
||||
$wpdesk_configuration = \FcfVendor\Symfony\Component\Yaml\Yaml::parseFile(\getcwd() . '/tests/codeception/wpdesk.yml');
|
||||
} catch (\FcfVendor\Symfony\Component\Yaml\Exception\ParseException $e) {
|
||||
$wpdesk_configuration = array();
|
||||
}
|
||||
return \FcfVendor\WPDesk\Composer\Codeception\Commands\Configuration::createFromEnvAndConfiguration($wpdesk_configuration);
|
||||
}
|
||||
/**
|
||||
* @param OutputInterface $output
|
||||
* @param Configuration $configuration
|
||||
*/
|
||||
private function prepareWpConfig(\FcfVendor\Symfony\Component\Console\Output\OutputInterface $output, \FcfVendor\WPDesk\Composer\Codeception\Commands\Configuration $configuration)
|
||||
{
|
||||
$apache_document_root = $configuration->getApacheDocumentRoot();
|
||||
$this->executeWpCliAndOutput('config set WP_DEBUG true --raw', $output, $apache_document_root);
|
||||
$this->executeWpCliAndOutput('config set WP_DEBUG_LOG true --raw', $output, $apache_document_root);
|
||||
$this->executeWpCliAndOutput('config set WP_DEBUG_DISPLAY false --raw', $output, $apache_document_root);
|
||||
$this->executeWpCliAndOutput('config set WP_HOME ' . $configuration->getWptestsUrl(), $output, $apache_document_root);
|
||||
$this->executeWpCliAndOutput('config set WP_SITEURL ' . $configuration->getWptestsUrl(), $output, $apache_document_root);
|
||||
$this->executeWpCliAndOutput('config set WP_AUTO_UPDATE_CORE false --raw', $output, $apache_document_root);
|
||||
$this->executeWpCliAndOutput('config set AUTOMATIC_UPDATER_DISABLED false --raw', $output, $apache_document_root);
|
||||
$this->executeWpCliAndOutput('rewrite structure \'/%postname%/\'', $output, $apache_document_root);
|
||||
$this->replace_in_file($apache_document_root . '/wp-config.php', 'if ( isset( $_SERVER[\'HTTP_X_FORWARDED_PROTO\'] ) && \'https\' === $_SERVER[\'HTTP_X_FORWARDED_PROTO\'] ) { $_SERVER[\'HTTPS\'] = \'on\'; }', '');
|
||||
$this->replace_in_file($apache_document_root . '/wp-config.php', '<?php', '<?php if ( isset( $_SERVER[\'HTTP_X_FORWARDED_PROTO\'] ) && \'https\' === $_SERVER[\'HTTP_X_FORWARDED_PROTO\'] ) { $_SERVER[\'HTTPS\'] = \'on\'; }');
|
||||
}
|
||||
/**
|
||||
* @param string $filename
|
||||
* @param string $string_to_replace
|
||||
* @param string $replace_with
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function replace_in_file($filename, $string_to_replace, $replace_with)
|
||||
{
|
||||
$content = \file_get_contents($filename);
|
||||
$content_chunks = \explode($string_to_replace, $content);
|
||||
$content = \implode($replace_with, $content_chunks);
|
||||
\file_put_contents($filename, $content);
|
||||
}
|
||||
/**
|
||||
* @param OutputInterface $output
|
||||
* @param Configuration $configuration
|
||||
*/
|
||||
private function activatePlugins(\FcfVendor\Symfony\Component\Console\Output\OutputInterface $output, \FcfVendor\WPDesk\Composer\Codeception\Commands\Configuration $configuration)
|
||||
{
|
||||
$this->executeWpCliAndOutput('plugin deactivate --all', $output, $configuration->getApacheDocumentRoot());
|
||||
$plugins = '';
|
||||
foreach ($configuration->getRepositoryPlugins() as $plugin) {
|
||||
$plugins .= ' ' . $plugin;
|
||||
}
|
||||
if ($plugins) {
|
||||
$this->executeWpCliAndOutput('plugin install ' . $plugins, $output, $configuration->getApacheDocumentRoot());
|
||||
}
|
||||
foreach ($configuration->getLocalPlugins() as $plugin) {
|
||||
$source = $this->preparePathForRsync($this->prepareLocalPluginDir($plugin, $configuration->getDependentPluginsDir()) . '/*', $configuration::isWindows());
|
||||
$target = $this->preparePathForRsync($this->prepareTargetDir($plugin, $configuration) . '/', $configuration::isWindows());
|
||||
$rsync = 'rsync -a ' . $source . ' ' . $target . ' --exclude=node_modules --exclude=.git --exclude=tests --exclude=.idea';
|
||||
$output->writeln($rsync);
|
||||
$this->execAndOutput($rsync, $output);
|
||||
}
|
||||
$this->executeWpCliAndOutput('plugin status', $output, $configuration->getApacheDocumentRoot());
|
||||
$this->executeWpCliAndOutput('plugin list', $output, $configuration->getApacheDocumentRoot());
|
||||
foreach ($configuration->getActivatePlugins() as $plugin) {
|
||||
$this->executeWpCliAndOutput('plugin activate ' . $plugin, $output, $configuration->getApacheDocumentRoot());
|
||||
}
|
||||
$this->executeWpCliAndOutput('plugin activate ' . $configuration->getPluginDir(), $output, $configuration->getApacheDocumentRoot());
|
||||
}
|
||||
/**
|
||||
* @param string $plugin .
|
||||
*/
|
||||
private function prepareLocalPluginDir($plugin, $local_plugins_dir = \false)
|
||||
{
|
||||
if (!$local_plugins_dir) {
|
||||
$local_plugins_dir = \dirname(\getcwd());
|
||||
}
|
||||
return $this->trailingslashit($local_plugins_dir) . $plugin;
|
||||
}
|
||||
/**
|
||||
* @param $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function trailingslashit($string)
|
||||
{
|
||||
return \rtrim($string, '/\\') . '/';
|
||||
}
|
||||
/**
|
||||
* @param string $command
|
||||
* @param OutputInterface $output
|
||||
* @param string $apache_document_root
|
||||
*/
|
||||
private function executeWpCliAndOutput($command, \FcfVendor\Symfony\Component\Console\Output\OutputInterface $output, $apache_document_root)
|
||||
{
|
||||
$output->write("WPCLI: {$command}\n");
|
||||
$wp = "wp";
|
||||
$command = $wp . ' ' . $command . ' --allow-root --path=' . $apache_document_root;
|
||||
$this->execAndOutput($command, $output);
|
||||
}
|
||||
/**
|
||||
* @param string $plugin_dir
|
||||
* @param OutputInterface $output
|
||||
* @param Configuration $configuration
|
||||
* @param bool $coverage
|
||||
*/
|
||||
private function installPlugin(string $plugin_dir, \FcfVendor\Symfony\Component\Console\Output\OutputInterface $output, \FcfVendor\WPDesk\Composer\Codeception\Commands\Configuration $configuration, bool $coverage = \true)
|
||||
{
|
||||
$source = $this->preparePathForRsync(\getcwd() . '/*', $configuration::isWindows());
|
||||
$target = $this->preparePathForRsync($this->prepareTargetDir($plugin_dir, $configuration) . '/', $configuration::isWindows());
|
||||
$rsync = 'rsync -av ' . $source . ' ' . $target . ' --exclude=node_modules --exclude=.git --exclude=.idea --exclude=vendor --exclude=vendor_prefixed --exclude=tests/wordpress ';
|
||||
$this->execAndOutput($rsync, $output);
|
||||
\copy(\getcwd() . '/.env.testing', $this->prepareTargetDir($plugin_dir, $configuration) . '/.env.testing');
|
||||
if (!$coverage) {
|
||||
$this->execAndOutput('composer install --working-dir=' . $configuration->getApacheDocumentRoot() . '/wp-content/plugins/' . $plugin_dir, $output);
|
||||
$this->execAndOutput('composer install --no-dev --working-dir=' . $configuration->getApacheDocumentRoot() . '/wp-content/plugins/' . $plugin_dir, $output);
|
||||
} else {
|
||||
$this->execAndOutput('composer require --dev codeception/c3 --working-dir=' . $configuration->getApacheDocumentRoot() . '/wp-content/plugins/' . $plugin_dir, $output);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param string $path
|
||||
* @param bool $is_windows
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function preparePathForRsync($path, $is_windows)
|
||||
{
|
||||
if ($is_windows) {
|
||||
$path = '/cygdrive/' . $path;
|
||||
$path = \str_replace(':', '', $path);
|
||||
$path = \str_replace('\\', '/', $path);
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
/**
|
||||
* @param string $plugin_slug
|
||||
* @param Configuration $configuration
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function prepareTargetDir($plugin_slug, \FcfVendor\WPDesk\Composer\Codeception\Commands\Configuration $configuration)
|
||||
{
|
||||
return $configuration->getApacheDocumentRoot() . '/wp-content/plugins/' . $plugin_slug;
|
||||
}
|
||||
/**
|
||||
* @param Configuration $configuration
|
||||
* @param OutputInterface $output
|
||||
*/
|
||||
private function prepareCommonWpWcConfiguration(\FcfVendor\WPDesk\Composer\Codeception\Commands\Configuration $configuration, \FcfVendor\Symfony\Component\Console\Output\OutputInterface $output)
|
||||
{
|
||||
$this->executeWpCliAndOutput('db reset --yes', $output, $configuration->getApacheDocumentRoot());
|
||||
$this->executeWpCliAndOutput('core install --url=' . $configuration->getWptestsIp() . ' --title=Woo-tests --admin_user=admin --admin_password=admin --admin_email=grola@seostudio.pl --skip-email', $output, $configuration->getApacheDocumentRoot());
|
||||
$commands = array('theme activate storefront-wpdesk-tests', 'plugin activate woocommerce');
|
||||
$commands = \array_merge($commands, $this->prepareWcOptionsCommands(), $this->prepareTaxes(), $this->prepareShippingMethods(), $this->prepareWooCommercePages(), $this->prepareCustomer(), $this->prepareDisableRESTApiPermissions(), $this->prepareCreateProductsCommands(), $configuration->getPrepareDatabase());
|
||||
foreach ($commands as $command) {
|
||||
$this->executeWpCliAndOutput($command, $output, $configuration->getApacheDocumentRoot());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function prepareWcOptionsCommands()
|
||||
{
|
||||
return array('option update woocommerce_admin_notices \'{}\'', 'option update storefront_nux_dismissed 1', 'option set woocommerce_store_address "al. Jana Pawła 12"', 'option set woocommerce_store_address_2 ""', 'option set woocommerce_store_city "Warszawa"', 'option set woocommerce_default_country "PL"', 'option set woocommerce_store_postalcode "22-100"', 'option set woocommerce_currency "PLN"', 'option set woocommerce_currency_pos "right_space"', 'option set woocommerce_product_type "physical"', 'option set woocommerce_allow_tracking "no"', 'option set --format=json woocommerce_stripe_settings \'{"enabled":"no","create_account":false,"email":false}\'', 'option set --format=json woocommerce_ppec_paypal_settings \'{"reroute_requests":false,"email":false}\'', 'option set --format=json woocommerce_cheque_settings \'{"enabled":"no"}\'', 'option set --format=json woocommerce_bacs_settings \'{"enabled":"no"}\'', 'option set --format=json woocommerce_cod_settings \'{"enabled":"yes"}\'', 'option set --format=json woocommerce_onboarding_profile \'{"skipped":true}\'', 'option set --format=json wc-admin-onboarding-profiler-reminder \'{"skipped":true}\'', 'option get woocommerce_onboarding_profile', 'option set woocommerce_task_list_hidden "yes"', 'option set woocommerce_task_list_hidden "yes"', 'option set woocommerce_show_marketplace_suggestions "no"');
|
||||
}
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private function prepareTaxes()
|
||||
{
|
||||
return array('wc tax create --country="PL" --rate=23 --name=VAT --shipping=true --user=admin', 'option set woocommerce_calc_taxes "yes"');
|
||||
}
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private function prepareShippingMethods()
|
||||
{
|
||||
return array('wc shipping_zone_method create 0 --method_id="flat_rate" --settings=\'{"title": "Flat rate", "cost":1, "tax_status": "taxable"}\' --enabled=true --user=admin');
|
||||
}
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private function prepareWooCommercePages()
|
||||
{
|
||||
return array('wc --user=admin tool run install_pages');
|
||||
}
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private function prepareCustomer()
|
||||
{
|
||||
return array('wc customer create --email=\'customer@woo.local\' --username="customer" --billing=\'{"first_name":"First","last_name":"Last","company":"WPDesk","address_1":"Street 1","city":"City","postcode": "53-030", "country": "PL", "phone": "012345678"}\' --password=\'customer\' --user=admin');
|
||||
}
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private function prepareDisableRESTApiPermissions()
|
||||
{
|
||||
return array('option set wpdesk_rest_api_disable_permissions "1"');
|
||||
}
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function prepareCreateProductsCommands()
|
||||
{
|
||||
return array($this->prepareCreateProductCommand('100', '100'), $this->prepareCreateProductCommand('10', '10'), $this->prepareCreateProductCommand('9', '9'), $this->prepareCreateProductCommand('1', '1'), $this->prepareCreateProductCommand('09', '0.9'), $this->prepareCreateProductCommand('009', '0.09'), $this->prepareCreateProductCommand('01', '0.1'), $this->prepareCreateProductCommand('001', '0.01'), $this->prepareCreateProductCommand('0001', '0.001'), $this->prepareCreateProductCommand('00001', '0.0001'));
|
||||
}
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $price
|
||||
* @param null|string $weight
|
||||
* @param null|string $sku
|
||||
* @param null|string $dimensions
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function prepareCreateProductCommand($name, $price, $weight = null, $sku = null, $dimensions = null)
|
||||
{
|
||||
$product_name = "Product {$name}";
|
||||
$weight = $weight ? $weight : $price;
|
||||
$sku = $sku ? $sku : 'product-' . $name;
|
||||
$dimensions = $dimensions ? $dimensions : '{"width":"' . $price . '","length":"' . $price . '","height":"' . $price . '"}';
|
||||
return "wc product create --name=\"{$product_name}\" --virtual=false --downloadable=false --type=simple --sku={$sku} --regular_price={$price} --weight={$weight} --dimensions='{$dimensions}' --user=admin";
|
||||
}
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @param bool $coverage
|
||||
*
|
||||
* @throws \Composer\Downloader\FilesystemException
|
||||
*/
|
||||
private function prepareLocalCodeceptionTests(\FcfVendor\Symfony\Component\Console\Input\InputInterface $input, \FcfVendor\Symfony\Component\Console\Output\OutputInterface $output, bool $coverage = \false)
|
||||
{
|
||||
$configuration = $this->getWpDeskConfiguration();
|
||||
$this->installPlugin($configuration->getPluginDir(), $output, $configuration, $coverage);
|
||||
$this->activatePlugins($output, $configuration);
|
||||
$this->prepareWpConfig($output, $configuration);
|
||||
$this->copyThemeFiles($configuration->getThemeFiles(), $configuration->getApacheDocumentRoot() . '/wp-content/themes/storefront-wpdesk-tests');
|
||||
$sep = \DIRECTORY_SEPARATOR;
|
||||
$codecept = "vendor{$sep}bin{$sep}codecept";
|
||||
$cleanOutput = $codecept . ' clean';
|
||||
$this->execAndOutput($cleanOutput, $output);
|
||||
}
|
||||
/**
|
||||
* @param array $theme_files
|
||||
* @param $theme_folder
|
||||
*
|
||||
* @throws FilesystemException
|
||||
*/
|
||||
private function copyThemeFiles(array $theme_files, $theme_folder)
|
||||
{
|
||||
foreach ($theme_files as $theme_file) {
|
||||
if (!\copy($theme_file, $this->trailingslashit($theme_folder) . \basename($theme_file))) {
|
||||
throw new \FcfVendor\Composer\Downloader\FilesystemException('Error copying theme file: ' . $theme_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\Composer\Codeception\Commands;
|
||||
|
||||
use FcfVendor\Symfony\Component\Console\Input\InputArgument;
|
||||
use FcfVendor\Symfony\Component\Console\Input\InputInterface;
|
||||
use FcfVendor\Symfony\Component\Console\Output\OutputInterface;
|
||||
use FcfVendor\Symfony\Component\Yaml\Exception\ParseException;
|
||||
use FcfVendor\Symfony\Component\Yaml\Yaml;
|
||||
/**
|
||||
* Prepare Database for Codeception tests command.
|
||||
*
|
||||
* @package WPDesk\Composer\Codeception\Commands
|
||||
*/
|
||||
class PrepareCodeceptionDb extends \FcfVendor\WPDesk\Composer\Codeception\Commands\BaseCommand
|
||||
{
|
||||
use LocalCodeceptionTrait;
|
||||
/**
|
||||
* Configure command.
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
$this->setName('prepare-codeception-db')->setDescription('Prepare codeception database.');
|
||||
}
|
||||
/**
|
||||
* Execute command.
|
||||
*
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
*
|
||||
* @return int 0 if everything went fine, or an error code
|
||||
*/
|
||||
protected function execute(\FcfVendor\Symfony\Component\Console\Input\InputInterface $input, \FcfVendor\Symfony\Component\Console\Output\OutputInterface $output)
|
||||
{
|
||||
$configuration = $this->getWpDeskConfiguration();
|
||||
$this->installPlugin($configuration->getPluginDir(), $output, $configuration);
|
||||
$this->prepareCommonWpWcConfiguration($configuration, $output);
|
||||
$this->prepareWpConfig($output, $configuration);
|
||||
$this->activatePlugins($output, $configuration);
|
||||
$this->executeWpCliAndOutput('db export ' . \getcwd() . '/tests/codeception/tests/_data/db.sql', $output, $configuration->getApacheDocumentRoot());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\Composer\Codeception\Commands;
|
||||
|
||||
use FcfVendor\Composer\Downloader\FilesystemException;
|
||||
use FcfVendor\Symfony\Component\Console\Input\InputArgument;
|
||||
use FcfVendor\Symfony\Component\Console\Input\InputInterface;
|
||||
use FcfVendor\Symfony\Component\Console\Output\OutputInterface;
|
||||
use FcfVendor\Symfony\Component\Yaml\Exception\ParseException;
|
||||
use FcfVendor\Symfony\Component\Yaml\Yaml;
|
||||
/**
|
||||
* Codeception tests run command.
|
||||
*
|
||||
* @package WPDesk\Composer\Codeception\Commands
|
||||
*/
|
||||
class PrepareLocalCodeceptionTests extends \FcfVendor\WPDesk\Composer\Codeception\Commands\RunCodeceptionTests
|
||||
{
|
||||
use LocalCodeceptionTrait;
|
||||
/**
|
||||
* Configure command.
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
$this->setName('prepare-local-codeception-tests')->setDescription('Prepare local codeception tests.');
|
||||
}
|
||||
/**
|
||||
* Execute command.
|
||||
*
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
*
|
||||
* @return int 0 if everything went fine, or an error code
|
||||
*/
|
||||
protected function execute(\FcfVendor\Symfony\Component\Console\Input\InputInterface $input, \FcfVendor\Symfony\Component\Console\Output\OutputInterface $output)
|
||||
{
|
||||
$this->prepareLocalCodeceptionTests($input, $output, \false);
|
||||
return 0;
|
||||
}
|
||||
/**
|
||||
* @param array $theme_files
|
||||
* @param $theme_folder
|
||||
*
|
||||
* @throws FilesystemException
|
||||
*/
|
||||
private function copyThemeFiles(array $theme_files, $theme_folder)
|
||||
{
|
||||
foreach ($theme_files as $theme_file) {
|
||||
if (!\copy($theme_file, $this->trailingslashit($theme_folder) . \basename($theme_file))) {
|
||||
throw new \FcfVendor\Composer\Downloader\FilesystemException('Error copying theme file: ' . $theme_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\Composer\Codeception\Commands;
|
||||
|
||||
use FcfVendor\Composer\Downloader\FilesystemException;
|
||||
use FcfVendor\Symfony\Component\Console\Input\InputArgument;
|
||||
use FcfVendor\Symfony\Component\Console\Input\InputInterface;
|
||||
use FcfVendor\Symfony\Component\Console\Output\OutputInterface;
|
||||
use FcfVendor\Symfony\Component\Yaml\Exception\ParseException;
|
||||
use FcfVendor\Symfony\Component\Yaml\Yaml;
|
||||
/**
|
||||
* Codeception tests run command.
|
||||
*
|
||||
* @package WPDesk\Composer\Codeception\Commands
|
||||
*/
|
||||
class PrepareLocalCodeceptionTestsWithCoverage extends \FcfVendor\WPDesk\Composer\Codeception\Commands\RunCodeceptionTests
|
||||
{
|
||||
use LocalCodeceptionTrait;
|
||||
/**
|
||||
* Configure command.
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
$this->setName('prepare-local-codeception-tests-with-coverage')->setDescription('Prepare local codeception tests.');
|
||||
}
|
||||
/**
|
||||
* Execute command.
|
||||
*
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @return void
|
||||
*/
|
||||
protected function execute(\FcfVendor\Symfony\Component\Console\Input\InputInterface $input, \FcfVendor\Symfony\Component\Console\Output\OutputInterface $output)
|
||||
{
|
||||
$this->prepareLocalCodeceptionTests($input, $output, \true);
|
||||
$configuration = $this->getWpDeskConfiguration();
|
||||
$plugin_file = $configuration->getApacheDocumentRoot() . '/wp-content/plugins/' . $configuration->getPluginFile();
|
||||
\file_put_contents($plugin_file, "\ndefine('C3_CODECOVERAGE_ERROR_LOG_FILE', '/tmp/c3_error.log'); include __DIR__ . '/c3.php';", \FILE_APPEND);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\Composer\Codeception\Commands;
|
||||
|
||||
use FcfVendor\Symfony\Component\Console\Input\InputArgument;
|
||||
use FcfVendor\Symfony\Component\Console\Input\InputInterface;
|
||||
use FcfVendor\Symfony\Component\Console\Output\OutputInterface;
|
||||
use FcfVendor\Symfony\Component\Yaml\Exception\ParseException;
|
||||
use FcfVendor\Symfony\Component\Yaml\Yaml;
|
||||
/**
|
||||
* Split test to multiple directories for parallel running in CI.
|
||||
*
|
||||
* @package WPDesk\Composer\Codeception\Commands
|
||||
*/
|
||||
class PrepareParallelCodeceptionTests extends \FcfVendor\WPDesk\Composer\Codeception\Commands\BaseCommand
|
||||
{
|
||||
const NUMBER_OF_JOBS = 'number_of_jobs';
|
||||
/**
|
||||
* Configure command.
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
$this->setName('prepare-parallel-codeception-tests')->setDescription('Prepare parallel codeception tests.')->setDefinition(array(new \FcfVendor\Symfony\Component\Console\Input\InputArgument(self::NUMBER_OF_JOBS, \FcfVendor\Symfony\Component\Console\Input\InputArgument::OPTIONAL, 'Number of jobs.', '4')));
|
||||
}
|
||||
/**
|
||||
* Execute command.
|
||||
*
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @return void
|
||||
*/
|
||||
protected function execute(\FcfVendor\Symfony\Component\Console\Input\InputInterface $input, \FcfVendor\Symfony\Component\Console\Output\OutputInterface $output)
|
||||
{
|
||||
$numberOfJobs = (int) $input->getArgument(self::NUMBER_OF_JOBS);
|
||||
$acceptanceTestsDir = \getcwd() . '/tests/codeception/tests/acceptance';
|
||||
for ($i = 1; $i <= $numberOfJobs; $i++) {
|
||||
$parallelDir = $acceptanceTestsDir . '/' . $i;
|
||||
if (!\file_exists($parallelDir)) {
|
||||
\mkdir($parallelDir);
|
||||
}
|
||||
}
|
||||
$currentIndex = 1;
|
||||
$files = \scandir($acceptanceTestsDir);
|
||||
foreach ($files as $fileName) {
|
||||
$fileFullPath = $acceptanceTestsDir . '/' . $fileName;
|
||||
if (!\is_dir($fileFullPath)) {
|
||||
$targetPath = $acceptanceTestsDir . '/' . $currentIndex . '/' . $fileName;
|
||||
\copy($fileFullPath, $targetPath);
|
||||
$currentIndex++;
|
||||
if ($currentIndex > $numberOfJobs) {
|
||||
$currentIndex = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\Composer\Codeception\Commands;
|
||||
|
||||
use FcfVendor\Symfony\Component\Console\Input\InputArgument;
|
||||
use FcfVendor\Symfony\Component\Console\Input\InputInterface;
|
||||
use FcfVendor\Symfony\Component\Console\Output\OutputInterface;
|
||||
use FcfVendor\Symfony\Component\Yaml\Exception\ParseException;
|
||||
use FcfVendor\Symfony\Component\Yaml\Yaml;
|
||||
/**
|
||||
* Prepare Database for Codeception tests command.
|
||||
*
|
||||
* @package WPDesk\Composer\Codeception\Commands
|
||||
*/
|
||||
class PrepareWordpressForCodeception extends \FcfVendor\WPDesk\Composer\Codeception\Commands\BaseCommand
|
||||
{
|
||||
use LocalCodeceptionTrait;
|
||||
/**
|
||||
* Configure command.
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
$this->setName('prepare-wordpress-for-codeception')->setDescription('Prepare wordpress installation for codeception tests.');
|
||||
}
|
||||
/**
|
||||
* Execute command.
|
||||
*
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
*
|
||||
* @return int 0 if everything went fine, or an error code
|
||||
*/
|
||||
protected function execute(\FcfVendor\Symfony\Component\Console\Input\InputInterface $input, \FcfVendor\Symfony\Component\Console\Output\OutputInterface $output)
|
||||
{
|
||||
$configuration = $this->getWpDeskConfiguration();
|
||||
$this->installWP($output, $configuration);
|
||||
return 0;
|
||||
}
|
||||
/**
|
||||
* @param OutputInterface $output
|
||||
* @param Configuration $configuration
|
||||
*/
|
||||
private function installWP(\FcfVendor\Symfony\Component\Console\Output\OutputInterface $output, \FcfVendor\WPDesk\Composer\Codeception\Commands\Configuration $configuration)
|
||||
{
|
||||
if (!\file_exists($configuration->getApacheDocumentRoot())) {
|
||||
\mkdir($configuration->getApacheDocumentRoot(), 0777, \true);
|
||||
}
|
||||
$dbhost = $configuration->getDbhost();
|
||||
$dbname = $configuration->getDbname();
|
||||
$dbuser = $configuration->getDbuser();
|
||||
$dbpassword = $configuration->getDbpassword();
|
||||
$url = $configuration->getWptestsIp();
|
||||
$apache_document_root = $configuration->getApacheDocumentRoot();
|
||||
$this->executeWpCliAndOutput('core download --force', $output, $apache_document_root);
|
||||
$this->executeWpCliAndOutput("core config --dbhost={$dbhost} --dbname={$dbname} --dbuser={$dbuser} --dbpass={$dbpassword}", $output, $apache_document_root);
|
||||
$this->executeWpCliAndOutput("core install --url={$url} --title=Woo-tests --admin_user=admin --admin_password=admin --admin_email=tests@wpdesk.dev --skip-email", $output, $apache_document_root);
|
||||
\copy('./vendor/wpdesk/wp-codeception/wordpress/htaccess', $apache_document_root . '/.htaccess');
|
||||
$this->executeWpCliAndOutput('rewrite structure \'/%postname%/\'', $output, $apache_document_root);
|
||||
$this->executeWpCliAndOutput('plugin install woocommerce', $output, $apache_document_root);
|
||||
$this->executeWpCliAndOutput('theme activate storefront', $output, $apache_document_root);
|
||||
$this->executeWpCliAndOutput('theme delete storefront-wpdesk-tests', $output, $apache_document_root);
|
||||
$this->executeWpCliAndOutput('theme install storefront', $output, $apache_document_root);
|
||||
$this->executeWpCliAndOutput('theme install https://gitlab.com/wpdesk/storefront-wpdesk-tests/-/archive/master/storefront-wpdesk-tests-master.zip', $output, $apache_document_root);
|
||||
\rename($apache_document_root . '/wp-content/themes/storefront-wpdesk-tests-master', $apache_document_root . '/wp-content/themes/storefront-wpdesk-tests');
|
||||
$this->executeWpCliAndOutput('theme activate storefront-wpdesk-tests', $output, $apache_document_root);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\Composer\Codeception\Commands;
|
||||
|
||||
use FcfVendor\Symfony\Component\Console\Input\InputArgument;
|
||||
use FcfVendor\Symfony\Component\Console\Input\InputInterface;
|
||||
use FcfVendor\Symfony\Component\Console\Output\OutputInterface;
|
||||
/**
|
||||
* Codeception tests run command.
|
||||
*
|
||||
* @package WPDesk\Composer\Codeception\Commands
|
||||
*/
|
||||
class RunCodeceptionTests extends \FcfVendor\WPDesk\Composer\Codeception\Commands\BaseCommand
|
||||
{
|
||||
const SINGLE = 'single';
|
||||
const FAST = 'fast';
|
||||
const WOOCOMMERCE_VERSION = 'woo_version';
|
||||
/**
|
||||
* Configure command.
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
$this->setName('run-codeception-tests')->setDescription('Run codeception tests.')->setDefinition(array(new \FcfVendor\Symfony\Component\Console\Input\InputArgument(self::SINGLE, \FcfVendor\Symfony\Component\Console\Input\InputArgument::OPTIONAL, 'Name of Single test to run.', 'all'), new \FcfVendor\Symfony\Component\Console\Input\InputArgument(self::FAST, \FcfVendor\Symfony\Component\Console\Input\InputArgument::OPTIONAL, 'Fast tests - do not shutdown docker-compose.', 'slow'), new \FcfVendor\Symfony\Component\Console\Input\InputArgument(self::WOOCOMMERCE_VERSION, \FcfVendor\Symfony\Component\Console\Input\InputArgument::OPTIONAL, 'WooCommerce version to install.', '')));
|
||||
}
|
||||
/**
|
||||
* Execute command.
|
||||
*
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
*
|
||||
* @return int 0 if everything went fine, or an error code
|
||||
*/
|
||||
protected function execute(\FcfVendor\Symfony\Component\Console\Input\InputInterface $input, \FcfVendor\Symfony\Component\Console\Output\OutputInterface $output)
|
||||
{
|
||||
$dockerComposeYaml = 'vendor/wpdesk/wp-codeception/docker/docker-compose.yaml';
|
||||
$singleTest = $input->getArgument(self::SINGLE);
|
||||
$fastTest = $input->getArgument(self::FAST);
|
||||
$wooVersion = $input->getArgument(self::WOOCOMMERCE_VERSION);
|
||||
$cache_dir = \sys_get_temp_dir() . '/codeception_cache';
|
||||
if (!\file_exists($cache_dir)) {
|
||||
\mkdir($cache_dir, 0777, \true);
|
||||
}
|
||||
\putenv('TMP_CACHE_DIR=' . $cache_dir);
|
||||
$codecept_param = ' --html --verbose -f ';
|
||||
$additionalParameters = ' -e CODECEPT_PARAM="' . $codecept_param . '" ';
|
||||
if (!empty($singleTest) && 'all' !== $singleTest) {
|
||||
$additionalParameters .= ' -e CODECEPT_PARAM="' . $codecept_param . ' acceptance ' . $singleTest . '" ';
|
||||
}
|
||||
if (!empty($wooVersion)) {
|
||||
$additionalParameters .= ' -e WOOCOMMERCE_VERSION="' . $wooVersion . '" ';
|
||||
}
|
||||
$runTestsCommand = 'docker-compose -f ' . $dockerComposeYaml . ' run ' . $additionalParameters . 'codecept';
|
||||
$output->writeln('Codeception command: ' . $runTestsCommand);
|
||||
$this->execAndOutput($runTestsCommand, $output);
|
||||
if (empty($fastTest) || self::FAST !== $fastTest) {
|
||||
$this->execAndOutput('docker-compose -f ' . $dockerComposeYaml . ' down -v', $output);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\Composer\Codeception\Commands;
|
||||
|
||||
use FcfVendor\Symfony\Component\Console\Input\InputArgument;
|
||||
use FcfVendor\Symfony\Component\Console\Input\InputInterface;
|
||||
use FcfVendor\Symfony\Component\Console\Output\OutputInterface;
|
||||
use FcfVendor\Symfony\Component\Yaml\Exception\ParseException;
|
||||
use FcfVendor\Symfony\Component\Yaml\Yaml;
|
||||
/**
|
||||
* Codeception tests run command.
|
||||
*
|
||||
* @package WPDesk\Composer\Codeception\Commands
|
||||
*/
|
||||
class RunLocalCodeceptionTests extends \FcfVendor\WPDesk\Composer\Codeception\Commands\RunCodeceptionTests
|
||||
{
|
||||
use LocalCodeceptionTrait;
|
||||
/**
|
||||
* Configure command.
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
$this->setName('run-local-codeception-tests')->setDescription('Run local codeception tests.')->setDefinition(array(new \FcfVendor\Symfony\Component\Console\Input\InputArgument(self::SINGLE, \FcfVendor\Symfony\Component\Console\Input\InputArgument::OPTIONAL, 'Name of Single test to run.', ' ')));
|
||||
}
|
||||
/**
|
||||
* Execute command.
|
||||
*
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
*
|
||||
* @return int 0 if everything went fine, or an error code
|
||||
*/
|
||||
protected function execute(\FcfVendor\Symfony\Component\Console\Input\InputInterface $input, \FcfVendor\Symfony\Component\Console\Output\OutputInterface $output)
|
||||
{
|
||||
$configuration = $this->getWpDeskConfiguration();
|
||||
$this->prepareWpConfig($output, $configuration);
|
||||
$singleTest = $input->getArgument(self::SINGLE);
|
||||
$sep = \DIRECTORY_SEPARATOR;
|
||||
$codecept = "vendor{$sep}bin{$sep}codecept";
|
||||
$cleanOutput = $codecept . ' clean';
|
||||
$this->execAndOutput($cleanOutput, $output);
|
||||
$runLocalTests = $codecept . ' run -f --steps --html --verbose acceptance ' . $singleTest;
|
||||
$this->execAndOutput($runLocalTests, $output);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\Composer\Codeception\Commands;
|
||||
|
||||
use FcfVendor\Symfony\Component\Console\Input\InputArgument;
|
||||
use FcfVendor\Symfony\Component\Console\Input\InputInterface;
|
||||
use FcfVendor\Symfony\Component\Console\Output\OutputInterface;
|
||||
use FcfVendor\Symfony\Component\Yaml\Exception\ParseException;
|
||||
use FcfVendor\Symfony\Component\Yaml\Yaml;
|
||||
/**
|
||||
* Codeception tests run command.
|
||||
*
|
||||
* @package WPDesk\Composer\Codeception\Commands
|
||||
*/
|
||||
class RunLocalCodeceptionTestsWithCoverage extends \FcfVendor\WPDesk\Composer\Codeception\Commands\RunCodeceptionTests
|
||||
{
|
||||
use LocalCodeceptionTrait;
|
||||
/**
|
||||
* Configure command.
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
$this->setName('run-local-codeception-tests-with-coverage')->setDescription('Run local codeception tests.')->setDefinition(array(new \FcfVendor\Symfony\Component\Console\Input\InputArgument(self::SINGLE, \FcfVendor\Symfony\Component\Console\Input\InputArgument::OPTIONAL, 'Name of Single test to run.', ' ')));
|
||||
}
|
||||
/**
|
||||
* Execute command.
|
||||
*
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
*
|
||||
* @return int 0 if everything went fine, or an error code
|
||||
*/
|
||||
protected function execute(\FcfVendor\Symfony\Component\Console\Input\InputInterface $input, \FcfVendor\Symfony\Component\Console\Output\OutputInterface $output)
|
||||
{
|
||||
$configuration = $this->getWpDeskConfiguration();
|
||||
$this->prepareWpConfig($output, $configuration);
|
||||
$singleTest = $input->getArgument(self::SINGLE);
|
||||
$sep = \DIRECTORY_SEPARATOR;
|
||||
$codecept = "vendor{$sep}bin{$sep}codecept";
|
||||
$cleanOutput = $codecept . ' clean';
|
||||
$this->execAndOutput($cleanOutput, $output);
|
||||
$runLocalTests = $codecept . ' run -f --steps --html --coverage --coverage-xml --coverage-html --verbose acceptance ' . $singleTest;
|
||||
$this->execAndOutput($runLocalTests, $output);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\Composer\Codeception\Commands;
|
||||
|
||||
/**
|
||||
* Trait with a sed like command
|
||||
* @see https://pl.wikipedia.org/wiki/Sed_(program)
|
||||
*
|
||||
* @package WPDesk\Composer\GitPlugin\Command
|
||||
*/
|
||||
trait SedTrait
|
||||
{
|
||||
/**
|
||||
* SED.
|
||||
*
|
||||
* @param string $file_pattern .
|
||||
* @param string $pattern .
|
||||
* @param string $replace .
|
||||
*
|
||||
* @return string[] array of changed files
|
||||
*/
|
||||
private function wpdeskSed($file_pattern, $pattern, $replace)
|
||||
{
|
||||
$changed_files = [];
|
||||
foreach (\glob($file_pattern) as $filename) {
|
||||
$input = \file_get_contents($filename);
|
||||
$output = \preg_replace($pattern, $replace, $input);
|
||||
if ($output !== $input) {
|
||||
$changed_files[] = $filename;
|
||||
\file_put_contents($filename, $output);
|
||||
}
|
||||
}
|
||||
return $changed_files;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class SettingsException
|
||||
* @package WPDesk\Composer\Codeception\Commands
|
||||
*/
|
||||
namespace FcfVendor\WPDesk\Composer\Codeception\Commands;
|
||||
|
||||
/**
|
||||
* Settings Exception.
|
||||
*/
|
||||
class SettingsException extends \RuntimeException
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace FcfVendor\WPDesk\Composer\Codeception;
|
||||
|
||||
use FcfVendor\Composer\Composer;
|
||||
use FcfVendor\Composer\IO\IOInterface;
|
||||
use FcfVendor\Composer\Plugin\Capable;
|
||||
use FcfVendor\Composer\Plugin\PluginInterface;
|
||||
/**
|
||||
* Composer plugin.
|
||||
*
|
||||
* @package WPDesk\Composer\Codeception
|
||||
*/
|
||||
class Plugin implements \FcfVendor\Composer\Plugin\PluginInterface, \FcfVendor\Composer\Plugin\Capable
|
||||
{
|
||||
/**
|
||||
* @var Composer
|
||||
*/
|
||||
private $composer;
|
||||
/**
|
||||
* @var IOInterface
|
||||
*/
|
||||
private $io;
|
||||
public function activate(\FcfVendor\Composer\Composer $composer, \FcfVendor\Composer\IO\IOInterface $io)
|
||||
{
|
||||
$this->composer = $composer;
|
||||
$this->io = $io;
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function deactivate(\FcfVendor\Composer\Composer $composer, \FcfVendor\Composer\IO\IOInterface $io)
|
||||
{
|
||||
$this->composer = $composer;
|
||||
$this->io = $io;
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function uninstall(\FcfVendor\Composer\Composer $composer, \FcfVendor\Composer\IO\IOInterface $io)
|
||||
{
|
||||
$this->composer = $composer;
|
||||
$this->io = $io;
|
||||
}
|
||||
public function getCapabilities()
|
||||
{
|
||||
return [\FcfVendor\Composer\Plugin\Capability\CommandProvider::class => \FcfVendor\WPDesk\Composer\Codeception\CommandProvider::class];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user