Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPP / Add 100% unit test coverage requirement for src #7510

Merged
merged 78 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 75 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
4cd4be9
Updated InitalState 'processing' method
zmaglica Oct 12, 2023
c256145
Added get and set intent to context object
zmaglica Oct 12, 2023
69dc092
Updated function name to match with InitialState class.
zmaglica Oct 12, 2023
fa1721e
Added Verify state that will be executed after Inital state
zmaglica Oct 12, 2023
9681249
Lint fixes.
zmaglica Oct 12, 2023
018d630
Changed class on intent getter and setter
zmaglica Oct 12, 2023
9f99f29
Code review fix: Fixed issue with VerifyState and process method
zmaglica Oct 12, 2023
e628258
Code review fixes: Lint fix
zmaglica Oct 12, 2023
ce20eaf
Code review fixes: Removed completed state variable in processing ser…
zmaglica Oct 12, 2023
7296e3b
Code review fixes: Used legacy proxy sergice to call methods in Check…
zmaglica Oct 12, 2023
5855149
Renamed VerifyState to VerifiedState
zmaglica Oct 12, 2023
684b2ad
Removed intent check in VerifiedState
zmaglica Oct 12, 2023
582352a
Code review fixes: Called complete() method on ProcessedState inside …
zmaglica Oct 12, 2023
427a6c3
Added missing method
zmaglica Oct 12, 2023
044cdf8
Refactored AuthenticationRequiredState to return redirect url only.
zmaglica Oct 12, 2023
c0814d5
Added legacy proxy call and fixed dependencies
zmaglica Oct 12, 2023
e218941
Changed method name in AuthenticationRequiredState
zmaglica Oct 13, 2023
8f1ebd8
Removed CheckoutEncryptionService service and moved methods to the state
zmaglica Oct 13, 2023
d07b60c
PSALM fixes
zmaglica Oct 13, 2023
4bf424a
Added auth required response class
zmaglica Oct 13, 2023
3e3b80b
Removed response class
zmaglica Oct 13, 2023
1937284
Fixed broken tests
zmaglica Oct 16, 2023
8eaa6de
Added tests for VerifiedState
zmaglica Oct 16, 2023
5a60491
Added testes for ProcessedState
zmaglica Oct 16, 2023
eed546c
Removed typo
zmaglica Oct 16, 2023
79a9bdb
Removed unused comment
zmaglica Oct 16, 2023
6384a34
Removed unused docblock
zmaglica Oct 16, 2023
e32a73c
Removed unused imports
zmaglica Oct 16, 2023
106b8c3
Removed order service dependecy from VerifiedState
zmaglica Oct 16, 2023
b8e438b
Added empty line
zmaglica Oct 16, 2023
d9b28ba
Updated comment on state
zmaglica Oct 16, 2023
4ac98dc
Added class check to determinate redirect url prefix.
zmaglica Oct 16, 2023
f3f8e5e
Fixed PSALM errors
zmaglica Oct 16, 2023
48faef1
Replaced dockblock excpetions with use statments
zmaglica Oct 16, 2023
818a8f4
Used better intent status constant
zmaglica Oct 16, 2023
af8b3c8
Cleaned ProcessedState class
zmaglica Oct 16, 2023
6f370c1
Removed unused comment
zmaglica Oct 16, 2023
93e856c
Added missing tests
zmaglica Oct 16, 2023
7765bee
Removed VerifiedState
zmaglica Oct 17, 2023
776c96f
Simplifed test for InitialState
zmaglica Oct 17, 2023
7799a23
Code review fixes
zmaglica Oct 17, 2023
596263c
Merged with latest dev
zmaglica Oct 17, 2023
5b0cce8
Lint fixes
zmaglica Oct 18, 2023
88531a9
Added changelog
zmaglica Oct 18, 2023
9fa462b
Fixed spacing in initial state
zmaglica Oct 18, 2023
48da0fc
Code review fixes
zmaglica Oct 18, 2023
f423504
Fixed psalm errors
zmaglica Oct 18, 2023
da53f1a
Merge branch 'develop' into rpp/7414-authentication-required-state
zmaglica Oct 18, 2023
3ea2e57
Adding the necessary files for a local check
RadoslavGeorgiev Oct 18, 2023
97345db
Code review fixes
zmaglica Oct 19, 2023
b35ba64
Used mocked version of state for tests
zmaglica Oct 19, 2023
62dbd78
Merge branch 'rpp/7414-authentication-required-state' into rpp/100-co…
RadoslavGeorgiev Oct 23, 2023
adb8aea
Workflow for src tests coverage
RadoslavGeorgiev Oct 23, 2023
6836deb
Changing config
RadoslavGeorgiev Oct 23, 2023
aa6b575
Renaming the new workflow
RadoslavGeorgiev Oct 23, 2023
e828d71
Fixing the name
RadoslavGeorgiev Oct 23, 2023
687e1bd
Added docblock for mocked sut variable
zmaglica Oct 23, 2023
1df06bb
One more rename
RadoslavGeorgiev Oct 23, 2023
1a734bc
Changelog entry
RadoslavGeorgiev Oct 23, 2023
2c16517
Updated tests
zmaglica Oct 23, 2023
f6abcee
Changed state names
zmaglica Oct 23, 2023
bd88285
Merge branch 'rpp/7414-authentication-required-state' into rpp/100-co…
RadoslavGeorgiev Oct 23, 2023
d62420c
Merge branch 'develop' into rpp/7414-authentication-required-state
zmaglica Oct 23, 2023
e90a707
Revert "Changed state names"
zmaglica Oct 23, 2023
518dff1
Removed unusued variable from test
zmaglica Oct 23, 2023
4e2d6b3
Merge branch 'rpp/7414-authentication-required-state' into rpp/100-co…
RadoslavGeorgiev Oct 23, 2023
e365772
Ignoring the workaround in Container.php
RadoslavGeorgiev Oct 24, 2023
b8724d1
Merge branch 'develop' into rpp/100-coverage-command
RadoslavGeorgiev Oct 24, 2023
260db03
Merge branch 'develop' into rpp/100-coverage-command
RadoslavGeorgiev Oct 24, 2023
f93c6a1
Merge branch 'develop' into rpp/100-coverage-command
RadoslavGeorgiev Oct 25, 2023
b94ccdf
Merge branch 'develop' into rpp/100-coverage-command
htdat Oct 26, 2023
b2c0f8b
Using a single local bash file
RadoslavGeorgiev Oct 26, 2023
d35db34
Using a matrix for GH workflow
RadoslavGeorgiev Oct 26, 2023
50072ab
Removing redundant files
RadoslavGeorgiev Oct 26, 2023
e5dc5a9
Removing another redundant file
RadoslavGeorgiev Oct 26, 2023
e0e4f10
Merge branch 'develop' into rpp/100-coverage-command
RadoslavGeorgiev Oct 26, 2023
1b5aeea
Adding a separate PHPUnit config for includes
RadoslavGeorgiev Oct 26, 2023
1070694
Merge branch 'develop' into rpp/100-coverage-command
RadoslavGeorgiev Oct 27, 2023
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
6 changes: 4 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ jobs:
woocommerce: [ 'latest' ]
wordpress: [ 'latest' ]
php: [ '7.4' ]
directory: [ 'includes', 'src' ]
env:
WP_VERSION: ${{ matrix.wordpress }}
WC_VERSION: ${{ matrix.woocommerce }}
WP_VERSION: ${{ matrix.wordpress }}
WC_VERSION: ${{ matrix.woocommerce }}
COVERAGE_DIR: ${{ matrix.directory }}
steps:
# clone the repository
- uses: actions/checkout@v3
Expand Down
16 changes: 13 additions & 3 deletions bin/check-test-coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

