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

Added tests and CI checks #4

Merged
merged 1 commit into from
Dec 20, 2023
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
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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

phpunit:
name: Unittest
runs-on: ubuntu-latest
container:
image: ghcr.io/elbformat/ibexa-icon-fieldtype/php
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: composer install
- name: Run tests
run: vendor/bin/phpunit

phpstan:
name: Static code analysis
runs-on: ubuntu-latest
container:
image: ghcr.io/elbformat/ibexa-icon-fieldtype/php
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: composer install
- name: Analyse
run: vendor/bin/phpstan
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
6 changes: 4 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,8 @@
"symfony/finder": "^5.4|^6.4"
},
"require-dev": {
"phpunit/phpunit": "^9.5"
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.6"
},
"config": {
"sort-packages": true,
Expand Down
11 changes: 11 additions & 0 deletions doc/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ Run tests
vendor/bin/phpunit
```

Run static code analysis
```bash
vendor/bin/phpstan
```

Fix styles (from outside the container)
```bash
docker-compose run phpcsfixer fix src
docker-compose run phpcsfixer 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
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ services:
image: ghcr.io/elbformat/ibexa-icon-fieldtype/php
volumes:
- ./:/var/www
phpcsfixer:
image: ghcr.io/elbformat/php-cs-fixer:edge-php8.2
volumes:
- ./:/code
11 changes: 5 additions & 6 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ RUN apk add --no-cache --virtual .build-deps autoconf g++ make linux-headers &&
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
4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: max
paths:
- src
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>
5 changes: 3 additions & 2 deletions 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 All @@ -11,7 +12,7 @@ class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('elbformat_icon');

/** @phpstan-ignore-next-line */
$treeBuilder->getRootNode()
->arrayPrototype() // Name of the set
->normalizeKeys(false)
Expand All @@ -29,4 +30,4 @@ public function getConfigTreeBuilder(): TreeBuilder

return $treeBuilder;
}
}
}
12 changes: 9 additions & 3 deletions 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 All @@ -13,6 +14,7 @@

class ElbformatIconExtension extends Extension implements PrependExtensionInterface
{
/** @param array<mixed> $configs */
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../../config/'));
Expand All @@ -28,8 +30,12 @@ public function load(array $configs, ContainerBuilder $container): void
public function prepend(ContainerBuilder $container): void
{
// Add template for rendering
$configFile = __DIR__.'/../../config/ezplatform.yaml';
$config = Yaml::parse(file_get_contents($configFile));
$configFile = file_get_contents(__DIR__.'/../../config/ezplatform.yaml');
if (false === $configFile) {
throw new \RuntimeException(sprintf('%s not found or not readable', __DIR__.'/../../config/ezplatform.yaml'));
}
/** @var array{'ezplatform':array<string,mixed>} $config */
$config = Yaml::parse($configFile);
$container->prependExtensionConfig('ezpublish', $config['ezplatform']);

// Register namespace (as this is not done automatically. Maybe the missing "bundle" in path?)
Expand All @@ -39,4 +45,4 @@ public function prepend(ContainerBuilder $container): void
$container->prependExtensionConfig('framework', ['translator' => ['paths' => [__DIR__.'/../../translations']]]);

}
}
}
5 changes: 3 additions & 2 deletions 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 @@ -9,7 +10,7 @@ class ElbformatIconBundle extends Bundle
{
public function getPath(): string
{
return realpath(__DIR__.'/..');
return dirname(__DIR__.'/..');
}

}
}
4 changes: 3 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 @@ -30,6 +31,7 @@ public function mapFieldValueForm(FormInterface $fieldForm, FieldData $data): vo
]);
}

/** @return array{'iconset':array{'type':string,'default':string}} */
public function getSettingsSchema(): array
{
return [
Expand All @@ -46,4 +48,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;
}
}
}
10 changes: 6 additions & 4 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)
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('iconset', ChoiceType::class,[
$builder->add('iconset', ChoiceType::class, [
'choices' => $this->iconSetManager->getSetList()
]);
}
}
}
9 changes: 5 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,18 +17,18 @@ final class IconType extends AbstractType
public function __construct(
private readonly IconSetManager $iconSetManager,
private readonly Environment $twig,
)
{
) {
}


public function buildForm(FormBuilderInterface $builder, array $options): void
{
/** @var string $iconSet */
$iconSet = $options['icon_set'];
$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 +48,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 string[] $items */
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;
}
}
}
Loading