Skip to content

Commit 84d4357

Browse files
authored
Allow Symfony 7 & Add tests
* Add phpunit * Allow Symfony 7 * Add PHPUnit tests * Add Github workflow to run tests * Add missing base files
1 parent d0271d3 commit 84d4357

15 files changed

+263
-1
lines changed

.gitattributes

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.gitattributes export-ignore
2+
.gitignore export-ignore
3+
tests/ export-ignore
4+
LICENSE export-ignore
5+
*.md export-ignore

.github/workflows/tests.yml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: "Tests"
2+
3+
on:
4+
pull_request: null
5+
push:
6+
branches:
7+
- "master"
8+
9+
jobs:
10+
phpunit:
11+
name: "PHPUnit"
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
include:
17+
- php-version: '5.6'
18+
phpunit-version: '5.7'
19+
symfony-version: '2.7.*'
20+
- php-version: '5.6'
21+
phpunit-version: '5.7'
22+
symfony-version: '2.8.*'
23+
- php-version: '5.6'
24+
phpunit-version: '5.7'
25+
symfony-version: '3.4.*'
26+
- php-version: '7.4'
27+
phpunit-version: '9.6'
28+
symfony-version: '4.4.*'
29+
- php-version: '7.4'
30+
phpunit-version: '9.6'
31+
symfony-version: '5.4.*'
32+
- php-version: '8.3'
33+
phpunit-version: '11.3'
34+
symfony-version: '6.4.*'
35+
- php-version: '8.3'
36+
phpunit-version: '11.3'
37+
symfony-version: '7.1.*'
38+
39+
steps:
40+
- name: "Checkout"
41+
uses: actions/checkout@v2
42+
43+
- name: "Setup PHP"
44+
uses: shivammathur/setup-php@v2
45+
with:
46+
coverage: none
47+
php-version: ${{ matrix.php-version }}
48+
49+
- name: "Install dependencies with composer"
50+
run: |
51+
composer require --no-update symfony/dependency-injection:${{ matrix.symfony-version }}
52+
composer require --no-update --dev phpunit/phpunit:${{ matrix.phpunit-version }}
53+
composer update --no-interaction --no-progress
54+
55+
- name: "Run tests with phpunit/phpunit"
56+
run: vendor/bin/phpunit

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/.idea
2+
/.phpunit.result.cache
3+
/vendor/
4+
/composer.lock

LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2024 Yann Eugoné
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

