diff --git a/.github/workflows/code-style.yml b/.github/workflows/code-style.yml index f60726f..cd20188 100644 --- a/.github/workflows/code-style.yml +++ b/.github/workflows/code-style.yml @@ -17,7 +17,7 @@ jobs: - name: Install PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.0 + php-version: 8.1 tools: composer # Specific versions of extensions available on PECL can be set up by suffixing the extension's name with the version. # https://github.com/shivammathur/setup-php?tab=readme-ov-file#heavy_plus_sign-php-extension-support @@ -29,4 +29,4 @@ jobs: run: composer update - name: Run php-cs-fixer - run: ./vendor/bin/php-cs-fixer fix --dry-run --diff . \ No newline at end of file + run: ./vendor/bin/php-cs-fixer fix --dry-run --diff . diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c6328c7..09910e3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -32,7 +32,6 @@ jobs: fail-fast: false matrix: php-version: - - "8.0" - "8.1" - "8.2" - "8.3" @@ -65,7 +64,7 @@ jobs: # https://github.com/php-coveralls/php-coveralls#github-actions - name: Upload coverage results to Coveralls - if: ${{ matrix.php-version == '8.0' }} + if: ${{ matrix.php-version == '8.1' }} env: COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | diff --git a/README.md b/README.md index c1f3f79..2291c73 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Ganesha is PHP implementation of [Circuit Breaker pattern](http://martinfowler.c ![ganesha](https://ackintosh.github.io/assets/images/ganesha.png) -[![Latest Stable Version](https://img.shields.io/packagist/v/ackintosh/ganesha.svg?style=flat-square)](https://packagist.org/packages/ackintosh/ganesha) [![Tests](https://github.com/ackintosh/ganesha/workflows/Tests/badge.svg)](https://github.com/ackintosh/ganesha/actions) [![Coverage Status](https://coveralls.io/repos/github/ackintosh/ganesha/badge.svg?branch=master)](https://coveralls.io/github/ackintosh/ganesha?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/ackintosh/ganesha/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/ackintosh/ganesha/?branch=master) [![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.0-8892BF.svg?style=flat-square)](https://php.net/) +[![Latest Stable Version](https://img.shields.io/packagist/v/ackintosh/ganesha.svg?style=flat-square)](https://packagist.org/packages/ackintosh/ganesha) [![Tests](https://github.com/ackintosh/ganesha/workflows/Tests/badge.svg)](https://github.com/ackintosh/ganesha/actions) [![Coverage Status](https://coveralls.io/repos/github/ackintosh/ganesha/badge.svg?branch=master)](https://coveralls.io/github/ackintosh/ganesha?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/ackintosh/ganesha/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/ackintosh/ganesha/?branch=master) [![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.1-8892BF.svg?style=flat-square)](https://php.net/) diff --git a/composer.json b/composer.json index 31bbb8b..d9bb20e 100644 --- a/composer.json +++ b/composer.json @@ -13,11 +13,11 @@ "repositories": [ { "type": "git", - "url": "https://github.com/kornrunner/phpunit-testlistener-vcr" + "url": "https://github.com/marmichalski/phpunit-testlistener-vcr" } ], "require": { - "php": ">=8.0", + "php": "^8.1", "psr/http-message": "^1.0|^2.0" }, "suggest": { @@ -28,11 +28,11 @@ "ext-mongodb": "Allows the usage of MongoDBAdapter" }, "require-dev": { - "phpunit/phpunit": "^9.5.10", + "phpunit/phpunit": "^10.5.41", "symfony/http-client": "^5.3.12|^6.0", "symfony/yaml": "^3.0|^4.0|^5.0|^6.0", - "php-vcr/php-vcr": "^1.4.5", - "php-vcr/phpunit-testlistener-vcr": "dev-php8 as 3.2.2", + "php-vcr/php-vcr": "dev-master#c0aeeba0f3804fcfdb9cd6b390b0cb3be250c070 as 1.9.0", + "php-vcr/phpunit-testlistener-vcr": "dev-phpunit-evt-system", "php-coveralls/php-coveralls": "~2.5", "predis/predis": "^1.1", "guzzlehttp/guzzle": "^7.4.5", diff --git a/docker-compose.yml b/docker-compose.yml index e9031a2..77207df 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '2' services: server: - image: php:8.0-apache + image: php:8.1-apache container_name: server volumes: - ./examples:/var/www/html diff --git a/examples/client/Dockerfile b/examples/client/Dockerfile index 1d7a263..093628b 100644 --- a/examples/client/Dockerfile +++ b/examples/client/Dockerfile @@ -1,4 +1,4 @@ -FROM php:8.0-cli +FROM php:8.1-cli COPY install_composer.sh /tmp/ diff --git a/phpunit.xml b/phpunit.xml index 75e2f21..a1c3cb5 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,9 +1,11 @@ - - - - ./src - + + @@ -16,7 +18,12 @@ - - - + + + ./src + + + + + diff --git a/tests/Ackintosh/Ganesha/Storage/Adapter/AbstractRedisTest.php b/tests/Ackintosh/Ganesha/Storage/Adapter/AbstractRedisSpec.php similarity index 99% rename from tests/Ackintosh/Ganesha/Storage/Adapter/AbstractRedisTest.php rename to tests/Ackintosh/Ganesha/Storage/Adapter/AbstractRedisSpec.php index 98f56fb..ff12cec 100644 --- a/tests/Ackintosh/Ganesha/Storage/Adapter/AbstractRedisTest.php +++ b/tests/Ackintosh/Ganesha/Storage/Adapter/AbstractRedisSpec.php @@ -8,7 +8,7 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -abstract class AbstractRedisTest extends TestCase +abstract class AbstractRedisSpec extends TestCase { /** * @var int diff --git a/tests/Ackintosh/Ganesha/Storage/Adapter/ApcuStoreTest.php b/tests/Ackintosh/Ganesha/Storage/Adapter/ApcuStoreTest.php index 996fafa..820f1d1 100644 --- a/tests/Ackintosh/Ganesha/Storage/Adapter/ApcuStoreTest.php +++ b/tests/Ackintosh/Ganesha/Storage/Adapter/ApcuStoreTest.php @@ -22,7 +22,7 @@ protected function tearDown(): void */ public function test_dec() { - $key = $this->getName(); + $key = $this->name(); $store = new ApcuStore(); $this->assertSame(-1, $store->dec($key)); @@ -37,7 +37,7 @@ public function test_dec() */ public function test_delete() { - $key = $this->getName(); + $key = $this->name(); $value = __METHOD__; $store = new ApcuStore(); @@ -52,7 +52,7 @@ public function test_delete() */ public function test_exists() { - $key = $this->getName(); + $key = $this->name(); $value = __METHOD__; $store = new ApcuStore(); @@ -67,7 +67,7 @@ public function test_exists() */ public function test_fetch() { - $key = $this->getName(); + $key = $this->name(); $value = __METHOD__; $store = new ApcuStore(); @@ -88,7 +88,7 @@ public function test_fetch() */ public function test_inc() { - $key = $this->getName(); + $key = $this->name(); $store = new ApcuStore(); $this->assertSame(1, $store->inc($key)); @@ -103,7 +103,7 @@ public function test_inc() */ public function test_store() { - $key = $this->getName(); + $key = $this->name(); $value = __METHOD__; $store = new ApcuStore(); @@ -130,7 +130,7 @@ public function provide_getIterator() */ public function test_getIterator(?string $pattern, int $expectCount) { - $name = $this->getName(); + $name = $this->name(); $keys = array_map( function ($index) use ($name) { return sprintf('%s %d', $name, $index); diff --git a/tests/Ackintosh/Ganesha/Storage/Adapter/ApcuTest.php b/tests/Ackintosh/Ganesha/Storage/Adapter/ApcuTest.php index c6bf0c6..5f236e9 100644 --- a/tests/Ackintosh/Ganesha/Storage/Adapter/ApcuTest.php +++ b/tests/Ackintosh/Ganesha/Storage/Adapter/ApcuTest.php @@ -690,7 +690,7 @@ private function getConfiguration(?StorageKeysInterface $storageKeys = null) private function getStorageKeys() { - $storageKeys = $this->getMockForAbstractClass(StorageKeysInterface::class); + $storageKeys = $this->createMock(StorageKeysInterface::class); $storageKeys->method('prefix')->willReturn('ganesha_'); $storageKeys->method('success')->willReturn('_success'); $storageKeys->method('failure')->willReturn('_failure'); @@ -702,16 +702,16 @@ private function getStorageKeys() private function getSuccessKey() { - return sprintf('ganesha_%s_success', $this->getName()); + return sprintf('ganesha_%s_success', $this->name()); } private function getLastFailureTimeKey() { - return sprintf('ganesha_%s_last_failure_time', $this->getName()); + return sprintf('ganesha_%s_last_failure_time', $this->name()); } private function getStatusKey() { - return sprintf('ganesha_%s_status', $this->getName()); + return sprintf('ganesha_%s_status', $this->name()); } } diff --git a/tests/Ackintosh/Ganesha/Storage/Adapter/MemcachedTest.php b/tests/Ackintosh/Ganesha/Storage/Adapter/MemcachedTest.php index 232b9b1..4716409 100644 --- a/tests/Ackintosh/Ganesha/Storage/Adapter/MemcachedTest.php +++ b/tests/Ackintosh/Ganesha/Storage/Adapter/MemcachedTest.php @@ -90,7 +90,7 @@ public function saveAndLoad() public function loadThrowsException() { $m = $this->getMockBuilder(\Memcached::class) - ->setMethods(['getResultCode']) + ->onlyMethods(['getResultCode']) ->getMock(); $m->expects($this->once()) ->method('getResultCode') @@ -109,7 +109,7 @@ public function loadThrowsException() public function saveThrowsException() { $m = $this->getMockBuilder(\Memcached::class) - ->setMethods(['set']) + ->onlyMethods(['set']) ->getMock(); $m->expects($this->once()) ->method('set') @@ -141,7 +141,7 @@ public function increment() public function incrementThrowsException() { $m = $this->getMockBuilder(\Memcached::class) - ->setMethods(['increment']) + ->onlyMethods(['increment']) ->getMock(); $m->expects($this->once()) ->method('increment') @@ -179,7 +179,7 @@ public function decrement() public function decrementThrowsException() { $m = $this->getMockBuilder(\Memcached::class) - ->setMethods(['decrement']) + ->onlyMethods(['decrement']) ->getMock(); $m->expects($this->once()) ->method('decrement') @@ -210,7 +210,7 @@ public function saveAndLoadLastFailureTime() public function saveLastFailureTimeThrowsException() { $m = $this->getMockBuilder(\Memcached::class) - ->setMethods(['set']) + ->onlyMethods(['set']) ->getMock(); $m->expects($this->once()) ->method('set') @@ -229,7 +229,7 @@ public function saveLastFailureTimeThrowsException() public function loadLastFailureTimeThrowsException() { $m = $this->getMockBuilder(\Memcached::class) - ->setMethods(['getResultCode']) + ->onlyMethods(['getResultCode']) ->getMock(); $m->expects($this->once()) ->method('getResultCode') @@ -260,7 +260,7 @@ public function saveAndLoadStatus() public function saveStatusThrowsException() { $m = $this->getMockBuilder(\Memcached::class) - ->setMethods(['set']) + ->onlyMethods(['set']) ->getMock(); $m->expects($this->once()) ->method('set') @@ -279,7 +279,7 @@ public function saveStatusThrowsException() public function loadStatusThrowsException() { $m = $this->getMockBuilder(\Memcached::class) - ->setMethods(['getResultCode']) + ->onlyMethods(['getResultCode']) ->getMock(); $m->expects($this->once()) ->method('getResultCode') @@ -299,7 +299,7 @@ public function loadStatusThrowsException() public function resetWillDoNothingIfNoDataExists() { $m = $this->getMockBuilder(\Memcached::class) - ->setMethods(['getStats', 'getAllKeys', 'getResultCode']) + ->onlyMethods(['getStats', 'getAllKeys', 'getResultCode']) ->getMock(); $m->expects($this->once()) ->method('getStats') @@ -325,7 +325,7 @@ public function resetWillDoNothingIfNoDataExists() public function resetThrowsExceptionWhenFailedToGetStats() { $m = $this->getMockBuilder(\Memcached::class) - ->setMethods(['getStats']) + ->onlyMethods(['getStats']) ->getMock(); $m->expects($this->once()) ->method('getStats') @@ -346,7 +346,7 @@ public function resetThrowsExceptionWhenFailedToGetStats() public function resetThrowsExceptionWhenFailedToGetAllKeys() { $m = $this->getMockBuilder(\Memcached::class) - ->setMethods(['getStats', 'getAllKeys', 'getResultCode']) + ->onlyMethods(['getStats', 'getAllKeys', 'getResultCode']) ->getMock(); $m->expects($this->once()) ->method('getStats') diff --git a/tests/Ackintosh/Ganesha/Storage/Adapter/PredisRedisTest.php b/tests/Ackintosh/Ganesha/Storage/Adapter/PredisRedisTest.php index 04d4d3a..d2040fa 100644 --- a/tests/Ackintosh/Ganesha/Storage/Adapter/PredisRedisTest.php +++ b/tests/Ackintosh/Ganesha/Storage/Adapter/PredisRedisTest.php @@ -5,7 +5,7 @@ use Predis\Client; use Predis\ClientInterface; -class PredisRedisTest extends AbstractRedisTest +class PredisRedisTest extends AbstractRedisSpec { protected function getRedisConnection(): ClientInterface { diff --git a/tests/Ackintosh/Ganesha/Storage/Adapter/RedisArrayTest.php b/tests/Ackintosh/Ganesha/Storage/Adapter/RedisArrayTest.php index cbbb66a..d06782a 100644 --- a/tests/Ackintosh/Ganesha/Storage/Adapter/RedisArrayTest.php +++ b/tests/Ackintosh/Ganesha/Storage/Adapter/RedisArrayTest.php @@ -4,7 +4,7 @@ use RedisArray; -class RedisArrayTest extends AbstractRedisTest +class RedisArrayTest extends AbstractRedisSpec { /** * @return RedisArray diff --git a/tests/Ackintosh/Ganesha/Storage/Adapter/RedisRedisTest.php b/tests/Ackintosh/Ganesha/Storage/Adapter/RedisRedisTest.php index a5a7a5c..c47bd67 100644 --- a/tests/Ackintosh/Ganesha/Storage/Adapter/RedisRedisTest.php +++ b/tests/Ackintosh/Ganesha/Storage/Adapter/RedisRedisTest.php @@ -2,7 +2,7 @@ namespace Ackintosh\Ganesha\Storage\Adapter; -class RedisRedisTest extends AbstractRedisTest +class RedisRedisTest extends AbstractRedisSpec { /** * @return \Redis diff --git a/tests/Ackintosh/Ganesha/Storage/Adapter/RedisStoreTest.php b/tests/Ackintosh/Ganesha/Storage/Adapter/RedisStoreTest.php index b08859f..c9ec301 100644 --- a/tests/Ackintosh/Ganesha/Storage/Adapter/RedisStoreTest.php +++ b/tests/Ackintosh/Ganesha/Storage/Adapter/RedisStoreTest.php @@ -24,7 +24,7 @@ public function zCardThrowsExceptionIfFailed() $this->expectException(\Ackintosh\Ganesha\Exception\StorageException::class); $mock = $this->getMockBuilder(\Redis::class) - ->setMethods(['zCard']) + ->onlyMethods(['zCard']) ->getMock(); $mock->expects($this->any()) ->method('zCard') diff --git a/tests/Ackintosh/GaneshaTest.php b/tests/Ackintosh/GaneshaTest.php index 6ae5662..8e02f19 100644 --- a/tests/Ackintosh/GaneshaTest.php +++ b/tests/Ackintosh/GaneshaTest.php @@ -66,26 +66,24 @@ public function recordsSuccessAndClose() /** * @test */ - public function notifyTripped() + public function tripsOnce() { - $ganesha = $this->buildGanesha( - 2, - 10 - ); + $ganesha = $this->buildGanesha(2, 10); - $receiver = $this->getMockBuilder('\stdClass') - ->setMethods(['receive']) - ->getMock(); - $receiver->expects($this->once()) - ->method('receive') - ->with(Ganesha::EVENT_TRIPPED, $this->service, ''); + $calledTimes = 0; - $ganesha->subscribe(function ($event, $service, $message) use ($receiver) { - $receiver->receive($event, $service, $message); + $ganesha->subscribe(function ($event, $service, $message) use (&$calledTimes) { + $this->assertSame(Ganesha::EVENT_TRIPPED, $event); + $this->assertSame($this->service, $service); + $this->assertSame('', $message); + + ++$calledTimes; }); $ganesha->failure($this->service); $ganesha->failure($this->service); + + $this->assertSame(1, $calledTimes); }