From b6e1bde5b5682e3482d677a84150aade96bf12b5 Mon Sep 17 00:00:00 2001 From: Adam Nicholson Date: Fri, 20 Jan 2023 12:47:01 +0000 Subject: [PATCH 1/8] Add PHP8 Support --- .travis.yml | 2 ++ composer.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f4c0128..0ef2563 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,7 @@ language: php php: + - 8.1 + - 8.0 - 7.0 - 5.6 - hhvm diff --git a/composer.json b/composer.json index 87a3b90..c243baa 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ ], "require": { "php": ">=5.4.0", - "psr/cache": "^1.0" + "psr/cache": "^1.0 || ^2.0 || 3.0" }, "require-dev": { "psr/log": "*@dev", From fe7a8403215c666d69b299e39959c39ede75a368 Mon Sep 17 00:00:00 2001 From: Adam Nicholson Date: Mon, 23 Jan 2023 12:46:34 +0000 Subject: [PATCH 2/8] Upgrade PHPUnit version --- .travis.yml | 3 -- composer.json | 6 ++- tests/Bridge/Laravel/IlluminateContainer.php | 2 +- .../Laravel/IlluminateEventDispatcher.php | 2 +- tests/Bridge/League/LeagueContainer.php | 2 +- tests/Busses/SynchronousCommandBusTest.php | 8 +-- tests/ChiefTest.php | 20 +++---- tests/ChiefTestCase.php | 7 ++- tests/Decorators/CachingDecoratorTest.php | 54 ++++++++++++++----- .../CommandQueueingDecoratorTest.php | 10 ++-- tests/Decorators/DecoratorTest.php | 2 +- .../EventDispatchingDecoratorTest.php | 8 +-- tests/Decorators/LoggingDecoratorTest.php | 14 ++--- ...ansactionalCommandLockingDecoratorTest.php | 2 +- .../NativeCommandHandlerResolverTest.php | 4 +- 15 files changed, 86 insertions(+), 58 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0ef2563..87b1ec6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,6 @@ language: php php: - 8.1 - 8.0 - - 7.0 - - 5.6 - - hhvm install: composer install --no-interaction --prefer-source script: diff --git a/composer.json b/composer.json index c243baa..b2f71ff 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ } ], "require": { - "php": ">=5.4.0", + "php": ">=8.0", "psr/cache": "^1.0 || ^2.0 || 3.0" }, "require-dev": { @@ -17,7 +17,9 @@ "illuminate/container": "*@dev", "illuminate/events": "*@dev", "league/container": "~1.3", - "phpunit/phpunit": "^5.2" + "phpunit/phpunit": "^9.5", + "phpspec/prophecy": "^1.16", + "phpspec/prophecy-phpunit": "^2.0" }, "autoload": { "psr-4": { diff --git a/tests/Bridge/Laravel/IlluminateContainer.php b/tests/Bridge/Laravel/IlluminateContainer.php index ed0cd27..8280c6f 100644 --- a/tests/Bridge/Laravel/IlluminateContainer.php +++ b/tests/Bridge/Laravel/IlluminateContainer.php @@ -9,7 +9,7 @@ class IlluminateContainerTest extends ChiefTestCase { public function testMakeHitsInnerContainer() { - $container = new IlluminateContainer($inner = $this->getMock('Illuminate\Container\Container')); + $container = new IlluminateContainer($inner = $this->createMock('Illuminate\Container\Container')); $container->expects($this->once())->method('make')->with('stdClass')->willReturn(new \stdClass()); $made = $container->make('stdClass'); $this->assertTrue($made instanceof \stdClass); diff --git a/tests/Bridge/Laravel/IlluminateEventDispatcher.php b/tests/Bridge/Laravel/IlluminateEventDispatcher.php index c8cb377..992c636 100644 --- a/tests/Bridge/Laravel/IlluminateEventDispatcher.php +++ b/tests/Bridge/Laravel/IlluminateEventDispatcher.php @@ -9,7 +9,7 @@ class IlluminateEventDispatcherTest extends ChiefTestCase { public function testDispatchHitsDispatcher() { - $instance = new IlluminateEventDispatcher($dispatcher = $this->getMock('Illuminate\Events\Dispatcher')); + $instance = new IlluminateEventDispatcher($dispatcher = $this->createMock('Illuminate\Events\Dispatcher')); $eventName = 'Foo.Event'; $eventdata = new TestCommand(); $dispatcher->expects($this->once())->method('fire')->with($eventName, $eventdata); diff --git a/tests/Bridge/League/LeagueContainer.php b/tests/Bridge/League/LeagueContainer.php index 6de7087..9058e09 100644 --- a/tests/Bridge/League/LeagueContainer.php +++ b/tests/Bridge/League/LeagueContainer.php @@ -8,7 +8,7 @@ class LeagueContainerTest extends ChiefTestCase { public function testMakeHitsInnerContainer() { - $container = new LeagueContainer($inner = $this->getMock('League\Container\Container')); + $container = new LeagueContainer($inner = $this->createMock('League\Container\Container')); $container->expects($this->once())->method('get')->with('stdClass')->willReturn(new \stdClass()); $made = $container->make('stdClass'); $this->assertTrue($made instanceof \stdClass); diff --git a/tests/Busses/SynchronousCommandBusTest.php b/tests/Busses/SynchronousCommandBusTest.php index 37ea0be..8216562 100644 --- a/tests/Busses/SynchronousCommandBusTest.php +++ b/tests/Busses/SynchronousCommandBusTest.php @@ -15,8 +15,8 @@ public function testInstance() public function testExecuteFiresHandlerProvidedByResolver() { - $resolver = $this->getMock('Chief\CommandHandlerResolver'); - $handler = $this->getMock('Chief\CommandHandler'); + $resolver = $this->createMock('Chief\CommandHandlerResolver'); + $handler = $this->createMock('Chief\CommandHandler'); $bus = new SynchronousCommandBus($resolver); $command = new TestCommand; $handler->expects($this->once())->method('handle')->with($command); @@ -26,8 +26,8 @@ public function testExecuteFiresHandlerProvidedByResolver() public function testExecuteReturnsHandlerResponse() { - $resolver = $this->getMock('Chief\CommandHandlerResolver'); - $handler = $this->getMock('Chief\CommandHandler'); + $resolver = $this->createMock('Chief\CommandHandlerResolver'); + $handler = $this->createMock('Chief\CommandHandler'); $bus = new SynchronousCommandBus($resolver); $command = new TestCommand; $handler->expects($this->once())->method('handle')->with($command)->willReturn('Foo-Bar.'); diff --git a/tests/ChiefTest.php b/tests/ChiefTest.php index 993c614..9cbcdda 100644 --- a/tests/ChiefTest.php +++ b/tests/ChiefTest.php @@ -29,7 +29,7 @@ public function testExecuteFiresByAutoResolution() public function testExecuteFiresHandlerAttachedByInstance() { $resolver = new NativeCommandHandlerResolver; - $resolver->bindHandler('Chief\Stubs\TestCommand', $handler = $this->getMock('Chief\CommandHandler')); + $resolver->bindHandler('Chief\Stubs\TestCommand', $handler = $this->createMock('Chief\CommandHandler')); $syncBus = new SynchronousCommandBus($resolver); $bus = new Chief($syncBus); $command = new TestCommand; @@ -63,14 +63,14 @@ public function testExecuteThrowsExceptionWhenNoHandler() { $bus = new Chief(); $command = new TestCommandWithoutHandler; - $this->setExpectedException('Exception'); + $this->expectException('Exception'); $bus->execute($command); } public function testCommandCanHandleItselfIfImplementsCommandHandler() { $bus = new Chief(); - $command = $this->getMock('Chief\Stubs\SelfHandlingCommand'); + $command = $this->createMock('Chief\Stubs\SelfHandlingCommand'); $command->expects($this->once())->method('handle')->with($command); $bus->execute($command); } @@ -78,8 +78,8 @@ public function testCommandCanHandleItselfIfImplementsCommandHandler() public function testDecoratorCommandBus() { $bus = new LogDecoratorCommandBus( - $logger = $this->getMock('Psr\Log\LoggerInterface'), - $innerBus = $this->getMock('Chief\Busses\SynchronousCommandBus') + $logger = $this->createMock('Psr\Log\LoggerInterface'), + $innerBus = $this->createMock('Chief\Busses\SynchronousCommandBus') ); $chief = new Chief($bus); $command = new TestCommand; @@ -91,7 +91,7 @@ public function testDecoratorCommandBus() public function testInstanceWithDecorators() { $chief = new Chief(new SynchronousCommandBus, [ - $decorator = $this->getMock('Chief\Decorator') + $decorator = $this->createMock('Chief\Decorator') ]); $command = new TestCommand; $decorator->expects($this->once())->method('execute')->with($command); @@ -100,11 +100,11 @@ public function testInstanceWithDecorators() public function testInstanceWithMultipleDecoratorsHitsNestedDecorators() { - $logger = $this->getMock('Psr\Log\LoggerInterface'); + $logger = $this->createMock('Psr\Log\LoggerInterface'); $chief = new Chief(new SynchronousCommandBus, [ $decoratorOne = new LoggingDecorator($logger), - $decoratorTwo = $this->getMock('Chief\Decorator'), + $decoratorTwo = $this->createMock('Chief\Decorator'), ]); $command = new TestCommand; $decoratorTwo->expects($this->once())->method('execute')->with($command); @@ -113,7 +113,7 @@ public function testInstanceWithMultipleDecoratorsHitsNestedDecorators() public function testInstanceWithMultipleDecoratorsHitsHandler() { - $logger = $this->getMock('Psr\Log\LoggerInterface'); + $logger = $this->createMock('Psr\Log\LoggerInterface'); $chief = new Chief(new SynchronousCommandBus, [ $decoratorOne = new LoggingDecorator($logger), @@ -125,7 +125,7 @@ public function testInstanceWithMultipleDecoratorsHitsHandler() } public function testInnerBusResponseIsReturnedByChief() { - $chief = new Chief($bus = $this->getMock('Chief\CommandBus')); + $chief = new Chief($bus = $this->createMock('Chief\CommandBus')); $bus->expects($this->once())->method('execute')->willReturn('foo-bar'); $response = $chief->execute(new TestCommand); $this->assertEquals($response, 'foo-bar'); diff --git a/tests/ChiefTestCase.php b/tests/ChiefTestCase.php index cae1245..ab45793 100644 --- a/tests/ChiefTestCase.php +++ b/tests/ChiefTestCase.php @@ -2,7 +2,10 @@ namespace Chief; -abstract class ChiefTestCase extends \PHPUnit_Framework_TestCase -{ +use PHPUnit\Framework\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; +abstract class ChiefTestCase extends TestCase +{ + use ProphecyTrait; } \ No newline at end of file diff --git a/tests/Decorators/CachingDecoratorTest.php b/tests/Decorators/CachingDecoratorTest.php index 9432a33..d9bfff1 100644 --- a/tests/Decorators/CachingDecoratorTest.php +++ b/tests/Decorators/CachingDecoratorTest.php @@ -49,12 +49,13 @@ public function test_execution_return_value_is_cached_when_command_implements_ca $inner = $this->prophesize(CommandBus::class); $decorator->setInnerBus($inner->reveal()); - $command = $this->prophesize(CacheableCommand::class)->reveal(); + $command = new FakeCachableCommand('fizzbuzz'); $notCachedItem = $this->prophesize(CacheItemInterface::class); $notCachedItem->isHit()->willReturn(false); - $notCachedItem->getKey()->willReturn(md5(serialize(($command)))); - $this->cache->getItem(Argument::any())->willReturn($notCachedItem->reveal()); + $cacheKey = md5(serialize(($command))); + $notCachedItem->getKey()->willReturn($cacheKey); + $this->cache->getItem($cacheKey)->willReturn($notCachedItem->reveal()); $notCachedItem->set(7)->shouldBeCalled()->willReturn($notCachedItem->reveal()); $notCachedItem->expiresAfter(3600)->shouldBeCalled()->willReturn($notCachedItem->reveal()); @@ -75,11 +76,7 @@ public function test_cache_expiry_can_be_overridden() $inner = $this->prophesize(CommandBus::class); $decorator->setInnerBus($inner->reveal()); - $commandProphecy = $this->prophesize(HasCacheOptions::class); - $commandProphecy->getCacheExpiry()->willReturn(60*60*24*365); - $commandProphecy->getCacheKey()->willReturn(null); - - $command = $commandProphecy->reveal(); + $command = new FakeCachableCommandWithCacheOptions('fizzbuzz', 60*60*24*365, null); $notCachedItem = $this->prophesize(CacheItemInterface::class); $notCachedItem->isHit()->willReturn(false); @@ -105,11 +102,7 @@ public function test_cache_key_can_be_overridden() $inner = $this->prophesize(CommandBus::class); $decorator->setInnerBus($inner->reveal()); - $commandProphecy = $this->prophesize(HasCacheOptions::class); - $commandProphecy->getCacheExpiry()->willReturn(null); - $commandProphecy->getCacheKey()->willReturn('custom-cache-key'); - - $command = $commandProphecy->reveal(); + $command = new FakeCachableCommandWithCacheOptions('fizzbuzz', null, 'custom-cache-key'); $notCachedItem = $this->prophesize(CacheItemInterface::class); $notCachedItem->isHit()->willReturn(false); @@ -135,7 +128,7 @@ public function test_cache_item_value_is_returned_if_cached() $inner = $this->prophesize(CommandBus::class); $decorator->setInnerBus($inner->reveal()); - $command = $this->prophesize(CacheableCommand::class)->reveal(); + $command = new FakeCachableCommand('fizzbuzz'); $cachedItem = $this->prophesize(CacheItemInterface::class); $cachedItem->isHit()->willReturn(true); @@ -157,3 +150,36 @@ protected function getDecorator() return new CachingDecorator($this->cache->reveal()); } } + +class FakeCachableCommand implements CacheableCommand +{ + public $data; + + public function __construct($data) + { + $this->data = $data; + } +} + +class FakeCachableCommandWithCacheOptions extends FakeCachableCommand implements HasCacheOptions +{ + private $expiry; + private $cacheKey; + + public function __construct($data, $expiry, $cacheKey) + { + $this->data = $data; + $this->expiry = $expiry; + $this->cacheKey = $cacheKey; + } + + public function getCacheExpiry() + { + return $this->expiry; + } + + public function getCacheKey() + { + return $this->cacheKey; + } +} diff --git a/tests/Decorators/CommandQueueingDecoratorTest.php b/tests/Decorators/CommandQueueingDecoratorTest.php index 749e7be..4c9eec9 100644 --- a/tests/Decorators/CommandQueueingDecoratorTest.php +++ b/tests/Decorators/CommandQueueingDecoratorTest.php @@ -11,13 +11,13 @@ class CommandQueueingDecoratorTest extends DecoratorTest { public function testInstance() { - $this->assertTrue(new CommandQueueingDecorator($this->getMock('Chief\CommandQueuer')) instanceof CommandBus); + $this->assertTrue(new CommandQueueingDecorator($this->createMock('Chief\CommandQueuer')) instanceof CommandBus); } public function testExecutePutsNormalCommandInInnerBus() { - $queuer = $this->getMock('Chief\CommandQueuer'); - $innerBus = $this->getMock('Chief\CommandBus'); + $queuer = $this->createMock('Chief\CommandQueuer'); + $innerBus = $this->createMock('Chief\CommandBus'); $bus = new CommandQueueingDecorator($queuer, $innerBus); $command = new TestCommand; $queuer->expects($this->never())->method('queue'); @@ -27,7 +27,7 @@ public function testExecutePutsNormalCommandInInnerBus() public function testExecutePutsQueueableCommandInQueuer() { - $queuer = $this->getMock('Chief\CommandQueuer'); + $queuer = $this->createMock('Chief\CommandQueuer'); $bus = new CommandQueueingDecorator($queuer); $command = new TestQueueableCommand; $queuer->expects($this->once())->method('queue')->with($command); @@ -39,7 +39,7 @@ public function testExecutePutsQueueableCommandInQueuer() */ protected function getDecorator() { - return new CommandQueueingDecorator($this->getMock('Chief\CommandQueuer')); + return new CommandQueueingDecorator($this->createMock('Chief\CommandQueuer')); } diff --git a/tests/Decorators/DecoratorTest.php b/tests/Decorators/DecoratorTest.php index bdce1d1..b365530 100644 --- a/tests/Decorators/DecoratorTest.php +++ b/tests/Decorators/DecoratorTest.php @@ -10,7 +10,7 @@ abstract class DecoratorTest extends ChiefTestCase public function testExecuteFiresInnerBusAndReturnsResponse() { $decorator = $this->getDecorator(); - $decorator->setInnerBus($bus = $this->getMock('Chief\CommandBus')); + $decorator->setInnerBus($bus = $this->createMock('Chief\CommandBus')); $command = new TestCommand(); $bus->expects($this->once())->method('execute')->with($command)->willReturn('Some response'); $response = $decorator->execute($command); diff --git a/tests/Decorators/EventDispatchingDecoratorTest.php b/tests/Decorators/EventDispatchingDecoratorTest.php index 607b7c7..68ce669 100644 --- a/tests/Decorators/EventDispatchingDecoratorTest.php +++ b/tests/Decorators/EventDispatchingDecoratorTest.php @@ -10,16 +10,16 @@ class EventDispatchingDecoratorTest extends DecoratorTest public function testInstance() { $decorator = $this->getDecorator(); - $decorator->setInnerBus($this->getMock('Chief\CommandBus')); + $decorator->setInnerBus($this->createMock('Chief\CommandBus')); $this->assertTrue($decorator instanceof CommandBus); } public function testExecuteFiresEventAndInnerBus() { $decorator = new EventDispatchingDecorator( - $dispatcher = $this->getMock('Chief\Decorators\EventDispatcher') + $dispatcher = $this->createMock('Chief\Decorators\EventDispatcher') ); - $decorator->setInnerBus($bus = $this->getMock('Chief\CommandBus')); + $decorator->setInnerBus($bus = $this->createMock('Chief\CommandBus')); $command = new TestCommand(); $bus->expects($this->once())->method('execute')->with($command); $dispatcher->expects($this->once())->method('dispatch')->with('Chief.Stubs.TestCommand', [$command]); @@ -28,6 +28,6 @@ public function testExecuteFiresEventAndInnerBus() protected function getDecorator() { - return new EventDispatchingDecorator($this->getMock('Chief\Decorators\EventDispatcher')); + return new EventDispatchingDecorator($this->createMock('Chief\Decorators\EventDispatcher')); } } \ No newline at end of file diff --git a/tests/Decorators/LoggingDecoratorTest.php b/tests/Decorators/LoggingDecoratorTest.php index 2fc9354..29f431f 100644 --- a/tests/Decorators/LoggingDecoratorTest.php +++ b/tests/Decorators/LoggingDecoratorTest.php @@ -10,16 +10,16 @@ class LoggingDecoratorTest extends DecoratorTest public function testInstance() { $decorator = $this->getDecorator(); - $decorator->setInnerBus($this->getMock('Chief\CommandBus')); + $decorator->setInnerBus($this->createMock('Chief\CommandBus')); $this->assertTrue($decorator instanceof CommandBus); } public function testExecuteLogsMessageAndFiresInnerBus() { $decorator = new LoggingDecorator( - $logger = $this->getMock('Psr\Log\LoggerInterface') + $logger = $this->createMock('Psr\Log\LoggerInterface') ); - $decorator->setInnerBus($bus = $this->getMock('Chief\CommandBus')); + $decorator->setInnerBus($bus = $this->createMock('Chief\CommandBus')); $command = new TestCommand(); $bus->expects($this->once())->method('execute')->with($command); $logger->expects($this->exactly(2))->method('debug')->with($this->anything(), ['Command' => serialize($command), 'Context' => null]); @@ -29,14 +29,14 @@ public function testExecuteLogsMessageAndFiresInnerBus() public function testExecuteLogsExecptionIfThrownByInnerBusAndBubbleException() { $decorator = new LoggingDecorator( - $logger = $this->getMock('Psr\Log\LoggerInterface') + $logger = $this->createMock('Psr\Log\LoggerInterface') ); - $decorator->setInnerBus($bus = $this->getMock('Chief\CommandBus')); + $decorator->setInnerBus($bus = $this->createMock('Chief\CommandBus')); $command = new TestCommand(); $bus->expects($this->once())->method('execute')->with($command)->will($this->throwException(new \Exception('Oops'))); $logger->expects($this->exactly(2))->method('debug')->with($this->anything(), ['Command' => serialize($command), 'Context' => null]); - $this->setExpectedException('Exception'); + $this->expectException('Exception'); $decorator->execute($command); } @@ -45,7 +45,7 @@ public function testExecuteLogsExecptionIfThrownByInnerBusAndBubbleException() */ protected function getDecorator() { - return new LoggingDecorator($this->getMock('Psr\Log\LoggerInterface')); + return new LoggingDecorator($this->createMock('Psr\Log\LoggerInterface')); } } diff --git a/tests/Decorators/TransactionalCommandLockingDecoratorTest.php b/tests/Decorators/TransactionalCommandLockingDecoratorTest.php index 6cbf502..e26cc37 100644 --- a/tests/Decorators/TransactionalCommandLockingDecoratorTest.php +++ b/tests/Decorators/TransactionalCommandLockingDecoratorTest.php @@ -75,7 +75,7 @@ public function testNestedCommandsNotExecutedWhenInitialCommandFailsBeforeReturn throw new \Exception('Something failed'); }); - $this->setExpectedException('Exception'); + $this->expectException('Exception'); $bus->execute($command); $this->assertEquals($countTestCommandCalled, 0); diff --git a/tests/Resolvers/NativeCommandHandlerResolverTest.php b/tests/Resolvers/NativeCommandHandlerResolverTest.php index bd1acc8..8d81f94 100644 --- a/tests/Resolvers/NativeCommandHandlerResolverTest.php +++ b/tests/Resolvers/NativeCommandHandlerResolverTest.php @@ -22,7 +22,7 @@ public function testInstantiable() public function testResolveThrowsExceptionWhenNoHandlerFound() { $resolver = new NativeCommandHandlerResolver; - $this->setExpectedException('Chief\Exceptions\UnresolvableCommandHandlerException'); + $this->expectException('Chief\Exceptions\UnresolvableCommandHandlerException'); $resolver->resolve(new TestCommandWithoutHandler); } @@ -42,7 +42,7 @@ public function testResolveReturnsHandlerWhenNotBoundAndHandlerNestedInHandlersN public function testResolveReturnsHandlerBoundByObject() { - $handler = $this->getMock('Chief\CommandHandler'); + $handler = $this->createMock('Chief\CommandHandler'); $resolver = new NativeCommandHandlerResolver; $resolver->bindHandler('Chief\Stubs\TestCommandWithoutHandler', $handler); $this->assertEquals($resolver->resolve(new TestCommandWithoutHandler), $handler); From 62702a1e183d050a5ea2e93451541ef6b075fde2 Mon Sep 17 00:00:00 2001 From: Adam Nicholson Date: Mon, 23 Jan 2023 15:50:09 +0000 Subject: [PATCH 3/8] Add placeholder github actions workflow --- .github/workflows/tests.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..e007988 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,18 @@ +name: GitHub Actions Demo +run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 +on: [push] +jobs: + Explore-GitHub-Actions: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v3 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." From e0316e68e3e0396f29d2a27322d41e918bc44c1b Mon Sep 17 00:00:00 2001 From: Adam Nicholson Date: Mon, 23 Jan 2023 15:54:33 +0000 Subject: [PATCH 4/8] Implement tests --- .github/workflows/tests.yml | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e007988..810dfd2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,18 +1,11 @@ -name: GitHub Actions Demo -run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 +name: PHPUnit Tests on: [push] jobs: Explore-GitHub-Actions: runs-on: ubuntu-latest + with: + php-version: '8.0' + tools: 'composer' steps: - - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." - - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" - - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." - - name: Check out repository code - uses: actions/checkout@v3 - - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." - - run: echo "🖥️ The workflow is now ready to test your code on the runner." - - name: List files in the repository - run: | - ls ${{ github.workspace }} - - run: echo "🍏 This job's status is ${{ job.status }}." + - run: composer install + - run: vendor/bin/phpunit \ No newline at end of file From 7a7565946f4826fd7421928a68aa05d67b3c407b Mon Sep 17 00:00:00 2001 From: Adam Nicholson Date: Mon, 23 Jan 2023 16:00:06 +0000 Subject: [PATCH 5/8] Fix yml --- .github/workflows/tests.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 810dfd2..3463cf3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,11 +1,13 @@ name: PHPUnit Tests on: [push] jobs: - Explore-GitHub-Actions: + Run-Tests: runs-on: ubuntu-latest - with: - php-version: '8.0' - tools: 'composer' steps: - - run: composer install - - run: vendor/bin/phpunit \ No newline at end of file + - name: Install dependencies + with: + php-version: '8.0' + tools: 'composer' + run: composer install + - name: Run tests + run: vendor/bin/phpunit \ No newline at end of file From 0a293ae6ccc2cd6354db0f502c41aaee422a5bc3 Mon Sep 17 00:00:00 2001 From: Adam Nicholson Date: Mon, 23 Jan 2023 16:03:29 +0000 Subject: [PATCH 6/8] Fix yml --- .github/workflows/tests.yml | 44 +++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3463cf3..9d54175 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,13 +1,39 @@ name: PHPUnit Tests -on: [push] +on: [push, pull_request] jobs: - Run-Tests: - runs-on: ubuntu-latest + build: + strategy: + matrix: + operating-system: [ubuntu-latest, windows-latest, macos-latest] + php-versions: ['7.4', '8.0', '8.1'] + runs-on: ${{ matrix.operating-system }} steps: - - name: Install dependencies + - name: Checkout + uses: actions/checkout@v3 + + # Docs: https://github.com/shivammathur/setup-php + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, simplexml, dom + coverage: xdebug + + - name: Get composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache composer dependencies + uses: actions/cache@v3 with: - php-version: '8.0' - tools: 'composer' - run: composer install - - name: Run tests - run: vendor/bin/phpunit \ No newline at end of file + path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + run: composer install --no-progress --prefer-dist --optimize-autoloader + + - name: Test with phpunit + run: vendor/bin/phpunit --coverage-text From 20d3abe5d84ce8b5d70d514299b1ddc93dccd409 Mon Sep 17 00:00:00 2001 From: Adam Nicholson Date: Mon, 23 Jan 2023 16:05:05 +0000 Subject: [PATCH 7/8] Remove PHP 7.4 support --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9d54175..a112fa1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,7 +5,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest, windows-latest, macos-latest] - php-versions: ['7.4', '8.0', '8.1'] + php-versions: ['8.0', '8.1'] runs-on: ${{ matrix.operating-system }} steps: - name: Checkout From 9d2cebcd199d8e99879022195c3731f41d2f5c6d Mon Sep 17 00:00:00 2001 From: Adam Nicholson Date: Mon, 23 Jan 2023 16:07:31 +0000 Subject: [PATCH 8/8] Do not run tests against Windows --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a112fa1..22cdc87 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,7 +4,7 @@ jobs: build: strategy: matrix: - operating-system: [ubuntu-latest, windows-latest, macos-latest] + operating-system: [ubuntu-latest, macos-latest] php-versions: ['8.0', '8.1'] runs-on: ${{ matrix.operating-system }} steps: