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
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/phpunit.xml.dist export-ignore
/testo.php export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.php_cs.dist.php export-ignore
Expand Down
16 changes: 0 additions & 16 deletions .github/workflows/phpunit.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ on:
pull_request: null
push:
branches:
- '*.*'
- '1.x'

name: static analysis

Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/testo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
on:
pull_request: null
push:
branches:
- '1.x'

name: testo

jobs:
testo:
uses: spiral/gh-actions/.github/workflows/testo.yml@master
with:
os: >-
['ubuntu-latest']
dependencies: >-
['lowest', 'highest']
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.idea
.php_cs
.php_cs.cache
.phpunit.result.cache
build
composer.lock
coverage
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ processes connected to the RoadRunner server.

Make sure that your server is configured with following PHP version and extensions:

- PHP 8.1+
- PHP 8.2+

### Installation

Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@
}
],
"require": {
"php": "^8.1",
"php": "^8.2",
"ramsey/uuid": "^4.7",
"roadrunner-php/roadrunner-api-dto": "^1.0",
"spiral/goridge": "^4.0"
},
"require-dev": {
"mockery/mockery": "^1.5",
"phpunit/phpunit": "^10.0",
"vimeo/psalm": "^5.9"
"mockery/mockery": "^1.6",
"testo/bridge-mockery": "^0.1.2",
"testo/testo": "^0.10.55",
"vimeo/psalm": "^6 || ^7"
},
"autoload": {
"psr-4": {
Expand All @@ -65,7 +66,7 @@
}
},
"scripts": {
"test": "vendor/bin/phpunit",
"test": "vendor/bin/testo",
"psalm": "vendor/bin/psalm --config=psalm.xml ./src --show-info=true"
},
"config": {
Expand Down
34 changes: 0 additions & 34 deletions phpunit.xml

This file was deleted.

10 changes: 10 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,14 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<!-- #[\Override] is a PHP 8.3 attribute, the package still supports PHP 8.2 -->
<MissingOverrideAttribute errorLevel="suppress" />
<!-- int|float TTL multiplied by an int, the product is rounded and cast to int right away -->
<InvalidOperand>
<errorLevel type="suppress">
<file name="src/Lock.php" />
</errorLevel>
</InvalidOperand>
</issueHandlers>
</psalm>
20 changes: 20 additions & 0 deletions testo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

use Testo\Application\Config\ApplicationConfig;
use Testo\Application\Config\SuiteConfig;
use Testo\Bridge\Mockery\MockeryPlugin;

return new ApplicationConfig(
src: ['src'],
suites: [
new SuiteConfig(
name: 'Unit',
location: ['tests/src'],
),
],
plugins: [
new MockeryPlugin(),
],
);
61 changes: 27 additions & 34 deletions tests/src/LockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,22 @@
use RoadRunner\Lock\LockIdGeneratorInterface;
use Spiral\Goridge\RPC\Codec\ProtobufCodec;
use Spiral\Goridge\RPC\RPCInterface;

final class LockTest extends TestCase
use Testo\Assert;
use Testo\Assert\ExpectException;
use Testo\Data\DataProvider;
use Testo\Lifecycle\BeforeTest;
use Testo\Test;

#[Test]
final class LockTest
{
private RPCInterface|MockInterface $rpc;
private LockIdGeneratorInterface|MockInterface $idGenerator;
private Lock $lock;

#[BeforeTest]
protected function setUp(): void
{
parent::setUp();

$this->rpc = m::mock(RPCInterface::class);

$this->rpc->shouldReceive('withCodec')
Expand All @@ -34,9 +39,7 @@ protected function setUp(): void
$this->lock = new Lock($this->rpc, $this->idGenerator);
}

/**
* @dataProvider lockTypeDataProvider
*/
#[DataProvider('lockTypeDataProvider')]
public function testLock(
string $method,
string $callMethod,
Expand Down Expand Up @@ -69,15 +72,13 @@ public function testLock(

$result = $this->lock->$method(resource: 'resource', id: $id, ttl: $ttl, waitTTL: $wait);
if ($expectedResult) {
$this->assertSame(($id === null ? 'some-id' : $id), $result);
Assert::same($result, ($id === null ? 'some-id' : $id));
} else {
$this->assertFalse($result);
Assert::false($result);
}
}

/**
* @dataProvider resultDataProvider
*/
#[DataProvider('resultDataProvider')]
public function testRelease(bool $result): void
{
$this->rpc->shouldReceive('call')
Expand All @@ -90,12 +91,10 @@ public function testRelease(bool $result): void
})
->andReturn(new Response(['ok' => $result]));

$this->assertSame($result, $this->lock->release('resource', 'some-id'));
Assert::same($this->lock->release('resource', 'some-id'), $result);
}

/**
* @dataProvider resultDataProvider
*/
#[DataProvider('resultDataProvider')]
public function testForceRelease(bool $result): void
{
$this->rpc->shouldReceive('call')
Expand All @@ -108,12 +107,10 @@ public function testForceRelease(bool $result): void
})
->andReturn(new Response(['ok' => $result]));

