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

chore: add integration tests to CI and composer.json command #5311

Merged
merged 1 commit into from
Jul 3, 2023
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
48 changes: 48 additions & 0 deletions .github/workflows/php-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,55 @@ jobs:
fail_ci_if_error: true
verbose: true

integration-tests:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: [ '8.0', '8.1', '8.2' ]
nextcloud-versions: [ 'master']
include:
- php-versions: '7.4'
nextcloud-versions: 'stable25'
- php-versions: '8.1'
nextcloud-versions: 'stable26'
- php-versions: '8.1'
nextcloud-versions: 'stable27'
name: php${{ matrix.php-versions }} on ${{ matrix.nextcloud-versions }} integration tests
env:
CI: true
XDEBUG_MODE: coverage
steps:
- name: Set up php${{ matrix.php-versions }}
uses: shivammathur/setup-php@c5fc0d8281aba02c7fda07d3a70cc5371548067d
with:
php-version: ${{ matrix.php-versions }}
extensions: ctype, curl, dom, gd, gmp, iconv, intl, json, mbstring, openssl, pdo_sqlite, posix, sqlite, xml, zip
coverage: xdebug
- name: Checkout Nextcloud
run: git clone https://github.com/nextcloud/server.git --recursive --depth 1 -b ${{ matrix.nextcloud-versions }} nextcloud
- name: Patch version check for nightly PHP
if: ${{ matrix.php-versions == '8.2' }}
run: echo "<?php" > nextcloud/lib/versioncheck.php
- name: Install Nextcloud
run: php -f nextcloud/occ maintenance:install --database-name oc_autotest --database-user oc_autotest --admin-user admin --admin-pass admin --database sqlite --database-pass=''
- name: Checkout the app
uses: actions/checkout@v3
with:
path: nextcloud/apps/calendar
- name: Install dependencies
working-directory: nextcloud/apps/calendar
run: composer install
- name: Install Calendar
run: php -f nextcloud/occ app:enable calendar
- name: Run tests
working-directory: nextcloud/apps/calendar
run: composer run test:integration

summary:
runs-on: ubuntu-latest
needs:
- unit-tests
- integration-tests

if: always()

Expand All @@ -63,3 +108,6 @@ jobs:
steps:
- name: Unit test status
run: if ${{ needs.unit-tests.result != 'success' && needs.unit-tests.result != 'skipped' }}; then exit 1; fi
- name: Integration test status
run: if ${{ needs.integration-tests.result != 'success' && needs.integration-tests.result != 'skipped' }}; then exit 1; fi

2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"psalm": "psalm",
"test": "phpunit --configuration phpunit.unit.xml --fail-on-warning",
"test:dev": "phpunit --configuration phpunit.unit.xml --fail-on-warning --stop-on-error --stop-on-failure",
"test:integration": "phpunit -c phpunit.integration.xml --fail-on-warning",
"test:integration:dev": "phpunit -c phpunit.integration.xml --no-coverage --order-by=defects --stop-on-defect --fail-on-warning --stop-on-error --stop-on-failure",
"post-install-cmd": [
"@composer bin all install --ansi"
],
Expand Down
2 changes: 2 additions & 0 deletions lib/Http/JsonResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

