Skip to content

Commit 0968bb7

Browse files
committed
codestyle
1 parent d9d6521 commit 0968bb7

File tree

7 files changed

+156
-135
lines changed

7 files changed

+156
-135
lines changed

.editorconfig

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
root = true
2+
3+
[*.php]
4+
indent_style = space
5+
indent_size = 2
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
9+
[*.{yml,yaml}]
10+
indent_style = space
11+
indent_size = 2
12+
charset = utf-8
13+
trim_trailing_whitespace = true
14+
15+
[*.md]
16+
indent_style = space
17+
indent_size = 4
18+
charset = utf-8
19+
20+
[*.json]
21+
indent_size = 2
22+
charset = utf-8

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Symfony DI component loader
22

3+
[![phpunit](https://github.com/alexpts/php-symfony-di-loader/actions/workflows/phpunit.yml/badge.svg?branch=master)](https://github.com/alexpts/php-symfony-di-loader/actions/workflows/phpunit.yml)
34
[![codecov](https://codecov.io/gh/alexpts/php-symfony-di-loader/branch/master/graph/badge.svg?token=14L6IJA5UE)](https://codecov.io/gh/alexpts/php-symfony-di-loader)
45

56
Simple loader for symfony [DependencyInjection component]( https://symfony.com/doc/current/components/dependency_injection.html)

src/Dumper.php

-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public function dumpMeta(string $filePath, ContainerBuilder $container, CacheWat
4949

5050
protected function getAllWatchFiles(ContainerBuilder $container, CacheWatcher $cacheWatcher): array
5151
{
52-
5352
$reflectionExtractor = fn(): ReflectionClass => $this->classReflector; // $this => ReflectionClassResource
5453

5554
$watch = [];
@@ -81,7 +80,6 @@ protected function getAllWatchFiles(ContainerBuilder $container, CacheWatcher $c
8180
];
8281
array_push($watch, ...$autoloadFiles);
8382
}
84-
continue;
8583
}
8684
}
8785

test/unit/DumperTest.php

+21-21
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,28 @@
1212
class DumperTest extends TestCase
1313
{
1414

15-
public function testDumpBadPath(): void
16-
{
17-
$dumper = new Dumper;
18-
$container = new ContainerBuilder;
19-
$container->compile();
15+
public function testDumpBadPath(): void
16+
{
17+
$dumper = new Dumper;
18+
$container = new ContainerBuilder;
19+
$container->compile();
2020

21-
$this->expectException(RuntimeException::class);
22-
$this->expectExceptionCode(0);
23-
$this->expectExceptionMessage('Can`t dump cache for DI container');
24-
$dumper->dump('/bad/path/', 'AppContainer', $container);
25-
}
21+
$this->expectException(RuntimeException::class);
22+
$this->expectExceptionCode(0);
23+
$this->expectExceptionMessage('Can`t dump cache for DI container');
24+
$dumper->dump('/bad/path/', 'AppContainer', $container);
25+
}
2626

27-
public function testDumpMetaBadPath(): void
28-
{
29-
$dumper = new Dumper;
30-
$container = new ContainerBuilder;
31-
$container->compile();
32-
$watcher = new CacheWatcher;
27+
public function testDumpMetaBadPath(): void
28+
{
29+
$dumper = new Dumper;
30+
$container = new ContainerBuilder;
31+
$container->compile();
32+
$watcher = new CacheWatcher;
3333

34-
$this->expectException(RuntimeException::class);
35-
$this->expectExceptionCode(0);
36-
$this->expectExceptionMessage('Can`t dump meta for DI container');
37-
$dumper->dumpMeta('/bad/path/', $container, $watcher);
38-
}
34+
$this->expectException(RuntimeException::class);
35+
$this->expectExceptionCode(0);
36+
$this->expectExceptionMessage('Can`t dump meta for DI container');
37+
$dumper->dumpMeta('/bad/path/', $container, $watcher);
38+
}
3939
}

test/unit/LoaderContainerTest.php

+99-99
Original file line numberDiff line numberDiff line change
@@ -15,103 +15,103 @@
1515

1616
class LoaderContainerTest extends TestCase
1717
{
18-
protected function setUp(): void
19-
{
20-
parent::setUp();
21-
vfsStream::setup('/temp/');
22-
}
23-
24-
protected function tearDown(): void
25-
{
26-
vfsStreamWrapper::unregister();
27-
parent::tearDown();
28-
}
29-
30-
public function testConstructor(): void
31-
{
32-
$loader = new LoaderContainer;
33-
static::assertInstanceOf(LoaderContainerInterface::class, $loader);
34-
}
35-
36-
public function testAddExtension(): void
37-
{
38-
$loader = new LoaderContainer;
39-
$prop = new ReflectionProperty($loader, 'extensions');
40-
$prop->setAccessible(true);
41-
42-
static::assertCount(0, $prop->getValue($loader));
43-
44-
$loader = $loader->addExtension(new TestExtension);
45-
static::assertInstanceOf(LoaderContainerInterface::class, $loader);
46-
static::assertCount(1, $prop->getValue($loader));
47-
}
48-
49-
public function testSetCheckExpired(): void
50-
{
51-
$loader = new LoaderContainer;
52-
$prop = new ReflectionProperty($loader, 'checkExpired');
53-
$prop->setAccessible(true);
54-
55-
static::assertTrue($prop->getValue($loader));
56-
57-
$loader = $loader->setCheckExpired(false);
58-
static::assertInstanceOf(LoaderContainerInterface::class, $loader);
59-
static::assertFalse($prop->getValue($loader));
60-
61-
$loader = $loader->setCheckExpired(true);
62-
static::assertTrue($prop->getValue($loader));
63-
}
64-
65-
public function testGetWatcher(): void
66-
{
67-
$loader = new LoaderContainer;
68-
static::assertInstanceOf(CacheWatcher::class, $loader->getWatcher());
69-
}
70-
71-
public function testGetContainer(): void
72-
{
73-
$loader = new LoaderContainer;
74-
$container = $loader->getContainer([__DIR__ .'/config/di.yml'], 'vfs://temp/cache.php');
75-
static::assertInstanceOf(ContainerBuilder::class, $container);
76-
static::assertInstanceOf(Container::class, $container);
77-
static::assertFileExists('vfs://temp/cache.php');
78-
static::assertFileExists('vfs://temp/cache.php.v2.meta');
79-
}
80-
81-
public function testGetContainerFromCacheFile(): void
82-
{
83-
// build case
84-
$loader = new LoaderContainer;
85-
$container = $loader->getContainer([__DIR__ .'/config/di.yml'], 'vfs://temp/cache.php');
86-
static::assertInstanceOf(ContainerBuilder::class, $container);
87-
88-
// file cache case
89-
$loader->clearProcessCache();
90-
$container2 = $loader->getContainer([__DIR__ .'/config/di.yml'], 'vfs://temp/cache.php');
91-
static::assertNotInstanceOf(ContainerBuilder::class, $container2);
92-
static::assertInstanceOf(Container::class, $container2);
93-
}
94-
95-
public function testGetContainerFromCacheProcess(): void
96-
{
97-
// Build
98-
$loader = new LoaderContainer;
99-
$loader->getContainer([__DIR__ .'/config/di.yml'], 'vfs://temp/cache.php');
100-
101-
// Process cache
102-
$container = $loader->getContainer([__DIR__ .'/config/di.yml'], 'vfs://temp/cache.php');
103-
static::assertInstanceOf(ContainerBuilder::class, $container);
104-
105-
// file cache
106-
$loader->clearProcessCache();
107-
$container = $loader->getContainer([__DIR__ .'/config/di.yml'], 'vfs://temp/cache.php');
108-
static::assertNotInstanceOf(ContainerBuilder::class, $container);
109-
static::assertInstanceOf(Container::class, $container);
110-
111-
// Process cache
112-
unlink('vfs://temp/cache.php');
113-
$container = $loader->getContainer([__DIR__ .'/config/di.yml'], 'vfs://temp/cache.php');
114-
static::assertNotInstanceOf(ContainerBuilder::class, $container);
115-
static::assertInstanceOf(Container::class, $container);
116-
}
18+
protected function setUp(): void
19+
{
20+
parent::setUp();
21+
vfsStream::setup('/temp/');
22+
}
23+
24+
protected function tearDown(): void
25+
{
26+
vfsStreamWrapper::unregister();
27+
parent::tearDown();
28+
}
29+
30+
public function testConstructor(): void
31+
{
32+
$loader = new LoaderContainer;
33+
static::assertInstanceOf(LoaderContainerInterface::class, $loader);
34+
}
35+
36+
public function testAddExtension(): void
37+
{
38+
$loader = new LoaderContainer;
39+
$prop = new ReflectionProperty($loader, 'extensions');
40+
$prop->setAccessible(true);
41+
42+
static::assertCount(0, $prop->getValue($loader));
43+
44+
$loader = $loader->addExtension(new TestExtension);
45+
static::assertInstanceOf(LoaderContainerInterface::class, $loader);
46+
static::assertCount(1, $prop->getValue($loader));
47+
}
48+
49+
public function testSetCheckExpired(): void
50+
{
51+
$loader = new LoaderContainer;
52+
$prop = new ReflectionProperty($loader, 'checkExpired');
53+
$prop->setAccessible(true);
54+
55+
static::assertTrue($prop->getValue($loader));
56+
57+
$loader = $loader->setCheckExpired(false);
58+
static::assertInstanceOf(LoaderContainerInterface::class, $loader);
59+
static::assertFalse($prop->getValue($loader));
60+
61+
$loader = $loader->setCheckExpired(true);
62+
static::assertTrue($prop->getValue($loader));
63+
}
64+
65+
public function testGetWatcher(): void
66+
{
67+
$loader = new LoaderContainer;
68+
static::assertInstanceOf(CacheWatcher::class, $loader->getWatcher());
69+
}
70+
71+
public function testGetContainer(): void
72+
{
73+
$loader = new LoaderContainer;
74+
$container = $loader->getContainer([__DIR__ . '/config/di.yml'], 'vfs://temp/cache.php');
75+
static::assertInstanceOf(ContainerBuilder::class, $container);
76+
static::assertInstanceOf(Container::class, $container);
77+
static::assertFileExists('vfs://temp/cache.php');
78+
static::assertFileExists('vfs://temp/cache.php.v2.meta');
79+
}
80+
81+
public function testGetContainerFromCacheFile(): void
82+
{
83+
// build case
84+
$loader = new LoaderContainer;
85+
$container = $loader->getContainer([__DIR__ . '/config/di.yml'], 'vfs://temp/cache.php');
86+
static::assertInstanceOf(ContainerBuilder::class, $container);
87+
88+
// file cache case
89+
$loader->clearProcessCache();
90+
$container2 = $loader->getContainer([__DIR__ . '/config/di.yml'], 'vfs://temp/cache.php');
91+
static::assertNotInstanceOf(ContainerBuilder::class, $container2);
92+
static::assertInstanceOf(Container::class, $container2);
93+
}
94+
95+
public function testGetContainerFromCacheProcess(): void
96+
{
97+
// Build
98+
$loader = new LoaderContainer;
99+
$loader->getContainer([__DIR__ . '/config/di.yml'], 'vfs://temp/cache.php');
100+
101+
// Process cache
102+
$container = $loader->getContainer([__DIR__ . '/config/di.yml'], 'vfs://temp/cache.php');
103+
static::assertInstanceOf(ContainerBuilder::class, $container);
104+
105+
// file cache
106+
$loader->clearProcessCache();
107+
$container = $loader->getContainer([__DIR__ . '/config/di.yml'], 'vfs://temp/cache.php');
108+
static::assertNotInstanceOf(ContainerBuilder::class, $container);
109+
static::assertInstanceOf(Container::class, $container);
110+
111+
// Process cache
112+
unlink('vfs://temp/cache.php');
113+
$container = $loader->getContainer([__DIR__ . '/config/di.yml'], 'vfs://temp/cache.php');
114+
static::assertNotInstanceOf(ContainerBuilder::class, $container);
115+
static::assertInstanceOf(Container::class, $container);
116+
}
117117
}

test/unit/config/di.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
services:
2-
_defaults:
3-
autowire: true
4-
autoconfigure: false
5-
public: true
2+
_defaults:
3+
autowire: true
4+
autoconfigure: false
5+
public: true
66

7-
PTS\SymfonyDiLoader\CacheWatcher: ~
7+
PTS\SymfonyDiLoader\CacheWatcher: ~
88

99
imports:
10-
- { resource: import.yml }
10+
- { resource: import.yml }

test/unit/config/import.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
services:
2-
_defaults:
3-
autowire: true
4-
autoconfigure: false
5-
public: true
2+
_defaults:
3+
autowire: true
4+
autoconfigure: false
5+
public: true
66

7-
Symfony\Component\Config\FileLocator: ~
8-
PTS\SymfonyDiLoader\FactoryContainer:
9-
arguments: [Symfony\Component\DependencyInjection\Loader\YamlFileLoader, '@Symfony\Component\Config\FileLocator']
7+
Symfony\Component\Config\FileLocator: ~
8+
PTS\SymfonyDiLoader\FactoryContainer:
9+
arguments: [ Symfony\Component\DependencyInjection\Loader\YamlFileLoader, '@Symfony\Component\Config\FileLocator' ]

0 commit comments

Comments
 (0)