$this->assertSame($result, $this->lock->forceRelease('resource'));
Assert::same($this->lock->forceRelease('resource'), $result);
}

/**
* @dataProvider resultDataProvider
*/
#[DataProvider('resultDataProvider')]
public function testExists(bool $result): void
{
$this->rpc->shouldReceive('call')
Expand All @@ -126,12 +123,10 @@ public function testExists(bool $result): void
})
->andReturn(new Response(['ok' => $result]));

$this->assertSame($result, $this->lock->exists('resource'));
Assert::same($this->lock->exists('resource'), $result);
}

/**
* @dataProvider updateTTLDataProvider
*/
#[DataProvider('updateTTLDataProvider')]
public function testUpdateTTL($ttl, int $expectedTtl, bool $result): void
{
$this->rpc->shouldReceive('call')
Expand All @@ -145,12 +140,10 @@ public function testUpdateTTL($ttl, int $expectedTtl, bool $result): void
})
->andReturn(new Response(['ok' => $result]));

$this->assertSame($result, $this->lock->updateTTL('resource', 'some-id', $ttl));
Assert::same($this->lock->updateTTL('resource', 'some-id', $ttl), $result);
}

/**
* @dataProvider resultDataProvider
*/
#[DataProvider('resultDataProvider')]
public function testExistsWithId(bool $result): void
{
$this->rpc->shouldReceive('call')
Expand All @@ -163,7 +156,7 @@ public function testExistsWithId(bool $result): void
})
->andReturn(new Response(['ok' => $result]));

$this->assertSame($result, $this->lock->exists('resource', 'some-id'));
Assert::same($this->lock->exists('resource', 'some-id'), $result);
}

public static function lockTypeDataProvider(): \Generator
Expand Down Expand Up @@ -220,33 +213,33 @@ public static function resultDataProvider(): \Traversable
yield [false];
}

#[ExpectException(\LogicException::class)]
public function testLockNegativeTtl(): void
{
self::expectException(\LogicException::class);
$this->lock->lock('resource', 'uuid', -300);
}

#[ExpectException(\LogicException::class)]
public function testLockNegativeWaitTtl(): void
{
self::expectException(\LogicException::class);
$this->lock->lock('resource', 'uuid', 0, -300);
}

#[ExpectException(\LogicException::class)]
public function testLockReadNegativeTtl(): void
{
self::expectException(\LogicException::class);
$this->lock->lock('resource', 'uuid', -300);
}

#[ExpectException(\LogicException::class)]
public function testLockReadNegativeWaitTtl(): void
{
self::expectException(\LogicException::class);
$this->lock->lockRead('resource', 'uuid', 0, -300);
}

#[ExpectException(\LogicException::class)]
public function testUpdateNegativeWaitTtl(): void
{
self::expectException(\LogicException::class);
$this->lock->updateTTL('resource', 'uuid', -300);
}
}
10 changes: 0 additions & 10 deletions tests/src/TestCase.php

This file was deleted.

Loading