Skip to content
Draft
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
6 changes: 5 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [8.1, 8.2, 8.3, 8.4]
php: [8.1, 8.2, 8.3, 8.4, 8.5]
laravel: [10, 11, 12]
driver: [swoole, openswoole, 'roadrunner/frankenphp']
exclude:
Expand All @@ -26,6 +26,10 @@ jobs:
laravel: 12
- php: 8.4
laravel: 10
- php: 8.5
laravel: 10
- php: 8.5
laravel: 11
- php: 8.1
driver: openswoole

Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@
"laravel/scout": "^10.2.1",
"laravel/socialite": "^5.6.1",
"livewire/livewire": "^2.12.3|^3.0",
"mockery/mockery": "^1.5.1",
"nunomaduro/collision": "^6.4.0|^7.5.2|^8.0",
"orchestra/testbench": "^8.21|^9.0|^10.0",
"orchestra/testbench": "^8.36|^9.15|^10.8",
"phpstan/phpstan": "^2.1.7",
"phpunit/phpunit": "^10.4|^11.5",
"spiral/roadrunner-cli": "^2.6.0",
Expand Down
38 changes: 30 additions & 8 deletions tests/BinaryBootstrapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,52 @@

namespace Laravel\Octane\Tests;

use Orchestra\Testbench\Foundation\Actions\DeleteVendorSymlink;
use Orchestra\Testbench\Foundation\Application as Testbench;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;

use function Orchestra\Testbench\default_skeleton_path;
use function Orchestra\Testbench\package_path;
use function Orchestra\Testbench\php_binary;

class BinaryBootstrapTest extends TestCase
{
protected $app;

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

$this->app = Testbench::createVendorSymlink(default_skeleton_path(), package_path('vendor'));
}

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

(new DeleteVendorSymlink)->handle($this->app);

unset($this->app);
}

