Skip to content

Commit

Permalink
Merge pull request #41 from darkwood-fr/composer
Browse files Browse the repository at this point in the history
⬆️ Update composer
  • Loading branch information
matyo91 authored Sep 3, 2023
2 parents 5953a4b + 7a5adb7 commit 817a348
Show file tree
Hide file tree
Showing 17 changed files with 170 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
->setRules([
'@PHP82Migration' => true,
'@PhpCsFixer' => true,
'@Symfony' => true,
'@Symfony' => true, // https://cs.symfony.com/doc/ruleSets/Symfony.html
'@Symfony:risky' => true,
'heredoc_indentation' => false,
'php_unit_internal_class' => false, // From @PhpCsFixer but we don't want it
Expand Down
86 changes: 86 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
### 1.1.x

- Upgrade to Symfony 6.3
- Refactor docs structure
- Refactor tooling from https://github.com/jolicode/castor
- Rework on Flow\DriverInterface
- Update `async` that now $onResolve get called with async $callback result or Flow\Exception as first argument
- Update `tick` that now return a Closure to cleanup tick interval
- Remove `start` and `stop`
- Add Fiber Driver from https://github.com/jolicode/castor/blob/main/src/functions.php

### 1.1.2

- Update to PHP 8.2
- Upgrade from amphp/amp v2 to amphp/amp v3 that use PHP Fibers
- Upgrade from react/event-loop v1 to reactphp/async v4 that use PHP Fibers
- Upgrade from Swoole v5 to Openswoole v22
- Rename function `corouting` to `async` in Flow\DriverInterface
- Add function `sleep` in Flow\DriverInterface

### 1.1.1

- Rename entire project from `Railway FBP` to `Flow`
- Bundle `Flow` to PHP monorepository
- Merge from `packages/symfony` to `packages/php` and make Flow [Symfony](https://symfony.com) friendly
- New DX interface `Flow\FlowInterface`
- Error managment is now integrated to Flow
- Remove context associated with processing IP
- Deprecate `Flow\Flow\SequenceFlow` in favor for `Flow\Flow\Flow`
- Deprecate `Flow\Flow\ErrorFlow` in favor for `Flow\Flow\Flow`
- Update `Flow\Flow\YFlow` and make it plain native
- Update `Flow\IP` that use readonly object
- New Flow logo

### 1.1.0

- Release MIT License
- Update dependencies to PHP 8.1

### 1.0.9

- Add `Flow\Flow\YFlow` that allows introduce recursivity into Flow language approach

### 1.0.8

- Add code of conduct

### 1.0.7

- Define Monads

### 1.0.6

- Add `Flow\TransportFlow`
- Flow can process multiple jobs in parallel

### 1.0.5

- Add Symfony integration
- Define monads

### 1.0.4

- Refactor structure
- Decouple integration

### 1.0.3

- Add `Flow\IpStrategy` add several Ip strategy for data processing

### 1.0.2

- Add `Flow\Driver\DriverInterface`
- Add `Flow\Driver\AmpDriver`
- Add `Flow\Driver\ReactDriver`
- Add `Flow\Driver\SwooleDriver`

### 1.0.1

- Add `Flow\Producer\CollectionConsumer`
- Add `Flow\Producer\CollectionProducer`
- Add `Flow\Transport\CollectionTransport`

# 1.0.0

- Initial release
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,26 @@
}
],
"keywords": [
"php",
"symfony",
"async",
"amphp",
"async",
"fiber",
"monad",
"reactphp",
"swoole",
"monad"
"symfony",
"php"
],
"require": {
"php": "^8.2"
},
"require-dev": {
"amphp/amp": "^3.0",
"openswoole/ide-helper": "^22.0",
"phpunit/phpunit": "^9.5",
"react/async": "4.x-dev",
"phpunit/phpunit": "^10.3",
"react/async": "^4.1",
"symfony/doctrine-messenger": "^6.3",
"symfony/messenger": "^6.3",
"symfony/orm-pack": "^2.3"
"symfony/orm-pack": "^2.4"
},
"suggest": {
"amphp/amp": "Provide asynchronous with AMP",
Expand Down
2 changes: 2 additions & 0 deletions docs/src/content/en/docs/getting-started/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,5 @@ toc: true
- Add `Flow\Transport\CollectionTransport`

# 1.0.0

- Initial release
44 changes: 20 additions & 24 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="false"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
verbose="true"
colors="true">
<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
colors="true"
executionOrder="depends,defects"
failOnRisky="true"
failOnWarning="true"
requireCoverageMetadata="false">
<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
4 changes: 2 additions & 2 deletions src/Driver/SwooleDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public function async(Closure $callback, Closure $onResolve = null): Closure
Coroutine::run(static function () use ($callback, $onResolve, $args) {
Coroutine::create(static function (Closure $callback, array $args, Closure $onResolve = null) {
try {
$callback(...$args, ...($args = []));
$return = $callback(...$args, ...($args = []));
if ($onResolve) {
$onResolve(null);
$onResolve($return);
}
} catch (Throwable $exception) {
if ($onResolve) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Driver/AmpDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Flow\Driver\AmpDriver;
use Flow\DriverInterface;

class AmpDriverTest extends DriverTest
class AmpDriverTest extends DriverTestCase
{
protected function createDriver(): DriverInterface
{
Expand Down
35 changes: 23 additions & 12 deletions tests/Driver/DriverTest.php → tests/Driver/DriverTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@
use Exception;
use Flow\DriverInterface;
use PHPUnit\Framework\TestCase;
use Throwable;

abstract class DriverTest extends TestCase
abstract class DriverTestCase extends TestCase
{
public function testAsync(): void
{
$driver = $this->createDriver();
$driver->async(static function () {
}, function (?Throwable $e) {
$this->assertNull($e);
}, function (mixed $value) {
$this->assertNull($value);
})();
}

public function testAsyncReturn(): void
{
$driver = $this->createDriver();
$driver->async(static function () {
return 2;
}, function (mixed $value) {
$this->assertEquals(2, $value);
})();
}

Expand All @@ -25,8 +34,8 @@ public function testAsyncError(): void
$driver = $this->createDriver();
$driver->async(static function () {
throw new Exception();
}, function (?Throwable $e) {
$this->assertInstanceOf(Exception::class, $e);
}, function (mixed $value) {
$this->assertInstanceOf(Exception::class, $value);
})();
}

Expand All @@ -35,14 +44,16 @@ public function testDelay(): void
$driver = $this->createDriver();
$driver->async(static function () use ($driver) {
$driver->delay(1 / 1000);
}, function (?Throwable $e) {
$this->assertNull($e);
}, function (mixed $value) {
$this->assertNull($value);
})();
}

/*public function testTick(): void
public function testTick(): void
{
$i = 0;
$this->assertTrue(true);

/*$i = 0;
$driver = $this->createDriver();
$driver->tick(1, function () use (&$i) {
$i++;
Expand All @@ -51,8 +62,8 @@ public function testDelay(): void
$driver->delay(3 / 1000);
$this->assertGreaterThan(3, $i);
})();
}*/
})();*/
}

abstract protected function createDriver(): DriverInterface;
}
2 changes: 1 addition & 1 deletion tests/Driver/FiberDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Flow\Driver\FiberDriver;
use Flow\DriverInterface;

class FiberDriverTest extends DriverTest
class FiberDriverTest extends DriverTestCase
{
protected function createDriver(): DriverInterface
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Driver/ReactDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Flow\Driver\ReactDriver;
use Flow\DriverInterface;

class ReactDriverTest extends DriverTest
class ReactDriverTest extends DriverTestCase
{
protected function createDriver(): DriverInterface
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Driver/SwooleDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Flow\Driver\SwooleDriver;
use Flow\DriverInterface;

class SwooleDriverTest extends DriverTest
class SwooleDriverTest extends DriverTestCase
{
protected function createDriver(): DriverInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function testAckAndReject($receivers, $expectedReceiversIps, $expectedAck
/**
* @return array<array<mixed>>
*/
public function receiverProvider(): array
public static function receiverProvider(): array
{
$expectedReceiversIps = new SplObjectStorage();
/** @var array<mixed, ReceiverInterface> $expectedAckIpsReceivers */
Expand Down
9 changes: 6 additions & 3 deletions tests/Flow/FlowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
use Flow\Flow\Flow;
use Flow\Ip;
use Flow\IpStrategyInterface;
use PHPUnit\Framework\TestCase;
use RuntimeException;

class FlowTest extends AbstractFlowTest
class FlowTest extends TestCase
{
use FlowTrait;

/**
* @dataProvider jobProvider
*
Expand Down Expand Up @@ -71,11 +74,11 @@ public function testJobs(DriverInterface $driver): void
/**
* @return array<array<mixed>>
*/
public function jobProvider(): array
public static function jobProvider(): array
{
$exception = new RuntimeException('job error');

return $this->matrix(fn (DriverInterface $driver) => [
return self::matrix(fn (DriverInterface $driver) => [
'oneJob' => [[static function (ArrayObject $data) {
$data['number'] = 5;
}], 5],
Expand Down
7 changes: 4 additions & 3 deletions tests/Flow/AbstractFlowTest.php → tests/Flow/FlowTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@

use Closure;
use Flow\Driver\AmpDriver;
use Flow\Driver\FiberDriver;
use Flow\Driver\ReactDriver;
use Flow\Driver\SwooleDriver;
use Flow\IpStrategy\LinearIpStrategy;
use Flow\IpStrategy\MaxIpStrategy;
use Flow\IpStrategy\StackIpStrategy;
use PHPUnit\Framework\TestCase;

abstract class AbstractFlowTest extends TestCase
trait FlowTrait
{
/**
* @return array<array<mixed>>
*/
protected function matrix(Closure $datas): array
protected static function matrix(Closure $datas): array
{
$drivers = [
// 'amp' => fn (): AmpDriver => new AmpDriver(),
// 'fiber' => fn (): FiberDriver => new FiberDriver(),
'react' => fn (): ReactDriver => new ReactDriver(),
// 'swoole' => fn (): SwooleDriver => new SwooleDriver(),
];
Expand Down
9 changes: 6 additions & 3 deletions tests/Flow/TransportFlowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
use Flow\Flow\Flow;
use Flow\Flow\TransportFlow;
use Flow\IpStrategyInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Transport\InMemory\InMemoryTransport;

class TransportFlowTest extends AbstractFlowTest
class TransportFlowTest extends TestCase
{
use FlowTrait;

/**
* @dataProvider jobsProvider
*
Expand Down Expand Up @@ -48,9 +51,9 @@ public function testJobs(DriverInterface $driver, IpStrategyInterface $ipStrateg
/**
* @return array<array<mixed>>
*/
public function jobsProvider(): array
public static function jobsProvider(): array
{
return $this->matrix(fn (DriverInterface $driver) => [
return self::matrix(fn (DriverInterface $driver) => [
'oneJob' => [[static function (ArrayObject $data): void {
$data['number'] = 1;
}], 1],
Expand Down
Loading

0 comments on commit 817a348

Please sign in to comment.