Skip to content

Allow Symfony 7 & Add tests #3

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

Merged
merged 5 commits into from
Sep 5, 2024
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
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.gitattributes export-ignore
.gitignore export-ignore
tests/ export-ignore
LICENSE export-ignore
*.md export-ignore
56 changes: 56 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: "Tests"

on:
pull_request: null
push:
branches:
- "master"

jobs:
phpunit:
name: "PHPUnit"
runs-on: ubuntu-latest

strategy:
matrix:
include:
- php-version: '5.6'
phpunit-version: '5.7'
symfony-version: '2.7.*'
- php-version: '5.6'
phpunit-version: '5.7'
symfony-version: '2.8.*'
- php-version: '5.6'
phpunit-version: '5.7'
symfony-version: '3.4.*'
- php-version: '7.4'
phpunit-version: '9.6'
symfony-version: '4.4.*'
- php-version: '7.4'
phpunit-version: '9.6'
symfony-version: '5.4.*'
- php-version: '8.3'
phpunit-version: '11.3'
symfony-version: '6.4.*'
- php-version: '8.3'
phpunit-version: '11.3'
symfony-version: '7.1.*'

steps:
- name: "Checkout"
uses: actions/checkout@v2

- name: "Setup PHP"
uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: ${{ matrix.php-version }}

- name: "Install dependencies with composer"
run: |
composer require --no-update symfony/dependency-injection:${{ matrix.symfony-version }}
composer require --no-update --dev phpunit/phpunit:${{ matrix.phpunit-version }}
composer update --no-interaction --no-progress

- name: "Run tests with phpunit/phpunit"
run: vendor/bin/phpunit
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.idea
/.phpunit.result.cache
/vendor/
/composer.lock
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2024 Yann Eugoné

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
],
"require": {
"php": ">=5.5.9",
"symfony/dependency-injection": "^2.7|^3.0|^4.0|^5.0|^6.0"
"symfony/dependency-injection": "^2.7|^3.0|^4.0|^5.0|^6.0|^7.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7"
},
"autoload": {
"psr-4": { "Yokai\\DependencyInjection\\": "src" }
Expand Down
20 changes: 20 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
colors="true"
>
<testsuites>
<testsuite name="Tests">
<directory>./tests</directory>
</testsuite>
</testsuites>

<coverage>
<include>
<directory>./src</directory>
</include>
</coverage>
</phpunit>
19 changes: 19 additions & 0 deletions tests/CompilerPass/AdderRegisterTaggedServicesCompilerPassTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Yokai\DependencyInjection\Tests\CompilerPass;

use Yokai\DependencyInjection\CompilerPass\AdderRegisterTaggedServicesCompilerPass;
use Yokai\DependencyInjection\Tests\Fixtures\ServiceInterface;

class AdderRegisterTaggedServicesCompilerPassTest extends RegisterTaggedServicesCompilerPassTestCase
{
protected function createCompilerPass()
{
return new AdderRegisterTaggedServicesCompilerPass(
'registry',
'service',
ServiceInterface::class,
'addService'
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Yokai\DependencyInjection\Tests\CompilerPass;

use Yokai\DependencyInjection\CompilerPass\ArgumentRegisterTaggedServicesCompilerPass;
use Yokai\DependencyInjection\Tests\Fixtures\ServiceInterface;

class ArgumentRegisterTaggedServicesCompilerPassTest extends RegisterTaggedServicesCompilerPassTestCase
{
protected function createCompilerPass()
{
return new ArgumentRegisterTaggedServicesCompilerPass(
'registry',
'service',
ServiceInterface::class,
0
);
}
}
40 changes: 40 additions & 0 deletions tests/CompilerPass/RegisterTaggedServicesCompilerPassTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Yokai\DependencyInjection\Tests\CompilerPass;

use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Yokai\DependencyInjection\Tests\Fixtures\Service1;
use Yokai\DependencyInjection\Tests\Fixtures\Service2;
use Yokai\DependencyInjection\Tests\Fixtures\Service3;
use Yokai\DependencyInjection\Tests\Fixtures\ServiceRegistry;

abstract class RegisterTaggedServicesCompilerPassTestCase extends TestCase
{
public function test()
{
$container = new ContainerBuilder();
$container->setDefinition('registry', (new Definition(ServiceRegistry::class, [[]]))->setPublic(true));
$container->setDefinition('service1', (new Definition(Service1::class))->addTag('service'));
$container->setDefinition('service2', (new Definition(Service2::class))->addTag('service'));
$container->setDefinition('service3', (new Definition(Service3::class))->addTag('service'));

$container->addCompilerPass($this->createCompilerPass());
$container->compile();

/** @var ServiceRegistry|mixed $registry */
$registry = $container->get('registry');
self::assertInstanceOf(ServiceRegistry::class, $registry);
self::assertCount(3, $registry->services);
self::assertInstanceOf(Service1::class, $registry->services[0]);
self::assertInstanceOf(Service2::class, $registry->services[1]);
self::assertInstanceOf(Service3::class, $registry->services[2]);
}

/**
* @return CompilerPassInterface
*/
abstract protected function createCompilerPass();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Yokai\DependencyInjection\Tests\CompilerPass;

use Yokai\DependencyInjection\CompilerPass\SetterRegisterTaggedServicesCompilerPass;
use Yokai\DependencyInjection\Tests\Fixtures\ServiceInterface;

class SetterRegisterTaggedServicesCompilerPassTest extends RegisterTaggedServicesCompilerPassTestCase
{
protected function createCompilerPass()
{
return new SetterRegisterTaggedServicesCompilerPass(
'registry',
'service',
ServiceInterface::class,
'setServices'
);
}
}
7 changes: 7 additions & 0 deletions tests/Fixtures/Service1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Yokai\DependencyInjection\Tests\Fixtures;

class Service1 implements ServiceInterface
{
}
7 changes: 7 additions & 0 deletions tests/Fixtures/Service2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Yokai\DependencyInjection\Tests\Fixtures;

class Service2 implements ServiceInterface
{
}
7 changes: 7 additions & 0 deletions tests/Fixtures/Service3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Yokai\DependencyInjection\Tests\Fixtures;

class Service3 implements ServiceInterface
{
}
8 changes: 8 additions & 0 deletions tests/Fixtures/ServiceInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Yokai\DependencyInjection\Tests\Fixtures;

interface ServiceInterface
{

}
29 changes: 29 additions & 0 deletions tests/Fixtures/ServiceRegistry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Yokai\DependencyInjection\Tests\Fixtures;

class ServiceRegistry
{
/**
* @var array<ServiceInterface>
*/
public $services;

public function __construct(array $services = [])
{
$this->services = $services;
}

/**
* @param array<ServiceInterface> $services
*/
public function setServices(array $services)
{
$this->services = $services;
}

public function addService(ServiceInterface $service)
{
$this->services[] = $service;
}
}
Loading