/**
* @see https://github.com/omniti-labs/jsend
*
* @psalm-suppress MissingTemplateParam
*/
class JsonResponse extends Base {
public function __construct($data = [],
Expand Down
37 changes: 37 additions & 0 deletions phpunit.integration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
~
~ @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
~
~ @license GNU AGPL version 3 or any later version
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU Affero General Public License as
~ published by the Free Software Foundation, either version 3 of the
~ License, or (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU Affero General Public License for more details.
~
~ You should have received a copy of the GNU Affero General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="tests/php/unit/bootstrap.php"
verbose="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">../lib</directory>
</include>
<report>
<clover outputFile="./clover.integration.xml"/>
</report>
</coverage>
<testsuite name="integration">
<directory suffix="Test.php">./tests/php/integration</directory>
</testsuite>
</phpunit>
19 changes: 2 additions & 17 deletions tests/php/integration/Db/AppointmentConfigMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,14 @@ public function testFindById() {
$id = $appointment->getId();
$appointment = $this->mapper->findById($id);

$this->assertObjectHasAttribute('token', $appointment);

$this->assertEquals('okens', $appointment->getToken());
$this->assertObjectHasAttribute('name', $appointment);
$this->assertEquals('Test 2', $appointment->getName());
$this->assertObjectHasAttribute('description', $appointment);
$this->assertEquals('Test Description', $appointment->getDescription());
$this->assertObjectHasAttribute('increment', $appointment);
$this->assertEquals(15 * 60, $appointment->getIncrement());
$this->assertObjectHasAttribute('length', $appointment);
$this->assertEquals(60 * 60, $appointment->getLength());
$this->assertObjectHasAttribute('targetCalendarUri', $appointment);
$this->assertEquals('testuri', $appointment->getTargetCalendarUri());
$this->assertObjectHasAttribute('visibility', $appointment);
$this->assertEquals(AppointmentConfig::VISIBILITY_PUBLIC, $appointment->getVisibility());
$this->assertObjectHasAttribute('userId', $appointment);
$this->assertEquals('testuser', $appointment->getUserId());
}

Expand All @@ -114,21 +107,14 @@ public function testFindByToken() {
$token = $appointment->getToken();
$appointment = $this->mapper->findByToken($token);

$this->assertObjectHasAttribute('token', $appointment);

$this->assertEquals('okensdsadsas', $appointment->getToken());
$this->assertObjectHasAttribute('name', $appointment);
$this->assertEquals('Test 2', $appointment->getName());
$this->assertObjectHasAttribute('description', $appointment);
$this->assertEquals('Test Description', $appointment->getDescription());
$this->assertObjectHasAttribute('increment', $appointment);
$this->assertEquals(15 * 60, $appointment->getIncrement());
$this->assertObjectHasAttribute('length', $appointment);
$this->assertEquals(60 * 60, $appointment->getLength());
$this->assertObjectHasAttribute('targetCalendarUri', $appointment);
$this->assertEquals('testuri', $appointment->getTargetCalendarUri());
$this->assertObjectHasAttribute('visibility', $appointment);
$this->assertEquals(AppointmentConfig::VISIBILITY_PUBLIC, $appointment->getVisibility());
$this->assertObjectHasAttribute('userId', $appointment);
$this->assertEquals('testuser', $appointment->getUserId());
}

Expand All @@ -149,7 +135,6 @@ public function testFindAllForUser():void {
$this->assertNotEmpty($appointments);

foreach ($appointments as $appointment) {
$this->assertObjectHasAttribute('userId', $appointment);
$this->assertEquals('testuser', $appointment->getUserId());
}
}
Expand Down
8 changes: 0 additions & 8 deletions tests/php/integration/Db/BookingMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,13 @@ public function testFindByToken() {
$token = $booking->getToken();
$booking = $this->mapper->findByToken($token);

$this->assertObjectHasAttribute('apptConfigId', $booking);
$this->assertEquals('1', $booking->getApptConfigId());
$this->assertObjectHasAttribute('createdAt', $booking);
$this->assertEquals($this->time->getTime(), $booking->getCreatedAt());
$this->assertObjectHasAttribute('token', $booking);
$this->assertEquals('oken', $booking->getToken());
$this->assertObjectHasAttribute('displayName', $booking);
$this->assertEquals('Test', $booking->getDisplayName());
$this->assertObjectHasAttribute('start', $booking);
$this->assertEquals(123, $booking->getStart());
$this->assertObjectHasAttribute('end', $booking);
$this->assertEquals(123, $booking->getEnd());
$this->assertObjectHasAttribute('email', $booking);
$this->assertEquals('test@test.com', $booking->getEmail());
$this->assertObjectHasAttribute('timezone', $booking);
$this->assertEquals('Europe/Berlin', $booking->getTimezone());
}

Expand Down
Loading