Skip to content
Open
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
47 changes: 47 additions & 0 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: SonarCloud Analysis

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]

jobs:
sonarcloud:
name: SonarCloud Code Analysis
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: pcov, mbstring, xml, ctype, json, bcmath
coverage: pcov

- name: Set up environment variables
run: |
echo "APP_ENV=testing" >> $GITHUB_ENV
echo "APP_KEY=base64:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" >> $GITHUB_ENV
echo "DB_CONNECTION=sqlite" >> $GITHUB_ENV
echo "DB_DATABASE=:memory:" >> $GITHUB_ENV
echo "APP_LOG_LEVEL=notice" >> $GITHUB_ENV
echo "AUDIT_LOG_LEVEL=emergency" >> $GITHUB_ENV

- name: Install Composer dependencies
run: composer install --prefer-dist --no-progress --no-suggest --no-interaction

- name: Run unit tests with coverage
run: ./vendor/bin/phpunit --testsuite=unit --coverage-clover=coverage.xml

- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</include>
</source>
<coverage ignoreDeprecatedCodeUnits="true"
pathCoverage="true">
pathCoverage="false">
<report>
<clover outputFile="coverage.xml"/>
</report>
Expand Down
203 changes: 203 additions & 0 deletions tests/unit/Support/AmountGetAmountJsConfigTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
<?php

declare(strict_types=1);

namespace Tests\unit\Support;

use FireflyIII\Support\Amount;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\integration\TestCase;

final class AmountGetAmountJsConfigTest extends TestCase
{
#[DataProvider('provideFormatConfigurations')]
public function testGetAmountJsConfigReturnsExpectedFormat(
bool $sepBySpace,
int $signPosn,
string $sign,
bool $csPrecedes,
string $expected
): void {
$result = Amount::getAmountJsConfig($sepBySpace, $signPosn, $sign, $csPrecedes);
$this->assertSame($expected, $result);
}

public static function provideFormatConfigurations(): iterable
{
yield 'parentheses around all, currency before, with space' => [
true,
0,
'-',
true,
'(%s %v)',
];

yield 'parentheses around all, currency before, no space' => [
false,
0,
'-',
true,
'(%s%v)',
];

yield 'parentheses around all, currency after, with space' => [
true,
0,
'-',
false,
'(%v %s)',
];

yield 'parentheses around all, currency after, no space' => [
false,
0,
'-',
false,
'(%v%s)',
];

yield 'sign before all, currency before, with space' => [
true,
1,
'-',
true,
'-%s %v',
];

yield 'sign before all, currency before, no space' => [
false,
1,
'-',
true,
'-%s%v',
];

yield 'sign before all, currency after, with space' => [
true,
1,
'-',
false,
'-%v %s',
];

yield 'sign before all, currency after, no space' => [
false,
1,
'-',
false,
'-%v%s',
];

yield 'sign after all, currency before, with space' => [
true,
2,
'-',
true,
'%s %v-',
];

yield 'sign after all, currency before, no space' => [
false,
2,
'-',
true,
'%s%v-',
];

yield 'sign after all, currency after, with space' => [
true,
2,
'-',
false,
'%v %s-',
];

yield 'sign after all, currency after, no space' => [
false,
2,
'-',
false,
'%v%s-',
];

yield 'sign before symbol, currency before, with space' => [
true,
3,
'-',
true,
'-%s %v',
];

yield 'sign before symbol, currency before, no space' => [
false,
3,
'-',
true,
'-%s%v',
];

yield 'sign before symbol, currency after, with space' => [
true,
3,
'-',
false,
'%v -%s',
];

yield 'sign before symbol, currency after, no space' => [
false,
3,
'-',
false,
'%v-%s',
];

yield 'sign after symbol, currency before, with space' => [
true,
4,
'-',
true,
'%s- %v',
];

yield 'sign after symbol, currency before, no space' => [
false,
4,
'-',
true,
'%s-%v',
];

yield 'sign after symbol, currency after, with space' => [
true,
4,
'-',
false,
'%v %s-',
];

yield 'sign after symbol, currency after, no space' => [
false,
4,
'-',
false,
'%v%s-',
];

yield 'positive sign, sign before all' => [
true,
1,
'+',
true,
'+%s %v',
];

yield 'custom sign character' => [
false,
1,
'−',
false,
'−%v%s',
];
}
}
Loading
Loading