Skip to content
Snippets Groups Projects
Commit fefd6432 authored by Krzysiek's avatar Krzysiek Committed by Grzegorz Rola
Browse files

Devel tests

parent b1908822
No related branches found
No related tags found
No related merge requests found
before_script:
- cd /builds/wpdesk/plugin-template/
variables:
MYSQL_ROOT_PASSWORD: mysql
MYSQL_DATABASE: wptest
MYSQL_USER: mysql
MYSQL_PASSWORD: mysql
MYSQL_INNODB_LOG_BUFFER_SIZE: 32M
PHP_ERROR_REPORTING: E_ALL
GIT_STRATEGY: fetch
cache:
untracked: true
paths:
- vendor
stages:
- build
- tests
- docs
- pre-deploy
- deploy
build php:
image: wpdesknet/phpunit-woocommerce:0-0
stage: build
artifacts:
name: "dev vendor"
paths:
- vendor/
script:
- wget -nc https://getcomposer.org/download/1.6.3/composer.phar
- wget -nc https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
- php composer.phar install --no-progress
#build js:
# image: node:slim
# stage: build
# script:
# - cd app
# - git clone git@gitlab.com:wpdesk/plugins-tests.git
# - cd plugins-tests
# - npm install
# - grunt dev-chrome
code style test:
image: wpdesknet/phpunit-woocommerce:0-0
stage: tests
allow_failure: true
dependencies:
- build php
script:
- ls -l
- php --version
- php composer.phar phpcs
unit test 0:
image: wpdesknet/phpunit-woocommerce:0-0
stage: tests
dependencies:
- build php
coverage: '/^\s*Lines:\s*\d+.\d+\%/'
script:
- ls -l
- php --version
- php composer.phar phpunit-unit
integration test 0-0:
image: wpdesknet/phpunit-woocommerce:0-0
services:
- mysql
stage: tests
dependencies:
- build php
script:
- php --version
- php composer.phar phpunit-integration
integration test 1-1:
image: wpdesknet/phpunit-woocommerce:1-1
services:
- mysql
stage: tests
dependencies:
- build php
script:
- php --version
- php composer.phar phpunit-integration
integration test 2-2:
image: wpdesknet/phpunit-woocommerce:2-2
services:
- mysql
stage: tests
dependencies:
- build php
script:
- php --version
- php composer.phar phpunit-integration
integration test 3-3:
image: wpdesknet/phpunit-woocommerce:3-3
services:
- mysql
stage: tests
dependencies:
- build php
script:
- php --version
- phpunit --configuration phpunit-integration.xml
integration test 4-3:
image: wpdesknet/phpunit-woocommerce:4-3
services:
- mysql
stage: tests
dependencies:
- build php
script:
- php --version
- phpunit --configuration phpunit-integration.xml
# apigen requires PHP 7.1
apigen docs:
image: wpdesknet/phpunit-woocommerce:1-0
stage: docs
dependencies:
- build php
artifacts:
name: "docs"
paths:
- docs/
script:
- ls -l
- php --version
- php composer.phar docs
only:
- tags
build to deploy:
image: wpdesknet/phpunit-woocommerce:0-0
stage: pre-deploy
dependencies:
- build php
artifacts:
name: "production vendor"
paths:
- vendor/
script:
- php --version
- php composer.phar install --no-dev --no-progress
deploy to void:
image: wpdesknet/phpunit-woocommerce:0-0
stage: deploy
dependencies:
- build to deploy
script:
- echo void
when: manual
only:
- tags
\ No newline at end of file
destination: docs
extensions: [php]
source:
- classes
- plugin-template.php
- bootstrap.php
exclude:
- vendor
- tests
- languages
charset: [UTF-8]
main: Wordpress plugin
title: Plugin template more info
baseUrl: "/"
templateTheme: default
php: false
sourceCode: false
tree: false
deprecated: false
todo: false
download: false
accessLevels:
- public
- private
- protected
\ No newline at end of file
......@@ -15,7 +15,8 @@
"squizlabs/php_codesniffer": "^3.0.2",
"mockery/mockery": "^1.0",
"10up/wp_mock": "^0.3",
"wimg/php-compatibility": "^8"
"wimg/php-compatibility": "^8",
"apigen/apigen": "^4.1"
},
"autoload-dev": {
"psr-4": {
......@@ -23,6 +24,10 @@
}
},
"scripts": {
"phpcs": "vendor/bin/phpcs"
"test": "echo composer is alive",
"phpcs": "phpcs",
"phpunit-unit": "phpunit --configuration phpunit-unit.xml",
"phpunit-integration": "phpunit --configuration phpunit-integration.xml",
"docs": "apigen generate"
}
}
This diff is collapsed.
<phpunit bootstrap="tests/integration/bootstrap.php"
backupGlobals="false"
>
<testsuites>
<testsuite>
<directory prefix="test-" suffix=".php">./tests/integration</directory>
</testsuite>
</testsuites>
<logging>
<log type="junit" target="build-coverage/report.junit.xml"/>
<log type="coverage-html" target="build-coverage/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="build-coverage/coverage.txt"/>
<log type="coverage-clover" target="build-coverage/clover.xml"/>
</logging>
<php>
<env name="WP_DEVELOP_DIR" value="/tmp/wordpress-develop"/>
<env name="WC_DEVELOP_DIR" value="/tmp/woocommerce"/>
</php>
</phpunit>
\ No newline at end of file
<phpunit bootstrap="tests/unit/bootstrap.php">
<testsuites>
<testsuite>
<directory prefix="test-" suffix=".php">./tests/unit/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">classes</directory>
</whitelist>
</filter>
<logging>
<log type="junit" target="build-coverage/report.junit.xml"/>
<log type="coverage-html" target="build-coverage/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="build-coverage/coverage.txt"/>
<log type="coverage-clover" target="build-coverage/clover.xml"/>
</logging>
</phpunit>
\ No newline at end of file
......@@ -28,6 +28,7 @@
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly
......
<?php
// disable xdebug backtrace
if ( function_exists( 'xdebug_disable' ) ) {
xdebug_disable();
}
if ( getenv( 'PLUGIN_PATH' ) !== false ) {
define( 'PLUGIN_PATH', getenv( 'PLUGIN_PATH' ) );
} else {
define( 'PLUGIN_PATH', __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR );
}
require_once( getenv( 'WP_DEVELOP_DIR' ) . '/tests/phpunit/includes/functions.php' );
tests_add_filter( 'muplugins_loaded', function () {
require PLUGIN_PATH . '/plugin-template.php';
$plugins_to_active[] = 'plugin-template/plugin-template.php';
update_option( 'active_plugins', $plugins_to_active );
}, 100 );
putenv('WP_TESTS_DIR=' . getenv( 'WP_DEVELOP_DIR' ) . '/tests/phpunit');
require_once( getenv( 'WC_DEVELOP_DIR' ) . '/tests/bootstrap.php' );
<?php
use PHPUnit\Framework\TestCase;
require_once( PLUGIN_PATH . '/classes/wpdesk/class-plugin.php' );
require_once( PLUGIN_PATH . '/classes/plugin-template-factory.php' );
class Test_WPDesk_Plugin_Template_Factory extends TestCase {
public function testBuildForNotActivatedPlugin() {
$factory = new WPDesk_Plugin_Template_Factory();
$this->assertInstanceOf( WPDesk_Plugin_Template_Plugin::class, $factory::build_plugin() );
}
public function testGetPluginAlwaysSingleInstance() {
$factory = new WPDesk_Plugin_Template_Factory();
$instanceOne = $factory::get_plugin_instance();
$instanceTwo = $factory::get_plugin_instance();
$this->assertInstanceOf( WPDesk_Plugin_Template_Plugin::class, $instanceOne );
$this->assertSame($instanceOne, $instanceTwo);
}
}
\ No newline at end of file
<?php
/**
* PHPUnit bootstrap file
*/
require_once __DIR__ . '/../../vendor/autoload.php';
error_reporting( E_ALL );
if ( getenv( 'PLUGIN_PATH' ) !== false ) {
define( 'PLUGIN_PATH', getenv( 'PLUGIN_PATH' ) );
} else {
define( 'PLUGIN_PATH', __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR );
}
if ( getenv( 'ABSPATH' ) !== false ) {
define( 'ABSPATH', getenv( 'ABSPATH' ) );
} else {
define( 'ABSPATH', PLUGIN_PATH . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR );
}
WP_Mock::setUsePatchwork( true );
WP_Mock::bootstrap();
<?php
use PHPUnit\Framework\TestCase;
require_once( PLUGIN_PATH . '/classes/wpdesk/class-plugin.php' );
require_once( PLUGIN_PATH . '/classes/plugin-template-factory.php' );
class Test_WPDesk_Plugin_Template_Factory extends TestCase {
public function setUp() {
WP_Mock::setUp();
}
public function tearDown() {
WP_Mock::tearDown();
}
public function testBuildForNotActivatedPlugin() {
WP_Mock::userFunction( 'plugin_basename', [
'return' => 'some-plugin-name'
] );
WP_Mock::userFunction( 'admin_url', [
'return' => 'http://whatever.com'
] );
WP_Mock::userFunction( 'get_option', [
'args' => [ 'api_._activated', '0' ],
'return' => 'not Activated'
] );
WP_Mock::userFunction( 'plugin_dir_url', [
'return' => 'whatever'
] );
WP_Mock::userFunction( 'trailingslashit', [
'return_arg' => 0
] );
$factory = new WPDesk_Plugin_Template_Factory();
$this->assertInstanceOf( WPDesk_Plugin_Template_Plugin::class, $factory::build_plugin() );
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment