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

[TASK] Add Tests #31

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
82 changes: 82 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Tests
on:
push:
branches:
- main
- develop
pull_request:
branches:
- '**'

jobs:
tests:
name: Tests (PHP ${{ matrix.php-version }}, Composer ${{ matrix.composer-version }} & ${{ matrix.dependencies }} dependencies)
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-version: ["8.1", "8.2"]
composer-version: ["2.1", "2.2", "2.3", "2.4", "2.5"]
dependencies: ["highest", "lowest"]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

# Prepare environment
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer:v${{ matrix.composer-version }}
coverage: none

# Install dependencies
- name: Install Composer dependencies
uses: ramsey/composer-install@v2
with:
dependency-versions: ${{ matrix.dependencies }}

# Run tests
- name: Run tests
run: composer test:unit

coverage:
name: Test coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

# Prepare environment
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
tools: composer:v2
coverage: pcov

# Install dependencies
- name: Install Composer dependencies
uses: ramsey/composer-install@v2
with:
dependency-versions: highest

# Run Unit tests
- name: Build coverage directory
run: mkdir -p .build/coverage
- name: Run Unit tests with coverage
run: composer test:coverage

# Report coverage
- name: Fix coverage path
working-directory: .Build/coverage
run: sed -i 's#/home/runner/work/project-builder/project-builder#${{ github.workspace }}#g' clover.xml
- name: codecov report
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: .build/coverage
fail_ci_if_error: true
verbose: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/Resources/Private/Libs/Build/vendor
/Resources/Private/Libs/vendors.phar
/.php-cs-fixer.cache
/.phpunit.result.cache
42 changes: 42 additions & 0 deletions Tests/Unit/Utility/FrontendUtilityTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

/*
* This file is part of the TYPO3 CMS extension "cpsit/personio-jobs".
*
* Copyright (C) 2023 Martin Adler <m.adler@familie-redlich.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

namespace Unit\Utility;

use CPSIT\Typo3PersonioJobs\Utility\FrontendUtility;
use PHPUnit\Framework\TestCase;

class FrontendUtilityTest extends TestCase
{
/**
* @test
*/
public function getServerRequestReturnsServerRequest(): void
{
$GLOBALS['TYPO3_REQUEST'] = new \TYPO3\CMS\Core\Http\ServerRequest();

$serverRequest = FrontendUtility::getServerRequest();
self::assertInstanceOf(\Psr\Http\Message\ServerRequestInterface::class, $serverRequest);
self::assertSame($GLOBALS['TYPO3_REQUEST'], $serverRequest);
}
}
24 changes: 22 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
"email": "e.haeussler@familie-redlich.de",
"homepage": "https://www.cps-it.de",
"role": "Developer"
},
{
"name": "Martin Adler",
"email": "m.adler@familie-redlich.de",
"homepage": "https://www.cps-it.de",
"role": "Developer"
}
],
"require": {
Expand All @@ -37,7 +43,8 @@
"phpstan/phpstan": "^1.10",
"saschaegerer/phpstan-typo3": "^1.8",
"ssch/typo3-rector": "^1.1",
"typo3/coding-standards": "^0.7.1"
"typo3/coding-standards": "^0.7.1",
"typo3/testing-framework": "^8.0"
},
"suggest": {
"brotkrueml/schema": "Include JSON schema on job detail pages (^2.7)"
Expand All @@ -47,6 +54,11 @@
"CPSIT\\Typo3PersonioJobs\\": "Classes/"
}
},
"autoload-dev": {
"psr-4": {
"CPSIT\\Typo3PersonioJobs\\Tests\\": "Tests/"
}
},
"config": {
"allow-plugins": {
"ergebnis/composer-normalize": true,
Expand Down Expand Up @@ -85,6 +97,14 @@
"sca": [
"@sca:php"
],
"sca:php": "phpstan analyse -c phpstan.neon"
"sca:php": "phpstan analyse -c phpstan.neon",
"test": [
"@test:unit"
],
"test:coverage": [
"@test:coverage:unit"
],
"test:coverage:unit": "phpunit -c phpunit.unit.coverage.xml",
"test:unit": "phpunit -c phpunit.unit.xml"
}
}
Loading