This commit is contained in:
parent
1299a6c744
commit
d67a54a6b2
26
.gitea/workflows/test.yml
Normal file
26
.gitea/workflows/test.yml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
name: Run Unit Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- develop
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: phpunit_test
|
||||||
|
container: php:8.1-cli-alpine
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
apk add --no-cache git unzip
|
||||||
|
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
||||||
|
composer install --no-interaction --prefer-dist
|
||||||
|
|
||||||
|
- name: Run PHPUnit tests
|
||||||
|
run: |
|
||||||
|
vendor/bin/phpunit --configuration phpunit.xml
|
19
composer.json
Normal file
19
composer.json
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "example/php-woodpecker-demo",
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^9.5"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"App\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload-dev": {
|
||||||
|
"psr-4": {
|
||||||
|
"Tests\\": "tests/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "phpunit"
|
||||||
|
}
|
||||||
|
}
|
19
phpunit.xml
Normal file
19
phpunit.xml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit bootstrap="vendor/autoload.php"
|
||||||
|
colors="true"
|
||||||
|
verbose="true">
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="Default">
|
||||||
|
<directory>tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
|
||||||
|
<coverage processUncoveredFiles="true">
|
||||||
|
<include>
|
||||||
|
<directory>./src</directory>
|
||||||
|
</include>
|
||||||
|
<report>
|
||||||
|
<clover outputFile="coverage.xml"/>
|
||||||
|
</report>
|
||||||
|
</coverage>
|
||||||
|
</phpunit>
|
17
src/Calculator.php
Normal file
17
src/Calculator.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
class Calculator
|
||||||
|
{
|
||||||
|
public function add($a, $b)
|
||||||
|
{
|
||||||
|
return $a + $b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function subtract($a, $b)
|
||||||
|
{
|
||||||
|
$a = 1111;
|
||||||
|
return $a - $b;
|
||||||
|
}
|
||||||
|
}
|
13
tests/CalculatorTest.php
Normal file
13
tests/CalculatorTest.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use App\Calculator;
|
||||||
|
|
||||||
|
class CalculatorTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testAdd()
|
||||||
|
{
|
||||||
|
$calc = new Calculator();
|
||||||
|
$this->assertEquals(5, $calc->add(2, 3));
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user