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

Usage of PHPUnit as phar instead of composer dependency #780

Merged
merged 8 commits into from
Aug 10, 2021
Merged
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
2 changes: 1 addition & 1 deletion .github/actions/run-tests/mysql/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

FROM mariadb:10.1
FROM mariadb:10.5

LABEL maintainer="Christian Wolf <github@christianwolf.email>"

Expand Down
14 changes: 9 additions & 5 deletions .github/actions/run-tests/run-locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ setup_app () {
fi

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

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

# Restore server files
echo "Restoring server files"
rsync $RSYNC_PARAMS "volumes/dumps/$ENV_DUMP_PATH/nextcloud/" volumes/nextcloud/
if [ "$QUICK_MODE" = y ]; then
echo 'Quick mode activated. Does not restore server core files.'
else
echo "Restoring server files"
rsync $RSYNC_PARAMS "volumes/dumps/$ENV_DUMP_PATH/nextcloud/" volumes/nextcloud/
fi

# Restore DB dump
case "$INPUT_DB" in
Expand Down Expand Up @@ -456,7 +460,7 @@ RUN_INTEGRATION_TESTS=n
EXTRACT_CODE_COVERAGE=n
INSTALL_COMPOSER_DEPS=n
BUILD_NPM=n
QUICK_MODE=''
QUICK_MODE=n

DEBUG=n
DEBUG_PORT='9000'
Expand All @@ -478,7 +482,7 @@ COPY_ENV_DST=''
source mysql.env
source postgres.env

RSYNC_PARAMS="--delete --delete-delay --archive"
RSYNC_PARAMS="--delete --delete-delay --delete-excluded --archive"

##### Extract CLI parameters into internal variables

Expand Down
31 changes: 29 additions & 2 deletions .github/actions/run-tests/tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,35 @@ LABEL maintainer="Christian Wolf <github@christianwolf.email>"

ARG PHPVERSION

COPY install.sh /install.sh
RUN /install.sh ${PHPVERSION}
RUN apt-get -qq update && \
apt-get -qq -y install --no-install-recommends \
npm make default-mysql-client postgresql-client \
unzip git libfreetype6-dev libpng-dev libjpeg-dev libzip-dev \
cmake libpq-dev libsqlite3-dev sudo rsync tini wget > /dev/null && \
apt-get clean

COPY install-php-ini.sh /tmp/install-php-ini.sh
RUN /tmp/install-php-ini.sh

COPY install-sudoers.sh /tmp/install-sudoers.sh
RUN /tmp/install-sudoers.sh

COPY install-gd.sh /tmp/install-gd.sh
RUN /tmp/install-gd.sh ${PHPVERSION}

RUN docker-php-ext-configure zip > /dev/null && \
docker-php-ext-install -j$(nproc) zip > /dev/null && \
docker-php-ext-install -j$(nproc) pdo pdo_mysql pdo_pgsql pdo_sqlite > /dev/null && \
pecl install xdebug > /dev/null && \
docker-php-ext-enable xdebug > /dev/null

RUN npm install -g --quiet --loglevel warn npm@latest

COPY install-composer.sh /install-composer.sh
RUN /install-composer.sh

RUN wget -O /phpunit https://phar.phpunit.de/phpunit-9.phar && \
chmod +x /phpunit

COPY xdebug.config /tmp/xdebug.config
RUN cat /tmp/xdebug.config >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

if [ `whoami` = root ]; then

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

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

if [ -n "$DEBUG_MODE" ]; then
Expand Down
6 changes: 3 additions & 3 deletions .github/actions/run-tests/tests/entrypoints/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ do
done

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

pushd apps/cookbook

Expand Down Expand Up @@ -103,13 +103,13 @@ pushd apps/cookbook

if [ $RUN_UNIT_TESTS = 'y' ]; then
echo 'Starting unit testing.'
./vendor/phpunit/phpunit/phpunit -c phpunit.xml $PARAM_COVERAGE_UNIT "$@"
/phpunit -c phpunit.xml $PARAM_COVERAGE_UNIT "$@"
echo 'Unit testing done.'
fi

if [ $RUN_INTEGRATION_TESTS = 'y' ]; then
echo 'Starting integration testing.'
./vendor/phpunit/phpunit/phpunit -c phpunit.integration.xml $PARAM_COVERAGE_INTEGRATION "$@"
/phpunit -c phpunit.integration.xml $PARAM_COVERAGE_INTEGRATION "$@"
echo 'Integration testing done.'
fi

Expand Down
15 changes: 15 additions & 0 deletions .github/actions/run-tests/tests/install-composer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash -e

# Install composer
EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
php -r "copy('https://getcomposer.org/installer', '/tmp/composer-setup.php');"
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', '/tmp/composer-setup.php');")"

if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]
then
>&2 echo 'ERROR: Invalid installer checksum'
exit 1
fi

