Skip to content

Commit d16b846

Browse files
Merge pull request #780 from nextcloud/maintenance/phpunit-as-phar
Usage of PHPUnit as phar instead of composer dependency
2 parents 9feede0 + c781810 commit d16b846

16 files changed

+127
-115
lines changed

.github/actions/run-tests/mysql/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
FROM mariadb:10.1
2+
FROM mariadb:10.5
33

44
LABEL maintainer="Christian Wolf <[email protected]>"
55

.github/actions/run-tests/run-locally.sh

+9-5
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ setup_app () {
254254
fi
255255

256256
echo "Synchronizing the cookbook codebase to volume"
257-
rsync -a ../../../ volumes/cookbook --exclude /.git --exclude /.github/actions/run-tests/volumes --delete --delete-delay
257+
rsync -a ../../../ volumes/cookbook --exclude /.git --exclude /.github/actions/run-tests/volumes --exclude /node_modules/ --delete --delete-delay
258258

259259
echo "Activating the cookbook app in the server"
260260
docker-compose run --rm -T occ app:enable cookbook
@@ -328,8 +328,12 @@ restore_env_dump() {
328328
rsync $RSYNC_PARAMS "volumes/dumps/$ENV_DUMP_PATH/data/" volumes/data/
329329

330330
# Restore server files
331-
echo "Restoring server files"
332-
rsync $RSYNC_PARAMS "volumes/dumps/$ENV_DUMP_PATH/nextcloud/" volumes/nextcloud/
331+
if [ "$QUICK_MODE" = y ]; then
332+
echo 'Quick mode activated. Does not restore server core files.'
333+
else
334+
echo "Restoring server files"
335+
rsync $RSYNC_PARAMS "volumes/dumps/$ENV_DUMP_PATH/nextcloud/" volumes/nextcloud/
336+
fi
333337

334338
# Restore DB dump
335339
case "$INPUT_DB" in
@@ -456,7 +460,7 @@ RUN_INTEGRATION_TESTS=n
456460
EXTRACT_CODE_COVERAGE=n
457461
INSTALL_COMPOSER_DEPS=n
458462
BUILD_NPM=n
459-
QUICK_MODE=''
463+
QUICK_MODE=n
460464

461465
DEBUG=n
462466
DEBUG_PORT='9000'
@@ -478,7 +482,7 @@ COPY_ENV_DST=''
478482
source mysql.env
479483
source postgres.env
480484

481-
RSYNC_PARAMS="--delete --delete-delay --archive"
485+
RSYNC_PARAMS="--delete --delete-delay --delete-excluded --archive"
482486

483487
##### Extract CLI parameters into internal variables
484488

.github/actions/run-tests/tests/Dockerfile

+29-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,35 @@ LABEL maintainer="Christian Wolf <[email protected]>"
66

77
ARG PHPVERSION
88

9-
COPY install.sh /install.sh
10-
RUN /install.sh ${PHPVERSION}
9+
RUN apt-get -qq update && \
10+
apt-get -qq -y install --no-install-recommends \
11+
npm make default-mysql-client postgresql-client \
12+
unzip git libfreetype6-dev libpng-dev libjpeg-dev libzip-dev \
13+
cmake libpq-dev libsqlite3-dev sudo rsync tini wget > /dev/null && \
14+
apt-get clean
15+
16+
COPY install-php-ini.sh /tmp/install-php-ini.sh
17+
RUN /tmp/install-php-ini.sh
18+
19+
COPY install-sudoers.sh /tmp/install-sudoers.sh
20+
RUN /tmp/install-sudoers.sh
21+
22+
COPY install-gd.sh /tmp/install-gd.sh
23+
RUN /tmp/install-gd.sh ${PHPVERSION}
24+
25+
RUN docker-php-ext-configure zip > /dev/null && \
26+
docker-php-ext-install -j$(nproc) zip > /dev/null && \
27+
docker-php-ext-install -j$(nproc) pdo pdo_mysql pdo_pgsql pdo_sqlite > /dev/null && \
28+
pecl install xdebug > /dev/null && \
29+
docker-php-ext-enable xdebug > /dev/null
30+
31+
RUN npm install -g --quiet --loglevel warn npm@latest
32+
33+
COPY install-composer.sh /install-composer.sh
34+
RUN /install-composer.sh
35+
36+
RUN wget -O /phpunit https://phar.phpunit.de/phpunit-9.phar && \
37+
chmod +x /phpunit
1138

1239
COPY xdebug.config /tmp/xdebug.config
1340
RUN cat /tmp/xdebug.config >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

.github/actions/run-tests/tests/entrypoints/default-entrypoint.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
if [ `whoami` = root ]; then
44

5-
if [ -z "$QUICK_MODE" -o "$QUCK_MODE" = n ]; then
5+
if [ "$QUCK_MODE" = y ]; then
6+
echo "Quick mode activated. No permission update is carried out"
7+
else
68
echo "Setting uid and gid to $RUNNER_UID/$RUNNER_GID"
79
usermod -u $RUNNER_UID runner
810
groupmod -g $RUNNER_GID runner
911

1012
echo "Changing ownership of files to runner"
1113
chown -R runner: /nextcloud
12-
else
13-
echo "Quick mode activated. No permission update is carried out"
1414
fi
1515

1616
if [ -n "$DEBUG_MODE" ]; then

.github/actions/run-tests/tests/entrypoints/test.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ do
6262
done
6363

6464
echo "Synchronizing cookbook codebase"
65-
rsync -a /cookbook/ apps/cookbook/ --delete --delete-delay --exclude /.git --exclude /.github/actions/run-tests/volumes --exclude /docs
65+
rsync -a /cookbook/ apps/cookbook/ --delete --delete-delay --delete-excluded --exclude /.git --exclude /.github/actions/run-tests/volumes --exclude /docs --exclude /node_modules/
6666

6767
pushd apps/cookbook
6868

@@ -103,13 +103,13 @@ pushd apps/cookbook
103103

104104
if [ $RUN_UNIT_TESTS = 'y' ]; then
105105
echo 'Starting unit testing.'
106-
./vendor/phpunit/phpunit/phpunit -c phpunit.xml $PARAM_COVERAGE_UNIT "$@"
106+
/phpunit -c phpunit.xml $PARAM_COVERAGE_UNIT "$@"
107107
echo 'Unit testing done.'
108108
fi
109109

110110
if [ $RUN_INTEGRATION_TESTS = 'y' ]; then
111111
echo 'Starting integration testing.'
112-
./vendor/phpunit/phpunit/phpunit -c phpunit.integration.xml $PARAM_COVERAGE_INTEGRATION "$@"
112+
/phpunit -c phpunit.integration.xml $PARAM_COVERAGE_INTEGRATION "$@"
113113
echo 'Integration testing done.'
114114
fi
115115

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash -e
2+
3+
# Install composer
4+
EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
5+
php -r "copy('https://getcomposer.org/installer', '/tmp/composer-setup.php');"
6+
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', '/tmp/composer-setup.php');")"
7+
8+
if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]
9+
then
10+
>&2 echo 'ERROR: Invalid installer checksum'
11+
exit 1
12+
fi
13+
14+
php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
15+
rm /tmp/composer-setup.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash -e
2+
3+
function configure_gd_normal ()
4+
{
5+
docker-php-ext-configure gd --with-freetype --with-jpeg
6+
return $?
7+
}
8+
9+
function configure_gd_without ()
10+
{
11+
docker-php-ext-configure gd
12+
return $?
13+
}
14+
15+
function configure_gd()
16+
{
17+
if [ "$1" = "7.2" -o "$1" = "7.3" ]; then
18+
configure_gd_without
19+
return $?
20+
else
21+
configure_gd_normal
22+
return $?
23+
fi
24+
}
25+
26+
echo 'Installing PHP gd'
27+
configure_gd "$1" > /dev/null
28+
docker-php-ext-install -j$(nproc) gd > /dev/null
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
echo 'Installing php.ini for development'
4+
cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini
5+
cat > /usr/local/etc/php/conf.d/memory_limit.ini << EOF
6+
memory_limit = 512M
7+
EOF
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash -e
2+
3+
echo 'runner ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers

.github/actions/run-tests/tests/install.sh

-78
This file was deleted.

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
### Fixed
44
- Mark app as compatible with Nextcloud 22
55
[#778](https://github.com./nextcloud/cookbook/pull/778) @christianlupus
6+
- Usage of PHAR-based PHPUnit to avoid dependency on nikic/php-parser and dependency conflicts
7+
[#780](https://github.com./nextcloud/cookbook/pull/780) @christianlupus
68

79
### Removed
810
- Removed app info XML file to avoid confusion

composer.json

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
"ext-libxml": "*"
1313
},
1414
"require-dev": {
15-
"phpunit/phpunit": ">=8.0",
16-
"nikic/php-parser": "4.2",
1715
"nextcloud/coding-standard": "^0.5.0"
1816
},
1917
"scripts": {

phpunit.integration.xml

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1+
<?xml version="1.0"?>
12
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24
bootstrap="tests/bootstrap.php"
35
colors="true"
46
backupGlobals="false"
57
backupStaticAttributes="false"
68
cacheResult="true"
79
cacheResultFile="/tmp/phpunit.cache"
10+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
811
>
9-
<testsuites>
10-
<testsuite name="integration">
11-
<directory>./tests/Integration</directory>
12-
</testsuite>
13-
</testsuites>
14-
<filter>
15-
<whitelist processUncoveredFilesFromWhitelist="true" addUncoveredFilesFromWhitelist="true">
12+
<testsuites>
13+
<testsuite name="integration">
14+
<directory>./tests/Integration</directory>
15+
</testsuite>
16+
</testsuites>
17+
<coverage includeUncoveredFiles="true" processUncoveredFiles="true">
18+
<include>
1619
<directory suffix=".php">lib</directory>
17-
</whitelist>
18-
</filter>
20+
</include>
21+
</coverage>
1922
</phpunit>

phpunit.xml

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1+
<?xml version="1.0"?>
12
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24
bootstrap="tests/bootstrap.php"
35
colors="true"
46
backupGlobals="false"
57
backupStaticAttributes="false"
68
cacheResult="true"
79
cacheResultFile="/tmp/phpunit.cache"
10+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
811
>
9-
<testsuites>
10-
<testsuite name="unit">
11-
<directory>./tests/Unit</directory>
12-
</testsuite>
13-
</testsuites>
14-
<filter>
15-
<whitelist processUncoveredFilesFromWhitelist="true" addUncoveredFilesFromWhitelist="true">
12+
<testsuites>
13+
<testsuite name="unit">
14+
<directory>./tests/Unit</directory>
15+
</testsuite>
16+
</testsuites>
17+
<coverage includeUncoveredFiles="true" processUncoveredFiles="true">
18+
<include>
1619
<directory suffix=".php">lib</directory>
17-
</whitelist>
18-
</filter>
20+
</include>
21+
</coverage>
1922
</phpunit>

tests/Integration/AppTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
namespace OCA\Cookbook\Tests\Integration\Controller;
3+
namespace OCA\Cookbook\tests\Integration;
44

55
use OCP\App\IAppManager;
66
use OCP\AppFramework\App;
7-
use Test\TestCase;
7+
use PHPUnit\Framework\TestCase;
88

99
/**
1010
* This test shows how to make a small Integration Test. Query your class

tests/Integration/Setup/Migrations/Version000000Date20210701093123Test.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace tests\Integration\Setup\Migrations;
3+
namespace OCA\Cookbook\tests\Integration\Setup\Migrations;
44

55
use OCP\IDBConnection;
66
use OCP\AppFramework\App;

0 commit comments

Comments
 (0)