public function test_it_can_retrieve_base_path_from_environment_variable()
{
$basePath = realpath(__DIR__.'/../vendor/orchestra/testbench-core/laravel');
$basePath = default_skeleton_path();

$process = Process::fromShellCommandline(
'"'.$this->phpBinary().'" base-path.php', __DIR__, ['APP_BASE_PATH' => $basePath], null, null
php_binary(escape: true).' base-path.php', __DIR__, ['APP_BASE_PATH' => $basePath], null, null
);

$process->mustRun();

$output = $process->getOutput();

if (\PHP_VERSION_ID >= 80100) {
$output = array_filter(explode("\n", $output), function ($output) {
return ! empty($output) && ! str_starts_with($output, 'Deprecated:');
});
$output = array_filter(explode("\n", $output), function ($output) {
return ! empty($output) && ! str_starts_with($output, 'Deprecated:');
});

$output = implode('', $output);
}
$output = implode('', $output);

$this->assertSame($basePath, $output);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/EnsureRequestsDontExceedMaxExecutionTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class EnsureRequestsDontExceedMaxExecutionTimeTest extends TestCase
{
/** @doesNotPerformAssertions @test */
/** @test */
public function test_process_is_killed_if_current_request_exceeds_max_execution_time()
{
$table = new FakeTimerTable;
Expand Down
1 change: 0 additions & 1 deletion tests/Listeners/CloseMonologHandlersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

class CloseMonologHandlersTest extends TestCase
{
/** @doesNotPerformAssertions */
public function test_logger_are_closed_after_worker_termination()
{
[$app, $worker, $client] = $this->createOctaneContext([
Expand Down
1 change: 0 additions & 1 deletion tests/Listeners/FlushMonologStateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

class FlushMonologStateTest extends TestCase
{
/** @doesNotPerformAssertions */
public function test_logger_are_reset()
{
[$app, $worker, $client] = $this->createOctaneContext([
Expand Down
1 change: 0 additions & 1 deletion tests/Listeners/FlushTranslatorCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class FlushTranslatorCacheTest extends TestCase
{
/** @doesNotPerformAssertions */
public function test_parsed_keys_cache_is_flushed()
{
[$app, $worker, $client] = $this->createOctaneContext([
Expand Down
6 changes: 3 additions & 3 deletions tests/Listeners/ReportExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class ReportExceptionTest extends TestCase
{
/** @doesNotPerformAssertions @test */
/** @test */
public function test_exceptions_are_streamed()
{
[$app, $worker] = $this->createOctaneContext([]);
Expand All @@ -27,7 +27,7 @@ public function test_exceptions_are_streamed()
$worker->dispatchEvent($app, new WorkerErrorOccurred($exception, $app));
}

/** @doesNotPerformAssertions @test */
/** @test */
public function test_exceptions_are_reported()
{
[$app, $worker] = $this->createOctaneContext([]);
Expand All @@ -49,7 +49,7 @@ public function test_exceptions_are_reported()
$worker->dispatchEvent($app, new WorkerErrorOccurred($exception, $app));
}

/** @doesNotPerformAssertions @test */
/** @test */
public function test_dd_calls_are_not_streamed()
{
[$app, $worker] = $this->createOctaneContext([]);
Expand Down
6 changes: 3 additions & 3 deletions tests/OnWorkerStartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Laravel\Octane\Swoole\WorkerState;
use Mockery;

use function Orchestra\Testbench\default_skeleton_path;

class OnWorkerStartTest extends TestCase
{
public function test_should_clear_opcache_returns_true_by_default(): void
Expand All @@ -16,7 +18,6 @@ public function test_should_clear_opcache_returns_true_by_default(): void

$reflection = new \ReflectionClass($handler);
$method = $reflection->getMethod('shouldClearOpcodeCache');
$method->setAccessible(true);

$this->assertTrue($method->invoke($handler));
}
Expand All @@ -25,7 +26,7 @@ public function test_should_clear_opcache_returns_configured_value(): void
{
$extension = Mockery::mock(SwooleExtension::class);
$workerState = Mockery::mock(WorkerState::class);
$basePath = realpath(__DIR__.'/../vendor/orchestra/testbench-core/laravel');
$basePath = default_skeleton_path();

// Mock the OnWorkerStart handler to test just the shouldClearOpcodeCache method
$handler = Mockery::mock(OnWorkerStart::class, [
Expand All @@ -41,7 +42,6 @@ public function test_should_clear_opcache_returns_configured_value(): void

$reflection = new \ReflectionClass($handler);
$method = $reflection->getMethod('shouldClearOpcodeCache');
$method->setAccessible(true);

$this->assertFalse($method->invoke($handler));
}
Expand Down
10 changes: 5 additions & 5 deletions tests/RoadRunnerClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function test_marshal_request_method_marshals_proper_illuminate_request()
$this->assertEquals('Taylor', $request->query('name'));
}

/** @doesNotPerformAssertions @test */
/** @test */
public function test_respond_method_send_response_to_roadrunner()
{
$client = new RoadRunnerClient($psr7Client = Mockery::mock(PSR7Worker::class));
Expand All @@ -49,7 +49,7 @@ public function test_respond_method_send_response_to_roadrunner()
]), new OctaneResponse(new Response('Hello World', 200)));
}

/** @doesNotPerformAssertions @test */
/** @test */
public function test_respond_method_send_streamed_response_to_roadrunner()
{
$client = new RoadRunnerClient($psr7Client = Mockery::mock(PSR7Worker::class));
Expand All @@ -66,7 +66,7 @@ public function test_respond_method_send_streamed_response_to_roadrunner()
}, 200)));
}

/** @doesNotPerformAssertions @test */
/** @test */
public function test_respond_method_send_streamed_generator_response_to_roadrunner()
{
$client = new RoadRunnerClient($psr7Client = Mockery::mock(PSR7Worker::class));
Expand All @@ -92,7 +92,7 @@ public function test_respond_method_send_streamed_generator_response_to_roadrunn
]), new OctaneResponse(new StreamedResponse($responseCallback, 200)));
}

/** @doesNotPerformAssertions @test */
/** @test */
public function test_error_method_sends_error_response_to_roadrunner()
{
$psr7Client = Mockery::mock(PSR7Worker::class);
Expand All @@ -108,7 +108,7 @@ public function test_error_method_sends_error_response_to_roadrunner()
$client->error(new Exception('Something went wrong...'), $app, $request, $context);
}

/** @doesNotPerformAssertions @test */
/** @test */
public function test_error_method_sends_detailed_error_response_to_roadrunner_in_debug_mode()
{
$e = new Exception('Something went wrong...');
Expand Down
2 changes: 1 addition & 1 deletion tests/RoadRunnerServerProcessInspectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function test_can_determine_if_roadrunner_server_process_is_running_when_
$processIdFile->delete();
}

/** @doesNotPerformAssertions @test */
/** @test */
public function test_roadrunner_server_process_can_be_reloaded()
{
$this->createApplication();
Expand Down
20 changes: 10 additions & 10 deletions tests/SwooleClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function test_cant_serve_static_files_if_file_has_forbidden_extension():
$this->assertFalse($client->canServeRequestAsStaticFile($request, $context));
}

/** @doesNotPerformAssertions @test */
/** @test */
public function test_static_file_can_be_served(): void
{
$client = new SwooleClient;
Expand All @@ -153,7 +153,7 @@ public function test_static_file_can_be_served(): void
$client->serveStaticFile($request, $context);
}

/** @doesNotPerformAssertions @test */
/** @test */
public function test_static_file_headers_can_be_sent(): void
{
$this->createApplication();
Expand Down Expand Up @@ -209,7 +209,7 @@ public function test_cant_serve_static_files_through_symlink_using_directory_tra
$this->assertFalse($client->canServeRequestAsStaticFile($request, $context));
}

/** @doesNotPerformAssertions @test */
/** @test */
public function test_respond_method_sends_response_to_swoole(): void
{
$this->createApplication();
Expand Down Expand Up @@ -241,7 +241,7 @@ public function test_respond_method_sends_response_to_swoole(): void
]), new OctaneResponse($response));
}

/** @doesNotPerformAssertions @test */
/** @test */
public function test_respond_method_send_streamed_response_to_swoole(): void
{
$this->createApplication();
Expand All @@ -263,7 +263,7 @@ public function test_respond_method_send_streamed_response_to_swoole(): void
}, 200, ['Content-Type' => 'text/html'])));
}

/** @doesNotPerformAssertions @test */
/** @test */
public function test_respond_method_with_laravel_specific_status_code_sends_response_to_swoole(): void
{
$this->createApplication();
Expand All @@ -283,7 +283,7 @@ public function test_respond_method_with_laravel_specific_status_code_sends_resp
]), new OctaneResponse(new Response('Hello World', 419, ['Content-Type' => 'text/html'])));
}