composer.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
],
1313
"require": {
1414
"php": ">=5.5.9",
15-
"symfony/dependency-injection": "^2.7|^3.0|^4.0|^5.0|^6.0"
15+
"symfony/dependency-injection": "^2.7|^3.0|^4.0|^5.0|^6.0|^7.0"
16+
},
17+
"require-dev": {
18+
"phpunit/phpunit": "^5.7"
1619
},
1720
"autoload": {
1821
"psr-4": { "Yokai\\DependencyInjection\\": "src" }

phpunit.xml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
6+
backupGlobals="false"
7+
colors="true"
8+
>
9+
<testsuites>
10+
<testsuite name="Tests">
11+
<directory>./tests</directory>
12+
</testsuite>
13+
</testsuites>
14+
15+
<coverage>
16+
<include>
17+
<directory>./src</directory>
18+
</include>
19+
</coverage>
20+
</phpunit>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Yokai\DependencyInjection\Tests\CompilerPass;
4+
5+
use Yokai\DependencyInjection\CompilerPass\AdderRegisterTaggedServicesCompilerPass;
6+
use Yokai\DependencyInjection\Tests\Fixtures\ServiceInterface;
7+
8+
class AdderRegisterTaggedServicesCompilerPassTest extends RegisterTaggedServicesCompilerPassTestCase
9+
{
10+
protected function createCompilerPass()
11+
{
12+
return new AdderRegisterTaggedServicesCompilerPass(
13+
'registry',
14+
'service',
15+
ServiceInterface::class,
16+
'addService'
17+
);
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Yokai\DependencyInjection\Tests\CompilerPass;
4+
5+
use Yokai\DependencyInjection\CompilerPass\ArgumentRegisterTaggedServicesCompilerPass;
6+
use Yokai\DependencyInjection\Tests\Fixtures\ServiceInterface;
7+
8+
class ArgumentRegisterTaggedServicesCompilerPassTest extends RegisterTaggedServicesCompilerPassTestCase
9+
{
10+
protected function createCompilerPass()
11+
{
12+
return new ArgumentRegisterTaggedServicesCompilerPass(
13+
'registry',
14+
'service',
15+
ServiceInterface::class,
16+
0
17+
);
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Yokai\DependencyInjection\Tests\CompilerPass;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7+
use Symfony\Component\DependencyInjection\ContainerBuilder;
8+
use Symfony\Component\DependencyInjection\Definition;
9+
use Yokai\DependencyInjection\Tests\Fixtures\Service1;
10+
use Yokai\DependencyInjection\Tests\Fixtures\Service2;
11+
use Yokai\DependencyInjection\Tests\Fixtures\Service3;
12+
use Yokai\DependencyInjection\Tests\Fixtures\ServiceRegistry;
13+
14+
abstract class RegisterTaggedServicesCompilerPassTestCase extends TestCase
15+
{
16+
public function test()
17+
{
18+
$container = new ContainerBuilder();
19+
$container->setDefinition('registry', (new Definition(ServiceRegistry::class, [[]]))->setPublic(true));
20+
$container->setDefinition('service1', (new Definition(Service1::class))->addTag('service'));
21+
$container->setDefinition('service2', (new Definition(Service2::class))->addTag('service'));
22+
$container->setDefinition('service3', (new Definition(Service3::class))->addTag('service'));
23+
24+
$container->addCompilerPass($this->createCompilerPass());
25+
$container->compile();
26+
27+
/** @var ServiceRegistry|mixed $registry */
28+
$registry = $container->get('registry');
29+
self::assertInstanceOf(ServiceRegistry::class, $registry);
30+
self::assertCount(3, $registry->services);
31+
self::assertInstanceOf(Service1::class, $registry->services[0]);
32+
self::assertInstanceOf(Service2::class, $registry->services[1]);
33+
self::assertInstanceOf(Service3::class, $registry->services[2]);
34+
}
35+
36+
/**
37+
* @return CompilerPassInterface
38+
*/
39+
abstract protected function createCompilerPass();
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Yokai\DependencyInjection\Tests\CompilerPass;
4+
5+
use Yokai\DependencyInjection\CompilerPass\SetterRegisterTaggedServicesCompilerPass;
6+
use Yokai\DependencyInjection\Tests\Fixtures\ServiceInterface;
7+
8+
class SetterRegisterTaggedServicesCompilerPassTest extends RegisterTaggedServicesCompilerPassTestCase
9+
{
10+
protected function createCompilerPass()
11+
{
12+
return new SetterRegisterTaggedServicesCompilerPass(
13+
'registry',
14+
'service',
15+
ServiceInterface::class,
16+
'setServices'
17+
);
18+
}
19+
}

tests/Fixtures/Service1.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Yokai\DependencyInjection\Tests\Fixtures;
4+
5+
class Service1 implements ServiceInterface
6+
{
7+
}

tests/Fixtures/Service2.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Yokai\DependencyInjection\Tests\Fixtures;
4+
5+
class Service2 implements ServiceInterface
6+
{
7+
}

tests/Fixtures/Service3.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Yokai\DependencyInjection\Tests\Fixtures;
4+
5+
class Service3 implements ServiceInterface
6+
{
7+
}

tests/Fixtures/ServiceInterface.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Yokai\DependencyInjection\Tests\Fixtures;
4+
5+
interface ServiceInterface
6+
{
7+
8+
}

tests/Fixtures/ServiceRegistry.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Yokai\DependencyInjection\Tests\Fixtures;
4+
5+
class ServiceRegistry
6+
{
7+
/**
8+
* @var array<ServiceInterface>
9+
*/
10+
public $services;
11+
12+
public function __construct(array $services = [])
13+
{
14+
$this->services = $services;
15+
}
16+
17+
/**
18+
* @param array<ServiceInterface> $services
19+
*/
20+
public function setServices(array $services)
21+
{
22+
$this->services = $services;
23+
}
24+
25+
public function addService(ServiceInterface $service)
26+
{
27+
$this->services[] = $service;
28+
}
29+
}

0 commit comments

Comments
 (0)