Skip to content

Commit

Permalink
feat(symfony): Added symfony bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohan Giarelli committed Jan 13, 2025
1 parent af75644 commit d89f1cd
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 35 deletions.
10 changes: 3 additions & 7 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
vendor
build
bin
composer.phar
tests/Extension/Symfony/fixtures/app/var/
vendor/
.phpunit.result.cache
composer.lock
cache.properties
coverage.clover
docs/_build
10 changes: 2 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
tests/Extension/Symfony/fixtures/app/var/
vendor/
.phpunit.result.cache
vendor
build
bin
composer.phar
composer.lock
cache.properties
coverage.clover
docs/_build
.phpunit.result.cache
18 changes: 8 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ ARG DEPENDENCIES=highest

RUN set -eux; \
apk add --no-cache acl libzip; \
apk add --no-cache --virtual .build-deps ${PHPIZE_DEPS} zlib-dev libzip-dev linux-headers; \
apk add --no-cache --virtual .build-deps ${PHPIZE_DEPS} zlib-dev libzip-dev; \
docker-php-ext-install zip; \
pecl install xdebug;\
docker-php-ext-enable xdebug; \
pecl install pcov;\
docker-php-ext-enable pcov; \
apk del .build-deps;

RUN echo "xdebug.mode=coverage" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

WORKDIR /app
Expand All @@ -25,8 +23,8 @@ RUN set -eux; \
if [ "${DEPENDENCIES}" = "lowest" ]; then COMPOSER_MEMORY_LIMIT=-1 composer update --prefer-lowest --no-interaction; fi; \
if [ "${DEPENDENCIES}" = "highest" ]; then COMPOSER_MEMORY_LIMIT=-1 composer update --no-interaction; fi

COPY ./examples /app/examples
COPY ./src /app/src
COPY ./tests /app/tests
COPY ./phpunit.xml.dist /app/
COPY ./psalm.xml /app/
COPY --link ./examples /app/examples
COPY --link ./src /app/src
COPY --link ./tests /app/tests
COPY --link ./phpunit.xml.dist /app/
COPY --link ./psalm.xml /app/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cli:
docker run -it --rm -v${PWD}:/app -w/app yohang/finite ash

test:
docker run -it --rm -v${PWD}:/app -w/app yohang/finite php ./vendor/bin/phpunit
docker run -it --rm -v${PWD}:/app -w/app yohang/finite php ./vendor/bin/phpunit --coverage-text

test_all_targets:
docker build -t yohang/finite:php-8.1 --build-arg PHP_VERSION=8.1 .
Expand Down
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
],
"require": {
"php": ">=8.1",
"symfony/property-access": "^6.1|^7.0"
"symfony/property-access": ">=5.4,<8"
},
"require-dev": {
"phpunit/phpunit": "^10.5.40",
"symfony/var-dumper": "^6.1|^7.0",
"symfony/var-dumper": ">=5.4,<8",
"twig/twig": "^3.4",
"vimeo/psalm": "dev-master@dev"
"vimeo/psalm": "dev-master@dev",
"symfony/http-kernel": ">=5.4,<8",
"symfony/framework-bundle": ">=5.4,<8"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
colors="true"
bootstrap="tests/bootstrap.php"
bootstrap="tests/Extension/Symfony/fixtures/app/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd">
<source>
<include>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);

namespace Finite\Extension\Symfony\Bundle\DependencyInjection;

use Finite\Extension\Twig\FiniteExtension as TwigExtension;
use Finite\StateMachine;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Extension\Extension;

final class FiniteExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container): void
{
$container->addDefinitions(
[
StateMachine::class => (new Definition(StateMachine::class))->setPublic(true),
TwigExtension::class => new Definition(TwigExtension::class),
]
);
}
}
10 changes: 10 additions & 0 deletions src/Extension/Symfony/Bundle/FiniteBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);

namespace Finite\Extension\Symfony\Bundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

final class FiniteBundle extends Bundle
{
}
25 changes: 25 additions & 0 deletions tests/Extension/Symfony/ServiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);

namespace Finite\Tests\Extension\Symfony;

use Finite\Extension\Twig\FiniteExtension;
use Finite\StateMachine;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Bundle\FrameworkBundle\Test\TestContainer;

class ServiceTest extends KernelTestCase
{
public function test_services_are_registered(): void
{
/** @var TestContainer $container */
$container = static::getContainer();

$this->assertInstanceOf(StateMachine::class, $container->get(StateMachine::class));
}

protected static function getKernelClass(): string
{
return \AppKernel::class;
}
}
31 changes: 31 additions & 0 deletions tests/Extension/Symfony/fixtures/app/AppKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;

class AppKernel extends Kernel
{
use MicroKernelTrait;

public function registerBundles(): iterable
{
return [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Finite\Extension\Symfony\Bundle\FiniteBundle(),
];
}

protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader): void
{
$c->prependExtensionConfig('framework', ['test' => true]);
}

public function getProjectDir(): string
{
return __DIR__;
}

}
7 changes: 7 additions & 0 deletions tests/Extension/Symfony/fixtures/app/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
declare(strict_types=1);

$loader = require __DIR__ . '/../../../../../vendor/autoload.php';
require __DIR__.'/AppKernel.php';

return $loader;
5 changes: 0 additions & 5 deletions tests/bootstrap.php

This file was deleted.

0 comments on commit d89f1cd

Please sign in to comment.