Skip to content
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
11 changes: 5 additions & 6 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/.docker export-ignore
/.git* export-ignore
/.php-cs-fixer.php export-ignore
/*.md export-ignore
/*.svg export-ignore
/CHANGELOG.md export-ignore
/CONTRIBUTING.md export-ignore
/docker-compose.yml export-ignore
/compose.yml export-ignore
/doc export-ignore
/features export-ignore
/phpspec*.yml export-ignore
/Makefile export-ignore
/phpunit.xml export-ignore
/psalm.xml export-ignore
/README.md export-ignore
/spec export-ignore
4 changes: 2 additions & 2 deletions .github/workflows/commit-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ on: [pull_request]

jobs:
commit-lint:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7
with:
fetch-depth: ${{ github.event.pull_request.commits }}
ref: ${{ github.event.pull_request.head.sha }}
Expand Down
93 changes: 21 additions & 72 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,101 +10,50 @@ jobs:
cs-fix:
runs-on: ubuntu-24.04
name: PHP-CS-Fixer
container:
image: php:8.1-cli

steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v7

- name: Install dependencies
run: |
apt-get update && apt-get install -y \
git unzip zip \
libzip-dev libpng-dev libjpeg-dev libfreetype6-dev

docker-php-ext-configure gd --with-freetype --with-jpeg
docker-php-ext-install gd zip

curl -sS https://getcomposer.org/installer | php \
-- --install-dir=/usr/local/bin --filename=composer
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
extensions: gd, simplexml, zip
tools: composer:v2
coverage: none

composer install --prefer-dist --no-progress
- name: Install dependencies
uses: ramsey/composer-install@v4

- name: Run PHP CS Fixer
run: bin/php-cs-fixer fix --diff --dry-run


tests:
runs-on: ubuntu-24.04

strategy:
fail-fast: false
matrix:
php-version: ['8.1', '8.2', '8.3']

container:
image: php:${{ matrix.php-version }}-cli
php-version: ['8.1', '8.2', '8.3', '8.4', '8.5']

steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v7

- name: Install system dependencies
run: |
apt-get update && apt-get install -y \
git unzip zip \
libpng-dev libjpeg-dev libfreetype6-dev libzip-dev

- name: Install PHP extensions
run: |
docker-php-ext-configure gd --with-freetype --with-jpeg
docker-php-ext-install gd zip

- name: Install Composer
run: |
curl -sS https://getcomposer.org/installer | php \
-- --install-dir=/usr/local/bin --filename=composer
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: gd, simplexml, zip
tools: composer:v2
coverage: none

- name: Validate composer.json
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress
uses: ramsey/composer-install@v4

- name: Run tests
run: bin/phpunit --display-warnings --do-not-fail-on-warning


tests-php84:
runs-on: ubuntu-24.04
container:
image: php:8.4-cli

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install system dependencies
run: |
apt-get update && apt-get install -y \
git unzip zip \
libpng-dev libjpeg-dev libfreetype6-dev libzip-dev

- name: Install PHP extensions
run: |
docker-php-ext-configure gd --with-freetype --with-jpeg
docker-php-ext-install gd zip

- name: Install Composer
run: |
curl -sS https://getcomposer.org/installer | php \
-- --install-dir=/usr/local/bin --filename=composer

- name: Validate composer.json
run: composer validate

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

- name: Run tests
run: bin/phpunit --display-warnings --do-not-fail-on-warning
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v7

- name: Conventional Changelog Action
id: changelog
Expand Down
4 changes: 2 additions & 2 deletions tests/Calculator/GDTextSizeCalculatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public function itShouldComputeTextWidthWithSize8(): void
public function itShouldComputeTextWidthWithSize10(): void
{
$width = $this->calculator->calculateWidth('MIT', 10);
$this->assertEquals(29.0, $width);
$this->assertEqualsWithDelta(29.0, $width, 2.0);
}

#[Test]
public function itShouldComputeTextWidthWithSize14(): void
{
$width = $this->calculator->calculateWidth('MIT', 14);
$this->assertEquals(34.0, $width);
$this->assertEqualsWithDelta(34.0, $width, 2.0);
}

#[Test]
Expand Down
20 changes: 17 additions & 3 deletions tests/Render/SvgForTheBadgeRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,31 @@
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use PUGX\Poser\Badge;
use PUGX\Poser\Calculator\GDTextSizeCalculator;
use PUGX\Poser\Calculator\TextSizeCalculatorInterface;
use PUGX\Poser\Render\SvgForTheBadgeRenderer;

class SvgForTheBadgeRendererTest extends TestCase
{
private GDTextSizeCalculator $calculator;
private TextSizeCalculatorInterface $calculator;
private SvgForTheBadgeRenderer $render;

protected function setUp(): void
{
$this->calculator = new GDTextSizeCalculator();
$this->calculator = $this->createMock(TextSizeCalculatorInterface::class);
$this->calculator->method('calculateWidth')->willReturnCallback(static function (string $text): float {
$widths = [
'VERSION' => 53.0,
'STABLE' => 43.0,
'LICENSE' => 55.0,
'MIT' => 28.0,
'BUILD' => 42.0,
'PASSING' => 57.0,
'TEST' => 30.0,
'LOWERCASE' => 67.0,
];

return $widths[$text] ?? (float) (\strlen($text) * 8);
});
$this->render = new SvgForTheBadgeRenderer($this->calculator);
}

Expand Down
17 changes: 14 additions & 3 deletions tests/Render/SvgSocialRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,28 @@
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use PUGX\Poser\Badge;
use PUGX\Poser\Calculator\GDTextSizeCalculator;
use PUGX\Poser\Calculator\TextSizeCalculatorInterface;
use PUGX\Poser\Render\SvgSocialRender;

class SvgSocialRenderTest extends TestCase
{
private GDTextSizeCalculator $calculator;
private TextSizeCalculatorInterface $calculator;
private SvgSocialRender $render;

protected function setUp(): void
{
$this->calculator = new GDTextSizeCalculator();
$this->calculator = $this->createMock(TextSizeCalculatorInterface::class);
$this->calculator->method('calculateWidth')->willReturnCallback(static function (string $text): float {
$widths = [
'twitter' => 46.0,
'follow' => 43.0,
'github' => 45.0,
'stars' => 38.0,
'test' => 24.0,
];

return $widths[$text] ?? (float) (\strlen($text) * 7);
});
$this->render = new SvgSocialRender($this->calculator);
}

Expand Down