/** @doesNotPerformAssertions @test */
/** @test */
public function test_error_method_sends_error_response_to_swoole(): void
{
$client = new SwooleClient;
Expand All @@ -303,7 +303,7 @@ public function test_error_method_sends_error_response_to_swoole(): void
$swooleResponse->shouldHaveReceived('end')->with('Internal server error.');
}

/** @doesNotPerformAssertions @test */
/** @test */
public function test_error_method_sends_detailed_error_response_to_swoole_in_debug_mode(): void
{
$client = new SwooleClient;
Expand All @@ -323,7 +323,7 @@ public function test_error_method_sends_detailed_error_response_to_swoole_in_deb
$swooleResponse->shouldHaveReceived('end')->with((string) $e);
}

/** @doesNotPerformAssertions @test */
/** @test */
public function test_respond_method_send_not_chunked_response_to_swoole(): void
{
$this->createApplication();
Expand All @@ -345,7 +345,7 @@ public function test_respond_method_send_not_chunked_response_to_swoole(): void
]), new OctaneResponse($response));
}

/** @doesNotPerformAssertions @test */
/** @test */
public function test_respond_method_send_chunked_response_to_swoole(): void
{
$this->createApplication();
Expand All @@ -368,7 +368,7 @@ public function test_respond_method_send_chunked_response_to_swoole(): void
]), new OctaneResponse($response));
}

/** @doesNotPerformAssertions @test */
/** @test */
public function test_respond_method_preserves_header_formatting_if_configured(): void
{
$this->createApplication();
Expand Down
25 changes: 8 additions & 17 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
namespace Laravel\Octane\Tests;

use Carbon\Laravel\ServiceProvider as CarbonServiceProvider;
use Illuminate\Container\Container;
use Illuminate\Foundation\Bootstrap\HandleExceptions;
use Illuminate\Support\Facades\Facade;
use Laravel\Octane\ApplicationFactory;
use Laravel\Octane\Contracts\Client;
use Laravel\Octane\Octane;
Expand All @@ -14,14 +11,17 @@
use Laravel\Octane\Testing\Fakes\FakeClient;
use Laravel\Octane\Testing\Fakes\FakeWorker;
use Mockery;
use Orchestra\Testbench\Concerns\InteractsWithMockery;
use Orchestra\Testbench\Foundation\Application as Testbench;
use PHPUnit\Framework\TestCase as BaseTestCase;
use Swoole\Table;

use function Orchestra\Testbench\default_skeleton_path;
use function Orchestra\Testbench\laravel_version_compare;

class TestCase extends BaseTestCase
{
use InteractsWithMockery;

protected function createOctaneContext(array $requests)
{
$appFactory = Mockery::mock(ApplicationFactory::class);
Expand Down Expand Up @@ -66,7 +66,7 @@ protected function createSwooleTable()

protected function appFactory()
{
return new ApplicationFactory(realpath(__DIR__.'/../vendor/orchestra/testbench-core/laravel'));
return new ApplicationFactory(default_skeleton_path());
}

protected function config()
Expand All @@ -76,19 +76,10 @@ protected function config()

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

if (laravel_version_compare('11.0', '>=')) {
HandleExceptions::flushState();
} else {
HandleExceptions::forgetApp();
}
Testbench::flushState($this);

Container::setInstance(null);
$this->tearDownTheTestEnvironmentUsingMockery();

Facade::clearResolvedInstances();
Facade::setFacadeApplication(null);

Mockery::close();
parent::tearDown();
}
}
Loading