set -e

if [ "$1" == "src" ]; then
CONFIGURATION_FILE=phpunit-src.xml.dist
COVERAGE=100
else
CONFIGURATION_FILE=phpunit.xml.dist
COVERAGE=60
fi

echo "Installing the test environment..."

docker-compose exec -u www-data wordpress \
Expand All @@ -12,6 +20,8 @@ echo "Checking coverage..."
docker-compose exec -u www-data wordpress \
php -d xdebug.remote_autostart=on \
/var/www/html/wp-content/plugins/woocommerce-payments/vendor/bin/phpunit \
--configuration /var/www/html/wp-content/plugins/woocommerce-payments/phpunit.xml.dist \
--coverage-html /var/www/html/php-test-coverage
$*
--configuration "/var/www/html/wp-content/plugins/woocommerce-payments/$CONFIGURATION_FILE" \
--coverage-html /var/www/html/php-test-coverage \
--coverage-clover /var/www/html/clover.xml

./vendor/bin/coverage-check docker/wordpress/clover.xml $COVERAGE
6 changes: 3 additions & 3 deletions bin/phpunit.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ SUPPORTED_PHP_MAJOR_VERSION_FOR_PHPUNIT_INSTALLED_VIA_COMPOSER_JSON=7
SUPPORTED_PHP_MINOR_VERSION_FOR_PHPUNIT_INSTALLED_VIA_COMPOSER_JSON=3

