Skip to content

Commit

Permalink
Merge pull request #38 from vuongxuongminh/feat/bump-laravel-and-phpu…
Browse files Browse the repository at this point in the history
…nit-to-latest-version

feat: bump Laravel & PHPUnit to latest versions
  • Loading branch information
vuongxuongminh authored Jul 16, 2023
2 parents be78774 + b9d4448 commit 369b19a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.buildpath
.project
.settings
.phpunit.result.cache
.phpunit.cache
.idea
build
composer.lock
Expand All @@ -11,4 +11,4 @@ nbproject
vendor
phpunit.phar
phpunit.xml
Thumbs.db
Thumbs.db
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 4.0.0

- Add support Laravel 10 and drop support Laravel 9.
- Bump version and migrate syntax of PHPUnit.

## 3.0.0

- Drop support for older Laravel versions lower than 9.
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
],
"require": {
"php": "^8.1",
"illuminate/support": "^9.0",
"illuminate/support": "^10.0",
"spatie/async": "^1.5"
},
"require-dev": {
"orchestra/testbench": "^7.0",
"orchestra/testbench": "^8.0",
"symplify/easy-coding-standard": "^11.2"
},
"autoload": {
Expand Down
13 changes: 7 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage/>
<testsuites>
<testsuite name="VXM Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
8 changes: 5 additions & 3 deletions tests/EventTestClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@

use Exception;

class EventTestClass extends TestCase
class EventTestClass
{
public string|Exception $capture;

public function success($result)
{
$this->assertStringContainsString('ok!', $result);
$this->capture = $result;
}

public function catch(Exception $exception)
{
$this->assertStringContainsString('ok!', $exception->getMessage());
$this->capture = $exception;
}
}
29 changes: 19 additions & 10 deletions tests/JobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,55 @@
namespace VXM\Async\Tests;

use Async;
use PHPUnit\Framework\Attributes\DataProvider;
use VXM\Async\Pool;

class JobTest extends TestCase
{
/**
* @dataProvider successJobProvider
*/
protected function setUp(): void
{
parent::setUp();

$this->app->forgetInstance(EventTestClass::class);
$this->app->singleton(EventTestClass::class);
}

#[DataProvider('successJobProvider')]
public function testHandleSuccess($handler, array $events): void
{
Async::run($handler, $events);

$this->assertStringContainsString('ok!', current(Async::wait()));
$this->assertStringContainsString('ok!', $this->app->get(EventTestClass::class)->capture);
}

public function testBatchHandleSuccess(): void
{
Async::batchRun(...$this->successJobProvider());
Async::batchRun(...self::successJobProvider());

foreach (Async::wait() as $result) {
$this->assertStringContainsString('ok!', $result);
$this->assertStringContainsString('ok!', $this->app->get(EventTestClass::class)->capture);
}
}

/**
* @dataProvider errorJobProvider
*/
#[DataProvider('errorJobProvider')]
public function testHandleError($handler, array $events): void
{
Async::run($handler, $events);
$results = array_filter(Async::wait());

$this->assertEmpty($results);
$this->assertInstanceOf(\Exception::class, $this->app->get(EventTestClass::class)->capture);
}

public function testBatchHandleError(): void
{
Async::batchRun(...$this->errorJobProvider());
Async::batchRun(...self::errorJobProvider());
$results = array_filter(Async::wait());

$this->assertEmpty($results);
$this->assertInstanceOf(\Exception::class, $this->app->get(EventTestClass::class)->capture);
}

public function testMaxOutputLength(): void
Expand All @@ -64,7 +73,7 @@ public function testMaxOutputLength(): void
}
}

public function successJobProvider(): array
public static function successJobProvider(): array
{
return [
[
Expand All @@ -90,7 +99,7 @@ function () {
];
}

public function errorJobProvider(): array
public static function errorJobProvider(): array
{
return [
[
Expand Down

0 comments on commit 369b19a

Please sign in to comment.