Skip to content

Commit

Permalink
Merge branch 'master' into path-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
elazar authored Aug 14, 2024
2 parents 375979e + 587cc30 commit 455d3c2
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 36 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
name: CI

on: [push]
on:
push: ~
pull_request: ~

jobs:
build-test:
name: PHPUnit tests on ${{ matrix.php }}
runs-on: ubuntu-latest

strategy:
matrix:
php: [ '8.1', '8.2', '8.3' ]
steps:
- uses: actions/checkout@v2
- uses: php-actions/composer@v6
Expand All @@ -14,3 +19,11 @@ jobs:
sudo chmod -R 777 vendor/pestphp/pest/.temp
vendor/bin/pest
build-code-style:
name: PHP-CS-Fixer checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: php-actions/composer@v6
- name: Run CS-Fixer
run: vendor/bin/php-cs-fixer check
7 changes: 7 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2024 Matthew Turland

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.
30 changes: 15 additions & 15 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ class Container implements ContainerInterface, IteratorAggregate
public function __construct()
{
$this->entries = [
FilesystemRegistry::class => fn() => new FilesystemRegistry,
PassThruPathNormalizer::class => fn() => new PassThruPathNormalizer,
StripProtocolPathNormalizer::class => fn() => new StripProtocolPathNormalizer(
FilesystemRegistry::class => fn () => new FilesystemRegistry(),
PassThruPathNormalizer::class => fn () => new PassThruPathNormalizer(),
StripProtocolPathNormalizer::class => fn () => new StripProtocolPathNormalizer(
null,
$this->get(WhitespacePathNormalizer::class),
),
PathNormalizer::class => fn() => $this->get(StripProtocolPathNormalizer::class),
WhitespacePathNormalizer::class => fn() => new WhitespacePathNormalizer,
PortableVisibilityConverter::class => fn() => new PortableVisibilityConverter,
VisibilityConverter::class => fn() => $this->get(PortableVisibilityConverter::class),
LockRegistryInterface::class => fn() => $this->get(LocalLockRegistry::class),
LocalLockRegistry::class => fn() => new LocalLockRegistry,
NullLogger::class => fn() => new NullLogger,
LoggerInterface::class => fn() => $this->get(NullLogger::class),
BufferInterface::class => fn() => $this->get(MemoryBuffer::class),
MemoryBuffer::class => fn() => new MemoryBuffer,
OverflowBuffer::class => fn() => new OverflowBuffer,
FileBuffer::class => fn() => new FileBuffer,
PathNormalizer::class => fn () => $this->get(StripProtocolPathNormalizer::class),
WhitespacePathNormalizer::class => fn () => new WhitespacePathNormalizer(),
PortableVisibilityConverter::class => fn () => new PortableVisibilityConverter(),
VisibilityConverter::class => fn () => $this->get(PortableVisibilityConverter::class),
LockRegistryInterface::class => fn () => $this->get(LocalLockRegistry::class),
LocalLockRegistry::class => fn () => new LocalLockRegistry(),
NullLogger::class => fn () => new NullLogger(),
LoggerInterface::class => fn () => $this->get(NullLogger::class),
BufferInterface::class => fn () => $this->get(MemoryBuffer::class),
MemoryBuffer::class => fn () => new MemoryBuffer(),
OverflowBuffer::class => fn () => new OverflowBuffer(),
FileBuffer::class => fn () => new FileBuffer(),
];

$this->instances = [];
Expand Down
8 changes: 1 addition & 7 deletions src/FlystreamException.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ public static function protocolNotRegistered(string $protocol): self

public static function containerEntryNotFound(string $id): self
{
return new class(
sprintf(
'Specified container entry not found: %s',
$id
),
self::CODE_CONTAINER_ENTRY_NOT_FOUND
) extends FlystreamException implements NotFoundExceptionInterface { };
return new class (sprintf('Specified container entry not found: %s', $id), self::CODE_CONTAINER_ENTRY_NOT_FOUND) extends FlystreamException implements NotFoundExceptionInterface { };
}
}
4 changes: 2 additions & 2 deletions src/ServiceLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class ServiceLocator

public function __construct()
{
$this->container = new Container;
$this->container = new Container();
}

public static function getInstance(): self
{
if (self::$instance === null) {
self::$instance = new self;
self::$instance = new self();
}
return self::$instance;
}
Expand Down
10 changes: 5 additions & 5 deletions tests/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Elazar\Flystream\MemoryBuffer;

it('can iterate, detect, and get default entries', function () {
$container = new Container;
$container = new Container();
$expectedDependencyCount = 15;
$actualDependencyCount = 0;
foreach ($container as $class => $instance) {
Expand All @@ -19,11 +19,11 @@
});

it('throws an exception for an unknown key', function () {
(new Container)->get('unknown-key');
(new Container())->get('unknown-key');
})->throws(FlystreamException::class);

it('can override a dependency using a class name', function () {
$container = new Container;
$container = new Container();

$default = $container->get(BufferInterface::class);
expect($default)->toBeInstanceOf(MemoryBuffer::class);
Expand All @@ -35,9 +35,9 @@
});

it('can override a dependency using an instance', function () {
$container = new Container;
$container = new Container();

$buffer = new FileBuffer;
$buffer = new FileBuffer();
$container->set(BufferInterface::class, $buffer);

$override = $container->get(BufferInterface::class);
Expand Down
8 changes: 5 additions & 3 deletions tests/LocalLockRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@
it('releases locks when going out of scope', function () {
$testLock = new Lock('foo', Lock::TYPE_EXCLUSIVE);
$released = false;
$registry = new class($testLock, $released) extends LocalLockRegistry {
$registry = new class ($testLock, $released) extends LocalLockRegistry {
private Lock $testLock;
private bool $released;
public function __construct(Lock $testLock, bool &$released) {
public function __construct(Lock $testLock, bool &$released)
{
$this->testLock = $testLock;
$this->released = &$released;
}
public function release(Lock $lock): bool {
public function release(Lock $lock): bool
{
$this->released = true;
expect($lock)->toBe($this->testLock);
return parent::release($lock);
Expand Down
4 changes: 2 additions & 2 deletions tests/StreamWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
ServiceLocator::setInstance($serviceLocator);

$this->logger = new Logger(__FILE__);
$this->logger->pushHandler(new TestHandler);
$this->logger->pushHandler(new TestHandler());
ServiceLocator::set(LoggerInterface::class, $this->logger);

$this->registry = ServiceLocator::get(FilesystemRegistry::class);

$this->filesystem = new Filesystem(
new TestInMemoryFilesystemAdapter,
new TestInMemoryFilesystemAdapter(),
[],
ServiceLocator::get(PathNormalizer::class),
);
Expand Down

0 comments on commit 455d3c2

Please sign in to comment.