Skip to content

Commit

Permalink
Merge pull request spatie#124 from joaorobertopb/patch-1
Browse files Browse the repository at this point in the history
Bump 'phpunit' version And Fix build Travis-CI
  • Loading branch information
brendt authored Oct 6, 2020
2 parents 460eab3 + 2001e1c commit ed71650
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.phpunit.result.cache
build
composer.lock
vendor
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"require-dev": {
"larapack/dd": "^1.1",
"phpunit/phpunit": "^6.5",
"phpunit/phpunit": "^7.5 || ^8.0 || ^9.0",
"symfony/stopwatch": "^4.0 || ^5.0"
},
"suggest": {
Expand Down
3 changes: 1 addition & 2 deletions tests/ChildRuntimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Opis\Closure\SerializableClosure;
use function Opis\Closure\serialize;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Process;

class ChildRuntimeTest extends TestCase
Expand All @@ -31,6 +30,6 @@ public function it_can_run()

$process->wait();

$this->assertContains('child', $process->getOutput());
$this->assertStringContainsString('child', $process->getOutput());
}
}
13 changes: 6 additions & 7 deletions tests/ContentLengthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Spatie\Async\Tests;

use PHPUnit\Framework\TestCase;
use Spatie\Async\Output\ParallelError;
use Spatie\Async\Pool;

Expand All @@ -17,11 +16,11 @@ public function it_can_increase_max_content_length()

$pool->add(new MyTask(), $longerContentLength);

$this->assertContains('finished: 0', (string) $pool->status());
$this->assertStringContainsString('finished: 0', (string) $pool->status());

await($pool);

$this->assertContains('finished: 1', (string) $pool->status());
$this->assertStringContainsString('finished: 1', (string) $pool->status());
}

/** @test */
Expand All @@ -33,11 +32,11 @@ public function it_can_decrease_max_content_length()

$pool->add(new MyTask(), $shorterContentLength);

$this->assertContains('finished: 0', (string) $pool->status());
$this->assertStringContainsString('finished: 0', (string) $pool->status());

await($pool);

$this->assertContains('finished: 1', (string) $pool->status());
$this->assertStringContainsString('finished: 1', (string) $pool->status());
}

/** @test */
Expand All @@ -52,7 +51,7 @@ public function it_can_throw_error_with_increased_max_content_length()
}, $longerContentLength)
->catch(function (ParallelError $e) use ($longerContentLength) {
$message = "/The output returned by this child process is too large. The serialized output may only be $longerContentLength bytes long./";
$this->assertRegExp($message, $e->getMessage());
$this->assertMatchesRegExp($message, $e->getMessage());
});

await($pool);
Expand All @@ -70,7 +69,7 @@ public function it_can_throw_error_with_decreased_max_content_length()
}, $longerContentLength)
->catch(function (ParallelError $e) use ($longerContentLength) {
$message = "/The output returned by this child process is too large. The serialized output may only be $longerContentLength bytes long./";
$this->assertRegExp($message, $e->getMessage());
$this->assertMatchesRegExp($message, $e->getMessage());
});

await($pool);
Expand Down
15 changes: 7 additions & 8 deletions tests/ErrorHandlingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Error;
use Exception;
use ParseError;
use PHPUnit\Framework\TestCase;
use Spatie\Async\Output\ParallelError;
use Spatie\Async\Output\ParallelException;
use Spatie\Async\Pool;
Expand All @@ -21,7 +20,7 @@ public function it_can_handle_exceptions_via_catch_callback()
$pool->add(function () {
throw new MyException('test');
})->catch(function (MyException $e) {
$this->assertRegExp('/test/', $e->getMessage());
$this->assertMatchesRegExp('/test/', $e->getMessage());
});
}

Expand Down Expand Up @@ -88,7 +87,7 @@ public function it_can_handle_typed_exceptions_via_catch_callback()
throw new MyException('test');
})
->catch(function (MyException $e) use (&$myExceptionCount) {
$this->assertRegExp('/test/', $e->getMessage());
$this->assertMatchesRegExp('/test/', $e->getMessage());

$myExceptionCount += 1;
})
Expand All @@ -112,7 +111,7 @@ public function it_can_handle_typed_exceptions_via_catch_callback()
public function it_throws_the_exception_if_no_catch_callback()
{
$this->expectException(MyException::class);
$this->expectExceptionMessageRegExp('/test/');
$this->expectExceptionMessageRegularExpression('/test/');

$pool = Pool::create();

Expand All @@ -127,7 +126,7 @@ public function it_throws_the_exception_if_no_catch_callback()
public function it_throws_fatal_errors()
{
$this->expectException(Error::class);
$this->expectExceptionMessageRegExp('/test/');
$this->expectExceptionMessageRegularExpression('/test/');

$pool = Pool::create();

Expand All @@ -148,7 +147,7 @@ public function it_keeps_the_original_trace()

$myClass->throwException();
})->catch(function (MyException $exception) {
$this->assertContains('Spatie\Async\Tests\MyClass->throwException()', $exception->getMessage());
$this->assertStringContainsString('Spatie\Async\Tests\MyClass->throwException()', $exception->getMessage());
});