php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
rm /tmp/composer-setup.php
28 changes: 28 additions & 0 deletions .github/actions/run-tests/tests/install-gd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash -e

function configure_gd_normal ()
{
docker-php-ext-configure gd --with-freetype --with-jpeg
return $?
}

function configure_gd_without ()
{
docker-php-ext-configure gd
return $?
}

function configure_gd()
{
if [ "$1" = "7.2" -o "$1" = "7.3" ]; then
configure_gd_without
return $?
else
configure_gd_normal
return $?
fi
}

echo 'Installing PHP gd'
configure_gd "$1" > /dev/null
docker-php-ext-install -j$(nproc) gd > /dev/null
7 changes: 7 additions & 0 deletions .github/actions/run-tests/tests/install-php-ini.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

echo 'Installing php.ini for development'
cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini
cat > /usr/local/etc/php/conf.d/memory_limit.ini << EOF
memory_limit = 512M
EOF
3 changes: 3 additions & 0 deletions .github/actions/run-tests/tests/install-sudoers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash -e

echo 'runner ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
78 changes: 0 additions & 78 deletions .github/actions/run-tests/tests/install.sh

This file was deleted.

2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
### Fixed
- Mark app as compatible with Nextcloud 22
[#778](https://github.com/nextcloud/cookbook/pull/778) @christianlupus
- Usage of PHAR-based PHPUnit to avoid dependency on nikic/php-parser and dependency conflicts
[#780](https://github.com/nextcloud/cookbook/pull/780) @christianlupus

### Removed
- Removed app info XML file to avoid confusion
Expand Down
2 changes: 0 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
"ext-libxml": "*"
},
"require-dev": {
"phpunit/phpunit": ">=8.0",
"nikic/php-parser": "4.2",
"nextcloud/coding-standard": "^0.5.0"
},
"scripts": {
Expand Down
21 changes: 12 additions & 9 deletions phpunit.integration.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="tests/bootstrap.php"
colors="true"
backupGlobals="false"
backupStaticAttributes="false"
cacheResult="true"
cacheResultFile="/tmp/phpunit.cache"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<testsuites>
<testsuite name="integration">
<directory>./tests/Integration</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true" addUncoveredFilesFromWhitelist="true">
<testsuites>
<testsuite name="integration">
<directory>./tests/Integration</directory>
</testsuite>
</testsuites>
<coverage includeUncoveredFiles="true" processUncoveredFiles="true">
<include>
<directory suffix=".php">lib</directory>
</whitelist>
</filter>
</include>
</coverage>
</phpunit>
21 changes: 12 additions & 9 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="tests/bootstrap.php"
colors="true"
backupGlobals="false"
backupStaticAttributes="false"
cacheResult="true"
cacheResultFile="/tmp/phpunit.cache"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<testsuites>
<testsuite name="unit">
<directory>./tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true" addUncoveredFilesFromWhitelist="true">
<testsuites>
<testsuite name="unit">
<directory>./tests/Unit</directory>
</testsuite>
</testsuites>
<coverage includeUncoveredFiles="true" processUncoveredFiles="true">
<include>
<directory suffix=".php">lib</directory>
</whitelist>
</filter>
</include>
</coverage>
</phpunit>
4 changes: 2 additions & 2 deletions tests/Integration/AppTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace OCA\Cookbook\Tests\Integration\Controller;
namespace OCA\Cookbook\tests\Integration;

use OCP\App\IAppManager;
use OCP\AppFramework\App;
use Test\TestCase;
use PHPUnit\Framework\TestCase;

/**
* This test shows how to make a small Integration Test. Query your class
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace tests\Integration\Setup\Migrations;
namespace OCA\Cookbook\tests\Integration\Setup\Migrations;

use OCP\IDBConnection;
use OCP\AppFramework\App;
Expand Down