if [ $CURRENT_PHP_MAJOR_VERSION -gt $SUPPORTED_PHP_MAJOR_VERSION_FOR_PHPUNIT_INSTALLED_VIA_COMPOSER_JSON ]; then
./vendor/bin/phpunit -c phpunit.xml.dist "$@";
./vendor/bin/phpunit "$@";
else
if [ $CURRENT_PHP_MINOR_VERSION -ge $SUPPORTED_PHP_MINOR_VERSION_FOR_PHPUNIT_INSTALLED_VIA_COMPOSER_JSON ]; then
./vendor/bin/phpunit -c phpunit.xml.dist "$@";
./vendor/bin/phpunit "$@";
else
chmod +x ./bin/phpunit6
./bin/phpunit6 -c phpunit.xml.dist "$@";
./bin/phpunit6 "$@";
fi
fi

13 changes: 11 additions & 2 deletions bin/run-ci-tests-check-coverage.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ IFS=$'\n\t'
# set environment variables
WCPAY_DIR="$GITHUB_WORKSPACE"

# determine whether to test everything, or just src, and what coverage to require
if [ "$COVERAGE_DIR" == "src" ]; then
CONFIGURATION_FILE=phpunit-src.xml.dist
COVERAGE=100
else
CONFIGURATION_FILE=phpunit.xml.dist
COVERAGE=60
fi

composer self-update && composer install --no-progress
sudo systemctl start mysql.service
bash bin/install-wp-tests.sh woocommerce_test root root localhost $WP_VERSION $WC_VERSION false
echo 'Running the tests...'
bash bin/phpunit.sh --coverage-clover /tmp/clover.xml
vendor/bin/coverage-check /tmp/clover.xml 60
bash bin/phpunit.sh -c $CONFIGURATION_FILE --coverage-clover /tmp/clover.xml
vendor/bin/coverage-check /tmp/clover.xml $COVERAGE

2 changes: 1 addition & 1 deletion bin/run-ci-tests.bash
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ echo 'Setting up test environment...'
bash bin/install-wp-tests.sh woocommerce_test root root localhost $WP_VERSION $WC_VERSION false $GUTENBERG_VERSION

echo 'Running the tests...'
bash bin/phpunit.sh
bash bin/phpunit.sh -c phpunit.xml.dist
5 changes: 5 additions & 0 deletions changelog/patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: Adding 100% src coverage helpers.


1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"test:update-snapshots": "npm run test:js -- --updateSnapshot",
"test:php": "./bin/run-tests.sh",
"test:php-coverage": "./bin/check-test-coverage.sh",
"test:php-coverage-src": "./bin/check-test-coverage.sh src",
"test:php-watch": "npm run test:php -- -w",
"test:qit": "npm run build:release && ./tests/qit/security.sh",
"watch": "webpack --watch",
Expand Down
28 changes: 28 additions & 0 deletions phpunit-src.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0"?>
<phpunit
bootstrap="tests/unit/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite name="WCPay">
<directory suffix=".php">./tests/unit/helpers</directory>
<directory suffix=".php">./tests/unit/src</directory>
</testsuite>
</testsuites>

<!-- Set a whitelist for code coverage analysis -->
<filter>
<whitelist>
<directory suffix=".php">src</directory>
<exclude>
<!-- Service providers are simple, and ideally should not be used within tests. -->
<directory suffix=".php">src/Internal/DependencyManagement/ServiceProvider</directory>
</exclude>
</whitelist>
</filter>

</phpunit>
4 changes: 4 additions & 0 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use WCPay\Internal\DependencyManagement\ServiceProvider\GenericServiceProvider;
use WCPay\Internal\DependencyManagement\ServiceProvider\ProxiesServiceProvider;

// @codeCoverageIgnoreStart

/**
* Hides errors during update from 6.6.0 or 6.6.1 to 6.6.2.
*
Expand All @@ -36,6 +38,8 @@
wp_die();
}

// @codeCoverageIgnoreEnd

/**
* WCPay Dependency Injection Container.
*
Expand Down
Loading