From 7d07e246cceabb806851c5ebe091d165f2b46e9b Mon Sep 17 00:00:00 2001 From: Larry Garfield Date: Wed, 14 Aug 2024 09:58:18 -0500 Subject: [PATCH 1/5] Run CI on PRs. --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1268f99..4ffe309 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,8 @@ name: CI -on: [push] +on: + push: ~ + pull_request: ~ jobs: build-test: From d173a1c72d6924d20ced33ee5ae6ee66f9b24ca6 Mon Sep 17 00:00:00 2001 From: Larry Garfield Date: Wed, 14 Aug 2024 09:58:45 -0500 Subject: [PATCH 2/5] Run tests on all supported PHP versions. --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4ffe309..89abb6d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,8 +6,11 @@ on: 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 From 415f6c7c763f77da9c58e6005f0e1e3cfc53d954 Mon Sep 17 00:00:00 2001 From: Larry Garfield Date: Wed, 14 Aug 2024 10:02:40 -0500 Subject: [PATCH 3/5] Run PHP-CS-Fixer in CI as well. --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 89abb6d..08fb7e4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,4 +18,5 @@ jobs: run: | sudo chmod -R 777 vendor/pestphp/pest/.temp vendor/bin/pest - + - name: Run CS-Fixer + run: vendor/bin/php-cs-fixer check From bd86313a361dc14e3fbb6782ede3ba36ef264d68 Mon Sep 17 00:00:00 2001 From: Larry Garfield Date: Wed, 14 Aug 2024 10:03:30 -0500 Subject: [PATCH 4/5] Run CS-Fixer. --- src/Container.php | 30 +++++++++++++++--------------- src/FlystreamException.php | 8 +------- src/ServiceLocator.php | 4 ++-- tests/ContainerTest.php | 10 +++++----- tests/LocalLockRegistryTest.php | 8 +++++--- tests/StreamWrapperTest.php | 4 ++-- 6 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/Container.php b/src/Container.php index 0d29833..e2afd88 100644 --- a/src/Container.php +++ b/src/Container.php @@ -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 = []; diff --git a/src/FlystreamException.php b/src/FlystreamException.php index e43b2ab..7b0b4ec 100644 --- a/src/FlystreamException.php +++ b/src/FlystreamException.php @@ -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 { }; } } diff --git a/src/ServiceLocator.php b/src/ServiceLocator.php index 0d7e7da..6cd1e15 100644 --- a/src/ServiceLocator.php +++ b/src/ServiceLocator.php @@ -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; } diff --git a/tests/ContainerTest.php b/tests/ContainerTest.php index c75968c..19e3c82 100644 --- a/tests/ContainerTest.php +++ b/tests/ContainerTest.php @@ -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) { @@ -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); @@ -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); diff --git a/tests/LocalLockRegistryTest.php b/tests/LocalLockRegistryTest.php index 4d140b0..0b53e92 100644 --- a/tests/LocalLockRegistryTest.php +++ b/tests/LocalLockRegistryTest.php @@ -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); diff --git a/tests/StreamWrapperTest.php b/tests/StreamWrapperTest.php index dd3ac7c..4969734 100644 --- a/tests/StreamWrapperTest.php +++ b/tests/StreamWrapperTest.php @@ -15,12 +15,12 @@ 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 InMemoryFilesystemAdapter); + $this->filesystem = new Filesystem(new InMemoryFilesystemAdapter()); $this->registry->register('fly', $this->filesystem); }); From c574983076ecae61184ebd217fe4dba043d475aa Mon Sep 17 00:00:00 2001 From: Larry Garfield Date: Wed, 14 Aug 2024 10:06:21 -0500 Subject: [PATCH 5/5] Split up CS-Fixer and PHPUnit so CS-Fixer doesn't run on every PHP version. --- .github/workflows/ci.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 08fb7e4..3ab6c2a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,5 +18,12 @@ jobs: run: | sudo chmod -R 777 vendor/pestphp/pest/.temp vendor/bin/pest - - name: Run CS-Fixer - run: vendor/bin/php-cs-fixer check + + 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