Skip to content

Commit

Permalink
Added tests and CI checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannes Giesenow committed Dec 20, 2023
1 parent 701cf18 commit 66404e9
Show file tree
Hide file tree
Showing 19 changed files with 185 additions and 48 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: CI

on:
- pull_request
- push

jobs:
php-cs-fixer:
name: CS Fixer
runs-on: ubuntu-latest
container:
image: ghcr.io/elbformat/php-cs-fixer:edge-php8.2
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: check src
run: php-cs-fixer fix --dry-run src
- name: check tests
run: php-cs-fixer fix --dry-run tests
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/.idea
vendor/
/build
/vendor
.phpunit.result.cache
composer.lock
docker-compose.override.yml
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
],
"autoload": {
"psr-4": {
"Elbformat\\IconBundle\\": "src/"
"Elbformat\\IconBundle\\": "src/",
"Elbformat\\IconBundle\\Test\\": "tests/"
}
},
"require": {
Expand All @@ -27,7 +28,7 @@
"symfony/finder": "^5.4|^6.4"
},
"require-dev": {
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^9.6"
},
"config": {
"sort-packages": true,
Expand Down
6 changes: 6 additions & 0 deletions doc/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Run tests
vendor/bin/phpunit
```

Fix styles
```bash
docker run -v $(pwd):/code ghcr.io/elbformat/php-cs-fixer:edge-php8.2 fix src
docker run -v $(pwd):/code ghcr.io/elbformat/php-cs-fixer:edge-php8.2 fix tests
```

## In-Place development
If you want to test out how it integrates into ibexa, it's the easiest way to integrate the bundle into your project directly.
By adding it as "vcs" your are able to push the changes you made right from your vendor folder.
Expand Down
25 changes: 5 additions & 20 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,19 @@ FROM php:8.2-fpm-alpine

COPY --from=composer:2.5 /usr/bin/composer /usr/local/bin/composer

# ext-intl
RUN apk add --no-cache icu icu-data-full && \
apk add --no-cache --virtual .build-deps icu-dev && \
docker-php-ext-install intl && \
apk del .build-deps && \
rm -rf /tmp/*

#ext-xsl
RUN apk add --no-cache libxslt && \
apk add --no-cache --virtual .build-deps libxslt-dev && \
docker-php-ext-install xsl && \
apk del .build-deps && \
rm -rf /tmp/*

# xdebug
RUN apk add --no-cache --virtual .build-deps autoconf g++ make linux-headers && \
pecl install xdebug-3.2.1 && \
docker-php-ext-enable xdebug && \
apk del .build-deps && \
rm -rf /tmp/*

# ext-gd
RUN apk add --no-cache libpng libjpeg-turbo freetype && \
apk add --no-cache --virtual .build-deps libpng-dev libjpeg-turbo-dev freetype-dev && \
docker-php-ext-configure gd && \
docker-php-ext-install gd && \
# pcov
RUN apk add --no-cache --virtual .build-deps autoconf g++ make && \
pecl install pcov-1.0.11 && \
apk del .build-deps && \
rm -rf /tmp/*
rm -rf /tmp/* &&\
docker-php-ext-enable pcov

RUN rmdir /var/www/html
WORKDIR /var/www
24 changes: 24 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="true" backupStaticAttributes="false" colors="false" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" forceCoversAnnotation="false" processIsolation="false" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" stopOnRisky="false" verbose="false">
<coverage processUncoveredFiles="false">
<include>
<directory suffix=".php">src/</directory>
</include>
<report>
<clover outputFile="build/clover.xml"/>
<html outputDirectory="build/coverage/html" lowUpperBound="35" highLowerBound="70"/>
</report>
</coverage>
<testsuites>
<testsuite name="unit">
<directory>tests/</directory>
</testsuite>
</testsuites>
<logging>
<!-- <log type="coverage-php" target="/tmp/coverage.serialized"/>-->
<!-- <log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>-->
<junit outputFile="build/junit.xml"/>
<!-- <log type="testdox-html" target="/tmp/testdox.html"/>-->
<!-- <log type="testdox-text" target="/tmp/testdox.txt"/>-->
</logging>
</phpunit>
3 changes: 2 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Elbformat\IconBundle\DependencyInjection;
Expand Down Expand Up @@ -29,4 +30,4 @@ public function getConfigTreeBuilder(): TreeBuilder

return $treeBuilder;
}
}
}
3 changes: 2 additions & 1 deletion src/DependencyInjection/ElbformatIconExtension.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Elbformat\IconBundle\DependencyInjection;
Expand Down Expand Up @@ -39,4 +40,4 @@ public function prepend(ContainerBuilder $container): void
$container->prependExtensionConfig('framework', ['translator' => ['paths' => [__DIR__.'/../../translations']]]);

}
}
}
3 changes: 2 additions & 1 deletion src/ElbformatIconBundle.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Elbformat\IconBundle;
Expand All @@ -12,4 +13,4 @@ public function getPath(): string
return realpath(__DIR__.'/..');
}

}
}
3 changes: 2 additions & 1 deletion src/FieldType/Icon/Type.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Elbformat\IconBundle\FieldType\Icon;
Expand Down Expand Up @@ -46,4 +47,4 @@ public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, Field
'label' => false,
]);
}
}
}
10 changes: 7 additions & 3 deletions src/FieldType/Icon/Value.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Elbformat\IconBundle\FieldType\Icon;
Expand All @@ -9,11 +10,14 @@ final class Value implements ValueInterface
{
private ?string $icon;

public function __construct(?string $icon=null) { $this->icon = $icon; }
public function __construct(?string $icon = null)
{
$this->icon = $icon;
}

public function __toString(): string
{
return $this->icon;
return $this->icon ?? '';
}

public function getIcon(): ?string
Expand All @@ -25,4 +29,4 @@ public function setIcon(?string $icon): void
{
$this->icon = $icon;
}
}
}
8 changes: 5 additions & 3 deletions src/Form/Type/IconSettingsType.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Elbformat\IconBundle\Form\Type;
Expand All @@ -12,12 +13,13 @@ final class IconSettingsType extends AbstractType
{
public function __construct(
private readonly IconSetManager $iconSetManager,
) { }
) {
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('iconset', ChoiceType::class,[
$builder->add('iconset', ChoiceType::class, [
'choices' => $this->iconSetManager->getSetList()
]);
}
}
}
8 changes: 4 additions & 4 deletions src/Form/Type/IconType.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Elbformat\IconBundle\Form\Type;
Expand All @@ -16,8 +17,7 @@ final class IconType extends AbstractType
public function __construct(
private readonly IconSetManager $iconSetManager,
private readonly Environment $twig,
)
{
) {
}


Expand All @@ -27,7 +27,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
$iconList = $this->iconSetManager->getSet($iconSet)->getList();
$iconTemplates = [];
foreach($iconList as $icon) {
$iconTemplates[$icon] = $this->twig->render('@ElbformatIconFieldtype/icon.html.twig',['icon' => $icon,'iconset' => $iconSet]);
$iconTemplates[$icon] = $this->twig->render('@ElbformatIconFieldtype/icon.html.twig', ['icon' => $icon,'iconset' => $iconSet]);
}
$builder->add('icon', ChoiceType::class, [
'choices' => $iconList,
Expand All @@ -47,4 +47,4 @@ public function configureOptions(OptionsResolver $resolver): void
]);
$resolver->addAllowedTypes('icon_set', 'string');
}
}
}
7 changes: 4 additions & 3 deletions src/IconSet/IconSet.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Elbformat\IconBundle\IconSet;
Expand All @@ -8,17 +9,17 @@ class IconSet
/** @var array<string,string> */
protected array $items;

/** @param string[] */
/** @param $items string[] */
public function __construct(array $items)
{
// Convert to string => string array
$this->items = array_flip($items);
array_walk($this->items, fn(&$val, $key) => $val = $key);
array_walk($this->items, fn (&$val, $key) => $val = $key);
}

/** @return string[] */
public function getList(): array
{
return $this->items;
}
}
}
17 changes: 9 additions & 8 deletions src/IconSet/IconSetManager.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Elbformat\IconBundle\IconSet;
Expand All @@ -8,19 +9,19 @@
class IconSetManager
{
/** @var array<string,IconSet> */
protected array $sets;
protected array $sets = [];

/** array<string,array{?items:string[],?folder:string,?pattern:string} */
public function __construct(array $configs)
{
foreach ($configs as $setName => $setConfig) {
$items = [];
if (null !== ($setConfig['items']??null)) {
if (null !== ($setConfig['items'] ?? null)) {
$items = $setConfig['items'];
}
if (null !== ($setConfig['folder']??null)) {
$finder = (new Finder())->files()->in($setConfig['folder'])->depth(0);
if (null !== ($setConfig['pattern']??null)) {
if (null !== ($setConfig['folder'] ?? null)) {
$finder = (new Finder())->files()->in($setConfig['folder'])->depth(0)->sortByName();
if (null !== ($setConfig['pattern'] ?? null)) {
$finder = $finder->name($setConfig['pattern']);
}
foreach ($finder as $file) {
Expand All @@ -40,11 +41,11 @@ public function getSet(string $name): IconSet
}

/** @return array<string,string> */
public function getSetList():array
public function getSetList(): array
{
// Convert to string => string array
$sets = array_flip(array_keys($this->sets));
array_walk($sets, fn(&$val, $key) => $val = $key);
array_walk($sets, fn (&$val, $key) => $val = $key);
return $sets;
}
}
}
24 changes: 24 additions & 0 deletions tests/FieldType/Icon/ValueTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Elbformat\IconBundle\Test\FieldType\Icon;

use Elbformat\IconBundle\FieldType\Icon\Value;
use PHPUnit\Framework\TestCase;

class ValueTest extends TestCase
{
public function testAccess(): void
{
$value = new Value('icon1');
$this->assertSame('icon1', $value->getIcon());
$this->assertSame('icon1', (string) $value);
$value->setIcon(null);
$this->assertNull($value->getIcon());
$this->assertSame('', (string) $value);
$value->setIcon('value2');
$this->assertSame('value2', $value->getIcon());
$this->assertSame('value2', (string) $value);
}
}
Loading

0 comments on commit 66404e9

Please sign in to comment.