Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ ehthumbs_vista.db
# IDE specific
theme-sniffer.sublime-project
theme-sniffer.sublime-workspace

# Test coverage in HTML
tests/_reports
92 changes: 50 additions & 42 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,69 @@
dist: trusty

cache:
apt: true
directories:
# Cache directory for older Composer versions.
- $HOME/.composer/cache/files
# Cache directory for more recent Composer versions.
- $HOME/.cache/composer/files
apt: true
directories:
# Cache directory for older Composer versions.
- $HOME/.composer/cache/files
# Cache directory for more recent Composer versions.
- $HOME/.cache/composer/files

language: php

php:
- 7.0
- 7.1
- 7.3
- nightly
- 7.0
- 7.1
- 7.3
- nightly

env:
# Highest supported PHPCS version.
- PHPCS_BRANCH="dev-master" LINT=1
# Lowest supported PHPCS version.
- PHPCS_BRANCH="3.3.0"
# Highest supported PHPCS version.
- PHPCS_BRANCH="dev-master" LINT=1
# Lowest supported PHPCS version.
- PHPCS_BRANCH="3.3.0"

notifications:
email:
on_success: never
on_failure: change
email:
on_success: never
on_failure: change

branches:
only:
- master
- development
only:
- master
- development

matrix:
fast_finish: true
include:
# Seperate builds for PHP 7.2 with additional checks.
- php: 7.2
env: PHPCS_BRANCH="dev-master"
addons:
apt:
packages:
- libxml2-utils
- php: 7.2
env: PHPCS_BRANCH="3.3.0"

allow_failures:
# Allow failures for unstable builds.
- php: nightly
- php: "7.4snapshot"
fast_finish: true
include:
# Seperate builds for PHP 7.2 with additional checks.
- php: 7.2
env: PHPCS_BRANCH="dev-master" LINT=1 SNIFF=1
addons:
apt:
packages:
- libxml2-utils
- php: 7.2
env: PHPCS_BRANCH="3.3.1"

allow_failures:
# Allow failures for unstable builds.
- php: nightly
- php: "7.4snapshot"

before_install:
- phpenv config-rm xdebug.ini
- composer install
# Speed up build time by disabling Xdebug.
# https://johnblackbourn.com/reducing-travis-ci-build-times-for-wordpress-projects/
# https://twitter.com/kelunik/status/954242454676475904
- phpenv config-rm xdebug.ini || echo 'No xdebug config.'
- composer install
- bash bin/install-wp-tests.sh wordpress_test root '' localhost latest

script:
# Lint the PHP files against parse errors.
- if find . -path ./vendor -prune -o -name "*.php" -exec php -l {} \; | grep "^[Parse error|Fatal error]"; then exit 1; fi;
# Check the codestyle of the WPThemeReview codebase.
- composer check-cs .
# Lint the PHP files against parse errors.
if find . -path ./vendor -prune -o -name "*.php" -exec php -l {} \; | grep "^[Parse error|Fatal error]"; then exit 1; fi
# Check the codestyle of the WPThemeReview codebase.
- composer check-cs .
# Run integration tests
- composer pint
# Run unit tests
- composer punit
59 changes: 59 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!make

SETUP_TESTSUITE=bash bin/install-wp-tests.sh wordpress_test root '' localhost latest

DEFAULT_GOAL := help
help:
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-27s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

.PHONY: build-project
build-project: ## Runs the npm and composer installations, and builds the zip file
composer install && npm install && npm run build

.PHONY: build-dev
build-dev: ## Runs the npm and composer installations without the zip file
composer install && npm install && npm run dev

.PHONY: run-dev
run-dev: ## Runs the dev npm script
npm run dev

.PHONY: run-watch
run-watch: ## Runs the watch npm script
npm run watch

.PHONY: setup-testsuite
setup-testsuite: ## Set up the default testsuite - install test WordPress and database
$(shell $(SETUP_TESTSUITE))

.PHONY: clobber
clobber: ## Run pcov clobber script - to use pcov instead of Xdebug
composer clobber

.PHONY: unclobber
unclobber: ## Run pcov unclobber script - to revert the usage of pcov instead of Xdebug
composer unclobber

.PHONY: test-unit
test-unit: ## Run unit tests
composer run-tests-unit

.PHONY: test-unit-coverage
test-unit-coverage: ## Run unit tests with code coverage
composer run-tests-unit-cov

.PHONY: test-integration
test-integration: ## Run integration tests
composer run-tests-integ

.PHONY: test-integration-coverage
test-integration-coverage: ## Run integration tests with code coverage
composer run-tests-integ-cov

.PHONY: check-cs
check-cs: ## Check the code with PHPCS against the coding standards
composer check-cs

.PHONY: fix-cs
fix-cs: ## Run the PHPCBF command for code beautification according to coding standards
composer fix-cs
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,72 @@ When developing JavaScript code keep in mind the separation of concerns principl

The same is valid for PHP code. The business logic is stored in the `src/` folder, the JS and CSS are located in `assets/` folder and the views are located in the `views/` folder.

## Running unit or integration tests

Before running unit tests, you'll need to install a local test environment. You can do this by running:

```bash
bash bin/install-wp-tests.sh wordpress_test root '' localhost latest
```

in your terminal.

After this has been installed you can run

```bash
composer punit
```

to run unit tests (without coverage). To generate code coverage report you can run

```bash
composer punit-cov
```

In order for coverage to be generated, you'll need to have Xdebug installed.

To run integration tests you can run

```bash
composer pint
```

To generate code coverage report you can run

```bash
composer pint-cov
```

The output should look like this:

```bash
> @php ./vendor/bin/phpunit -c phpunit.integration.xml.dist --no-coverage --colors=always
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.

PHPUnit Pretty Result Printer 0.20.3 by Codedungeon and contributors.
==> Configuration: .../wp-content/plugins/theme-sniffer/vendor/codedungeon/phpunit-result-printer/phpunit-printer.yml

PHPUnit 6.5.14 by Sebastian Bergmann and contributors.

Runtime: PHP 7.2.14 with Xdebug 2.6.1
Configuration: .../wp-content/plugins/theme-sniffer/phpunit.integration.xml.dist


==> Plugin_Integration_Test ✓ ✓ ✓ ✓ ✓ ✓

Time: 4.43 seconds, Memory: 32.00MB
```

## Helpful Composer commands

The plugin offers few additional helpful commands, but you'll mostly be interested in this one

```bash
composer check-cs .
```

It will run `phpcs` check on the entire code base.
Loading