$pool->wait();
Expand All @@ -162,7 +161,7 @@ public function it_handles_stderr_as_parallel_error()
$pool->add(function () {
fwrite(STDERR, 'test');
})->catch(function (ParallelError $error) {
$this->assertContains('test', $error->getMessage());
$this->assertStringContainsString('test', $error->getMessage());
});

$pool->wait();
Expand Down Expand Up @@ -192,7 +191,7 @@ public function it_can_handle_synchronous_exception()
$pool->add(function () {
throw new MyException('test');
})->catch(function (MyException $e) {
$this->assertRegExp('/test/', $e->getMessage());
$this->assertMatchesRegExp('/test/', $e->getMessage());
});

$pool->wait();
Expand Down
16 changes: 8 additions & 8 deletions tests/PoolStatusTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace Spatie\Async;
namespace Spatie\Async\Tests;

use Exception;
use PHPUnit\Framework\TestCase;
use Spatie\Async\Tests\MyTask;
use Spatie\Async\Pool;

class PoolStatusTest extends TestCase
{
Expand All @@ -15,11 +15,11 @@ public function it_can_show_a_textual_status()

$pool->add(new MyTask());

$this->assertContains('finished: 0', (string) $pool->status());
$this->assertStringContainsString('finished: 0', (string) $pool->status());

await($pool);

$this->assertContains('finished: 1', (string) $pool->status());
$this->assertStringContainsString('finished: 1', (string) $pool->status());
}

/** @test */
Expand All @@ -37,9 +37,9 @@ public function it_can_show_a_textual_failed_status()

$pool->wait();

$this->assertContains('finished: 0', (string) $pool->status());
$this->assertContains('failed: 5', (string) $pool->status());
$this->assertContains('failed with Exception: Test', (string) $pool->status());
$this->assertStringContainsString('finished: 0', (string) $pool->status());
$this->assertStringContainsString('failed: 5', (string) $pool->status());
$this->assertStringContainsString('failed with Exception: Test', (string) $pool->status());
}

/** @test */
Expand All @@ -55,6 +55,6 @@ public function it_can_show_timeout_status()

$pool->wait();

$this->assertContains('timeout: 5', (string) $pool->status());
$this->assertStringContainsString('timeout: 5', (string) $pool->status());
}
}
10 changes: 3 additions & 7 deletions tests/PoolTest.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
<?php

namespace Spatie\Async;
namespace Spatie\Async\Tests;

use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use Spatie\Async\Pool;
use Spatie\Async\Process\SynchronousProcess;
use Spatie\Async\Tests\InvokableClass;
use Spatie\Async\Tests\MyClass;
use Spatie\Async\Tests\MyTask;
use Spatie\Async\Tests\NonInvokableClass;
use Symfony\Component\Stopwatch\Stopwatch;

class PoolTest extends TestCase
{
/** @var \Symfony\Component\Stopwatch\Stopwatch */
protected $stopwatch;

protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down
30 changes: 30 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Spatie\Async\Tests;

use PHPUnit\Framework\TestCase as BaseTestCase;

class TestCase extends BaseTestCase
{
public function expectExceptionMessageRegularExpression(string $regularExpression): void
{
if (method_exists($this, 'expectExceptionMessageMatches')) {
// PHPUnit 8.0+
$this->expectExceptionMessageMatches($regularExpression);
} else {
// legacy PHPUnit 7.5
$this->expectExceptionMessageRegExp($regularExpression);
}
}

public function assertMatchesRegExp($pattern, $string)
{
if (method_exists($this, 'assertMatchesRegularExpression')) {
// PHPUnit 10+
$this->assertMatchesRegularExpression($pattern, $string);
} else {
// PHPUnit < 9.2
$this->assertRegExp($pattern, $string);
}
}
}

0 comments on commit ed71650

Please sign in to comment.