Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,4 +29,4 @@ jobs:
run: composer update

- name: Run php-cs-fixer
run: ./vendor/bin/php-cs-fixer fix --dry-run --diff .
run: ./vendor/bin/php-cs-fixer fix --dry-run --diff .
3 changes: 1 addition & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ jobs:
fail-fast: false
matrix:
php-version:
- "8.0"
- "8.1"
- "8.2"
- "8.3"
Expand Down Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)

</div>

Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
"repositories": [
{
"type": "git",
"url": "https://github.com/kornrunner/phpunit-testlistener-vcr"
"url": "https://github.com/marmichalski/phpunit-testlistener-vcr"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPUnit 10 event system support: php-vcr/phpunit-testlistener-vcr#45

}
],
"require": {
"php": ">=8.0",
"php": "^8.1",
"psr/http-message": "^1.0|^2.0"
},
"suggest": {
Expand All @@ -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",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

php 8.4 support is not tagged 😭

"php-vcr/phpunit-testlistener-vcr": "dev-phpunit-evt-system",
"php-coveralls/php-coveralls": "~2.5",
"predis/predis": "^1.1",
"guzzlehttp/guzzle": "^7.4.5",
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/client/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.0-cli
FROM php:8.1-cli

COPY install_composer.sh /tmp/

Expand Down
23 changes: 15 additions & 8 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="tests/bootstrap.php"
colors="true"
>
<coverage>
<report>
<!-- https://github.com/php-coveralls/php-coveralls#phpunit -->
<clover outputFile="build/logs/clover.xml"/>
Expand All @@ -16,7 +18,12 @@
</testsuite>
</testsuites>
<logging/>
<listeners>
<listener class="VCR\PHPUnit\TestListener\VCRTestListener" file="vendor/php-vcr/phpunit-testlistener-vcr/src/VCRTestListener.php"/>
</listeners>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
<extensions>
<bootstrap class="VCR\PHPUnit\TestListener\Extension\VCRExtension" />
</extensions>
</phpunit>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions tests/Ackintosh/Ganesha/Storage/Adapter/ApcuStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -37,7 +37,7 @@ public function test_dec()
*/
public function test_delete()
{
$key = $this->getName();
$key = $this->name();
$value = __METHOD__;
$store = new ApcuStore();

Expand All @@ -52,7 +52,7 @@ public function test_delete()
*/
public function test_exists()
{
$key = $this->getName();
$key = $this->name();
$value = __METHOD__;
$store = new ApcuStore();

Expand All @@ -67,7 +67,7 @@ public function test_exists()
*/
public function test_fetch()
{
$key = $this->getName();
$key = $this->name();
$value = __METHOD__;
$store = new ApcuStore();

Expand All @@ -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));
Expand All @@ -103,7 +103,7 @@ public function test_inc()
*/
public function test_store()
{
$key = $this->getName();
$key = $this->name();
$value = __METHOD__;
$store = new ApcuStore();

Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions tests/Ackintosh/Ganesha/Storage/Adapter/ApcuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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());
}
}
22 changes: 11 additions & 11 deletions tests/Ackintosh/Ganesha/Storage/Adapter/MemcachedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Predis\Client;
use Predis\ClientInterface;

class PredisRedisTest extends AbstractRedisTest
class PredisRedisTest extends AbstractRedisSpec
{
protected function getRedisConnection(): ClientInterface
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Ackintosh/Ganesha/Storage/Adapter/RedisArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use RedisArray;

class RedisArrayTest extends AbstractRedisTest
class RedisArrayTest extends AbstractRedisSpec
{
/**
* @return RedisArray
Expand Down
2 changes: 1 addition & 1 deletion tests/Ackintosh/Ganesha/Storage/Adapter/RedisRedisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Ackintosh\Ganesha\Storage\Adapter;

class RedisRedisTest extends AbstractRedisTest
class RedisRedisTest extends AbstractRedisSpec
{
/**
* @return \Redis
Expand Down
2 changes: 1 addition & 1 deletion tests/Ackintosh/Ganesha/Storage/Adapter/RedisStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
24 changes: 11 additions & 13 deletions tests/Ackintosh/GaneshaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,24 @@ public function recordsSuccessAndClose()
/**
* @test
*/
public function notifyTripped()
public function tripsOnce()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not entirely certain what this test was asserting, my assumption here is that the EVENT_TRIPPED is passed only once?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right! My intention was to test that Ganesha::EVENT_TRIPPED is triggered, and that it happens only once.

{
$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);
}


Expand Down