diff --git a/.gitignore b/.gitignore index ce9611b6a..fa20a93b8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,4 @@ composer.lock /phpunit.xml .phpunit.result.cache !tests/Foundation/fixtures/hyperf1/composer.lock -tests/Foundation/fixtures/hyperf/runtime tests/Http/fixtures \ No newline at end of file diff --git a/composer.json b/composer.json index 656c8aaa4..b76b7f799 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,7 @@ "autoload": { "psr-4": { "Illuminate\\Events\\": "src/event/illuminate/", + "Workbench\\App\\": "src/testbench/workbench/app/", "Hypervel\\": "src/core/src/", "Hypervel\\Auth\\": "src/auth/src/", "Hypervel\\Broadcasting\\": "src/broadcasting/src/", @@ -54,7 +55,8 @@ "Hypervel\\Router\\": "src/router/src/", "Hypervel\\Session\\": "src/session/src/", "Hypervel\\Support\\": "src/support/src/", - "Hypervel\\Telescope\\": "src/telescope/src/" + "Hypervel\\Telescope\\": "src/telescope/src/", + "Hypervel\\Testbench\\": "src/testbench/src/" }, "files": [ "src/auth/src/Functions.php", @@ -152,7 +154,8 @@ "hypervel/router": "self.version", "hypervel/session": "self.version", "hypervel/support": "self.version", - "hypervel/telescope": "self.version" + "hypervel/telescope": "self.version", + "hypervel/testbench": "self.version" }, "suggest": { "hyperf/redis": "Required to use redis driver. (^3.1).", @@ -186,7 +189,8 @@ "phpstan/phpstan": "^1.11.5", "phpunit/phpunit": "10.5.45", "pusher/pusher-php-server": "^7.2", - "swoole/ide-helper": "~5.1.0" + "swoole/ide-helper": "~5.1.0", + "symfony/yaml": "^7.3" }, "config": { "sort-packages": true diff --git a/src/container/src/ScanConfig.php b/src/container/src/ScanConfig.php new file mode 100644 index 000000000..fc9d2d592 --- /dev/null +++ b/src/container/src/ScanConfig.php @@ -0,0 +1,66 @@ + $value) { + if (! isset($config[$key])) { + $config[$key] = []; + } + if (! is_array($value)) { + $value = [$value]; + } + $config[$key] = array_merge($config[$key], $value); + } + + return $config; + } +} diff --git a/src/filesystem/src/Filesystem.php b/src/filesystem/src/Filesystem.php index 08fdfa464..f078128ee 100644 --- a/src/filesystem/src/Filesystem.php +++ b/src/filesystem/src/Filesystem.php @@ -8,4 +8,13 @@ class Filesystem extends HyperfFilesystem { + /** + * Ensure a directory exists. + */ + public function ensureDirectoryExists(string $path, int $mode = 0755, bool $recursive = true): void + { + if (! $this->isDirectory($path)) { + $this->makeDirectory($path, $mode, $recursive); + } + } } diff --git a/src/foundation/src/ClassLoader.php b/src/foundation/src/ClassLoader.php index 2295c9586..d3289fac1 100644 --- a/src/foundation/src/ClassLoader.php +++ b/src/foundation/src/ClassLoader.php @@ -4,12 +4,12 @@ namespace Hypervel\Foundation; -use Hyperf\Di\Annotation\ScanConfig; use Hyperf\Di\Annotation\Scanner as AnnotationScanner; use Hyperf\Di\LazyLoader\LazyLoader; use Hyperf\Di\ScanHandler\PcntlScanHandler; use Hyperf\Di\ScanHandler\ScanHandlerInterface; use Hyperf\Support\DotenvManager; +use Hypervel\Container\ScanConfig; use Hypervel\Support\Composer; class ClassLoader diff --git a/src/foundation/src/Providers/FoundationServiceProvider.php b/src/foundation/src/Providers/FoundationServiceProvider.php index fa3809c1f..33e1fa084 100644 --- a/src/foundation/src/Providers/FoundationServiceProvider.php +++ b/src/foundation/src/Providers/FoundationServiceProvider.php @@ -97,7 +97,6 @@ protected function overrideHyperfConfigs(): void $configs = [ 'app_name' => $this->config->get('app.name'), 'app_env' => $this->config->get('app.env'), - 'scan_cacheable' => $this->config->get('app.scan_cacheable'), StdoutLoggerInterface::class . '.log_level' => $this->config->get('app.stdout_log_level'), 'translation.locale' => $this->config->get('app.locale'), 'translation.fallback_locale' => $this->config->get('app.fallback_locale'), diff --git a/src/foundation/src/Testing/Traits/CanConfigureMigrationCommands.php b/src/foundation/src/Testing/Traits/CanConfigureMigrationCommands.php index 602445e7c..3d7561f86 100644 --- a/src/foundation/src/Testing/Traits/CanConfigureMigrationCommands.php +++ b/src/foundation/src/Testing/Traits/CanConfigureMigrationCommands.php @@ -10,10 +10,8 @@ trait CanConfigureMigrationCommands { /** * The parameters that should be used when running "migrate:fresh". - * - * @return array */ - protected function migrateFreshUsing() + protected function migrateFreshUsing(): array { $seeder = $this->seeder(); $connection = $this->app @@ -31,30 +29,24 @@ protected function migrateFreshUsing() /** * Determine if views should be dropped when refreshing the database. - * - * @return bool */ - protected function shouldDropViews() + protected function shouldDropViews(): bool { return property_exists($this, 'dropViews') ? $this->dropViews : false; } /** * Determine if the seed task should be run when refreshing the database. - * - * @return bool */ - protected function shouldSeed() + protected function shouldSeed(): bool { return property_exists($this, 'seed') ? $this->seed : false; } /** * Determine the specific seeder class that should be used when refreshing the database. - * - * @return mixed */ - protected function seeder() + protected function seeder(): mixed { return property_exists($this, 'seeder') ? $this->seeder : false; } diff --git a/src/testbench/.gitignore b/src/testbench/.gitignore new file mode 100644 index 000000000..922a9a962 --- /dev/null +++ b/src/testbench/.gitignore @@ -0,0 +1,3 @@ +workbench/.env +workbench/composer.lock +workbench/runtime \ No newline at end of file diff --git a/src/testbench/bin/testbench-sync b/src/testbench/bin/testbench-sync new file mode 100755 index 000000000..e7cc161e7 --- /dev/null +++ b/src/testbench/bin/testbench-sync @@ -0,0 +1,33 @@ +#!/usr/bin/env php +copy("{$workingPath}/vendor/hypervel/testbench/testbench.yaml", "{$workingPath}/testbench.yaml"); + +Hypervel\Support\Collection::make([ + ...$files->allFiles("{$workingPath}/vendor/hypervel/testbench/workbench/app/"), +])->flatten() +->filter(static fn ($file) => is_file($file)) +->each(static function ($file) use ($files, $workingPath) { + $filename = $workingPath . Hypervel\Support\Str::after((string) $file, "{$workingPath}/vendor/hypervel/testbench/workbench"); + $files->ensureDirectoryExists(Hypervel\Support\Str::before($filename, basename($filename))); + $files->copy($file, $filename); +}); + +Hypervel\Support\Collection::make([ + ...$files->allFiles("{$workingPath}/vendor/hypervel/testbench/workbench/config/"), + ...$files->allFiles("{$workingPath}/vendor/hypervel/testbench/workbench/database/"), + ...$files->allFiles("{$workingPath}/vendor/hypervel/testbench/workbench/lang/"), + ...$files->allFiles("{$workingPath}/vendor/hypervel/testbench/workbench/routes/"), + ...$files->allFiles("{$workingPath}/vendor/hypervel/testbench/workbench/resources/"), +])->flatten() +->filter(static fn ($file) => is_file($file)) +->each(static function ($file) use ($files, $workingPath) { + $filename = $workingPath . Hypervel\Support\Str::after((string) $file, "{$workingPath}/vendor/hypervel/testbench/workbench"); + $files->ensureDirectoryExists(Hypervel\Support\Str::before($filename, basename($filename))); + $files->copy($file, $filename); +}); diff --git a/src/testbench/composer.json b/src/testbench/composer.json new file mode 100644 index 000000000..ccc9c1dcf --- /dev/null +++ b/src/testbench/composer.json @@ -0,0 +1,51 @@ +{ + "name": "hypervel/testbench", + "description": "The testbench package for Hypervel.", + "license": "MIT", + "keywords": [ + "php", + "hyperf", + "testbench", + "swoole", + "hypervel" + ], + "support": { + "issues": "https://github.com/hypervel/components/issues", + "source": "https://github.com/hypervel/components" + }, + "authors": [ + { + "name": "Albert Chen", + "email": "albert@hypervel.org" + } + ], + "require": { + "php": "^8.2", + "hypervel/framework": "^0.1", + "mockery/mockery": "^1.6.10", + "phpunit/phpunit": "^10.0.7", + "symfony/yaml": "^7.3", + "vlucas/phpdotenv": "^5.6.1" + }, + "autoload": { + "psr-4": { + "Hypervel\\Testbench\\": "src/", + "Workbench\\App\\": "workbench/app/" + } + }, + "extra": { + "branch-alias": { + "dev-main": "0.1-dev" + } + }, + "config": { + "sort-packages": true + }, + "bin": [ + "bin/testbench-sync" + ], + "scripts": { + "sync": "@php bin/testbench-sync" + }, + "minimum-stability": "dev" +} \ No newline at end of file diff --git a/src/testbench/src/Bootstrapper.php b/src/testbench/src/Bootstrapper.php new file mode 100644 index 000000000..2a0241679 --- /dev/null +++ b/src/testbench/src/Bootstrapper.php @@ -0,0 +1,146 @@ + [ + [ + 'name' => 'hypervel-testbench', + 'extra' => [ + 'hypervel' => [ + 'config' => static::getConfigProviders(), + 'providers' => static::$config['providers'] ?? [], + 'dont-discover' => static::$config['dont-discover'] ?? [], + ], + ], + ], + ], + 'packages-dev' => [], + ]; + + static::getFilesystem()->replace( + BASE_PATH . '/composer.lock', + json_encode($content, JSON_PRETTY_PRINT) + ); + } + + protected static function loadConfigFromYaml(string $workingPath, ?string $filename = 'testbench.yaml', array $defaults = []): void + { + $filename = LazyCollection::make(static function () use ($filename) { + yield $filename; + yield "{$filename}.example"; + yield "{$filename}.dist"; + })->map(static function ($file) use ($workingPath) { + return str_contains($file, DIRECTORY_SEPARATOR) ? $file : join_paths($workingPath, $file); + })->filter(static fn ($file) => is_file($file)) + ->first(); + + if (is_null($filename)) { + return; + } + + static::$config = Yaml::parseFile($filename) ?? []; + } + + protected static function generateEnv(): void + { + if (! $env = static::$config['env'] ?? []) { + return; + } + + static::getFilesystem()->replace( + join_paths(BASE_PATH, '/.env'), + implode(PHP_EOL, $env) + ); + } + + protected static function getConfigProviders(): array + { + ConfigProviderRegister::add( + static::$config['config-providers'] ?? [] + ); + + return ConfigProviderRegister::get(); + } + + protected static function registerPurgeFiles(): void + { + $purge = static::$config['purge'] ?? []; + $files = $purge['files'] ?? []; + $directories = $purge['directories'] ?? []; + + if (! $files && ! $directories) { + return; + } + + register_shutdown_function(function () use ($files, $directories) { + $filesystem = static::getFilesystem(); + foreach ($files as $file) { + if (! $filesystem->exists($file = BASE_PATH . "/{$file}")) { + continue; + } + $filesystem->delete($file); + } + + foreach ($directories as $directory) { + if (! $filesystem->exists($directory = BASE_PATH . "/{$directory}")) { + continue; + } + $filesystem->deleteDirectory($directory); + } + }); + } +} diff --git a/tests/Foundation/Testing/BootstrapConfigProvider.php b/src/testbench/src/ConfigProviderRegister.php similarity index 74% rename from tests/Foundation/Testing/BootstrapConfigProvider.php rename to src/testbench/src/ConfigProviderRegister.php index aa028e5e4..969eda712 100644 --- a/tests/Foundation/Testing/BootstrapConfigProvider.php +++ b/src/testbench/src/ConfigProviderRegister.php @@ -2,9 +2,11 @@ declare(strict_types=1); -namespace Hypervel\Tests\Foundation\Testing; +namespace Hypervel\Testbench; -class BootstrapConfigProvider +use Hyperf\Collection\Arr; + +class ConfigProviderRegister { protected static $configProviders = [ \Hyperf\Command\ConfigProvider::class, @@ -55,9 +57,30 @@ class BootstrapConfigProvider public static function get(): array { if (class_exists($devtoolClass = \Hyperf\Devtool\ConfigProvider::class)) { - return array_merge(self::$configProviders, [$devtoolClass]); + return array_merge(static::$configProviders, [$devtoolClass]); } - return self::$configProviders; + return static::$configProviders; + } + + public static function filter(callable $callback): array + { + return static::$configProviders = array_filter(static::get(), $callback); + } + + public static function add(array|string $providers): void + { + static::$configProviders = array_merge( + static::$configProviders, + Arr::wrap($providers) + ); + } + + public static function except(array|string $providers): void + { + static::$configProviders = array_diff( + static::$configProviders, + Arr::wrap($providers) + ); } } diff --git a/src/testbench/src/TestCase.php b/src/testbench/src/TestCase.php new file mode 100644 index 000000000..c9066a438 --- /dev/null +++ b/src/testbench/src/TestCase.php @@ -0,0 +1,49 @@ +afterApplicationCreated(function () { + Timer::clearAll(); + CoordinatorManager::until(Constants::WORKER_EXIT)->resume(); + }); + + parent::setUp(); + } + + protected function createApplication(): ApplicationContract + { + $app = new Application(); + $app->define(KernelContract::class, ConsoleKernel::class); + + ApplicationContext::setContainer($app); + + return $app; + } +} diff --git a/src/testbench/testbench.yaml b/src/testbench/testbench.yaml new file mode 100644 index 000000000..50d6cfbb8 --- /dev/null +++ b/src/testbench/testbench.yaml @@ -0,0 +1,19 @@ +providers: + - Workbench\App\Providers\WorkbenchServiceProvider + +env: + - APP_NAME="Hypervel Testbench" + +workbench: + discovers: + web: false + api: false + commands: false + +purge: + files: + - .env + - composer.lock + directories: + - runtime + - public/vendor \ No newline at end of file diff --git a/src/testbench/workbench/app/Console/Commands/DummyCommand.php b/src/testbench/workbench/app/Console/Commands/DummyCommand.php new file mode 100644 index 000000000..ab7005d58 --- /dev/null +++ b/src/testbench/workbench/app/Console/Commands/DummyCommand.php @@ -0,0 +1,21 @@ +info('It works!'); + + return 0; + } +} diff --git a/tests/Foundation/Testing/ExceptionHandler.php b/src/testbench/workbench/app/Exceptions/ExceptionHandler.php similarity index 94% rename from tests/Foundation/Testing/ExceptionHandler.php rename to src/testbench/workbench/app/Exceptions/ExceptionHandler.php index acd62fc09..80fcf6689 100644 --- a/tests/Foundation/Testing/ExceptionHandler.php +++ b/src/testbench/workbench/app/Exceptions/ExceptionHandler.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Hypervel\Tests\Foundation\Testing; +namespace Workbench\App\Exceptions; use Hypervel\Foundation\Exceptions\Handler as BaseExceptionHandler; use Hypervel\Http\Request; diff --git a/src/testbench/workbench/app/Http/Controllers/ExampleController.php b/src/testbench/workbench/app/Http/Controllers/ExampleController.php new file mode 100644 index 000000000..998f3fbc6 --- /dev/null +++ b/src/testbench/workbench/app/Http/Controllers/ExampleController.php @@ -0,0 +1,13 @@ +app->get(RouteFileCollector::class) + ->addRouteFile(dirname(__DIR__, 2) . '/routes/web.php'); + } + + if ($config['api'] ?? false) { + $this->app->get(RouteFileCollector::class) + ->addRouteFile(dirname(__DIR__, 2) . '/routes/api.php'); + } + + if ($config['commands'] ?? false) { + require dirname(__DIR__, 2) . '/routes/console.php'; + } + } +} diff --git a/tests/Foundation/fixtures/hyperf/config/app.php b/src/testbench/workbench/config/app.php similarity index 98% rename from tests/Foundation/fixtures/hyperf/config/app.php rename to src/testbench/workbench/config/app.php index 20ea295f7..2523eb41d 100644 --- a/tests/Foundation/fixtures/hyperf/config/app.php +++ b/src/testbench/workbench/config/app.php @@ -29,7 +29,7 @@ | */ - 'env' => app()->environment(), + 'env' => env('APP_ENV', 'dev'), /* |-------------------------------------------------------------------------- @@ -43,7 +43,7 @@ | */ - 'debug' => app()->hasDebugModeEnabled(), + 'debug' => env('APP_DEBUG', true), /* |-------------------------------------------------------------------------- diff --git a/tests/Foundation/fixtures/hyperf/config/auth.php b/src/testbench/workbench/config/auth.php similarity index 100% rename from tests/Foundation/fixtures/hyperf/config/auth.php rename to src/testbench/workbench/config/auth.php diff --git a/tests/Foundation/fixtures/hyperf/config/database.php b/src/testbench/workbench/config/database.php similarity index 100% rename from tests/Foundation/fixtures/hyperf/config/database.php rename to src/testbench/workbench/config/database.php diff --git a/tests/Foundation/fixtures/hyperf/config/exceptions.php b/src/testbench/workbench/config/exceptions.php similarity index 58% rename from tests/Foundation/fixtures/hyperf/config/exceptions.php rename to src/testbench/workbench/config/exceptions.php index 8482cf0ce..91a10d2f8 100644 --- a/tests/Foundation/fixtures/hyperf/config/exceptions.php +++ b/src/testbench/workbench/config/exceptions.php @@ -5,7 +5,7 @@ return [ 'handler' => [ 'http' => [ - Hypervel\Tests\Foundation\Testing\ExceptionHandler::class, + Workbench\App\Exceptions\ExceptionHandler::class, ], ], ]; diff --git a/tests/Foundation/fixtures/hyperf/config/logging.php b/src/testbench/workbench/config/logging.php similarity index 100% rename from tests/Foundation/fixtures/hyperf/config/logging.php rename to src/testbench/workbench/config/logging.php diff --git a/tests/Foundation/fixtures/hyperf/config/queue.php b/src/testbench/workbench/config/queue.php similarity index 100% rename from tests/Foundation/fixtures/hyperf/config/queue.php rename to src/testbench/workbench/config/queue.php diff --git a/tests/Foundation/fixtures/hyperf/config/session.php b/src/testbench/workbench/config/session.php similarity index 100% rename from tests/Foundation/fixtures/hyperf/config/session.php rename to src/testbench/workbench/config/session.php diff --git a/tests/Foundation/fixtures/hyperf/database/factories/UserFactory.php b/src/testbench/workbench/database/factories/UserFactory.php similarity index 93% rename from tests/Foundation/fixtures/hyperf/database/factories/UserFactory.php rename to src/testbench/workbench/database/factories/UserFactory.php index 48cb411c6..92bd016de 100644 --- a/tests/Foundation/fixtures/hyperf/database/factories/UserFactory.php +++ b/src/testbench/workbench/database/factories/UserFactory.php @@ -6,6 +6,7 @@ use Faker\Generator as Faker; use Hypervel\Tests\Foundation\Testing\Concerns\User; +/* @phpstan-ignore-next-line */ $factory->define(User::class, function (Faker $faker) { return [ 'name' => $faker->unique()->name(), diff --git a/tests/Foundation/fixtures/hyperf/database/migrations/2023_08_03_000000_create_users_table.php b/src/testbench/workbench/database/migrations/2023_08_03_000000_create_users_table.php similarity index 100% rename from tests/Foundation/fixtures/hyperf/database/migrations/2023_08_03_000000_create_users_table.php rename to src/testbench/workbench/database/migrations/2023_08_03_000000_create_users_table.php diff --git a/src/testbench/workbench/lang/en/welcome.php b/src/testbench/workbench/lang/en/welcome.php new file mode 100644 index 000000000..ad4774fdb --- /dev/null +++ b/src/testbench/workbench/lang/en/welcome.php @@ -0,0 +1,7 @@ + 'Good Morning', +]; diff --git a/src/testbench/workbench/resources/views/welcome.blade.php b/src/testbench/workbench/resources/views/welcome.blade.php new file mode 100644 index 000000000..7202418fe --- /dev/null +++ b/src/testbench/workbench/resources/views/welcome.blade.php @@ -0,0 +1 @@ +Hello Hypervel! \ No newline at end of file diff --git a/src/testbench/workbench/routes/api.php b/src/testbench/workbench/routes/api.php new file mode 100644 index 000000000..ef8c18e72 --- /dev/null +++ b/src/testbench/workbench/routes/api.php @@ -0,0 +1,22 @@ + 'Hello, world!']; +}); + +Route::get('api/failed', fn () => throw new RuntimeException('Bad route!')); diff --git a/src/testbench/workbench/routes/console.php b/src/testbench/workbench/routes/console.php new file mode 100644 index 000000000..70875dc87 --- /dev/null +++ b/src/testbench/workbench/routes/console.php @@ -0,0 +1,21 @@ +comment('What is essential is invisible to the eye.'); +})->purpose('Display an inspiring quote'); diff --git a/src/testbench/workbench/routes/web.php b/src/testbench/workbench/routes/web.php new file mode 100644 index 000000000..58b9cb146 --- /dev/null +++ b/src/testbench/workbench/routes/web.php @@ -0,0 +1,20 @@ + throw new RuntimeException('Bad route!')); + +Route::get('/', fn () => view('welcome'), ['name' => 'welcome']); diff --git a/tests/Bus/BusBatchTest.php b/tests/Bus/BusBatchTest.php index b765cc5be..c4aa4803e 100644 --- a/tests/Bus/BusBatchTest.php +++ b/tests/Bus/BusBatchTest.php @@ -21,7 +21,7 @@ use Hypervel\Queue\Contracts\Factory; use Hypervel\Queue\Contracts\Queue; use Hypervel\Queue\Contracts\ShouldQueue; -use Hypervel\Tests\Foundation\Testing\ApplicationTestCase; +use Hypervel\Testbench\TestCase; use Mockery as m; use PHPUnit\Framework\Attributes\DataProvider; use RuntimeException; @@ -30,7 +30,7 @@ * @internal * @coversNothing */ -class BusBatchTest extends ApplicationTestCase +class BusBatchTest extends TestCase { use RefreshDatabase; diff --git a/tests/Console/ArtisanCommandTest.php b/tests/Console/ArtisanCommandTest.php index 3e9c0b3ef..9f7341576 100644 --- a/tests/Console/ArtisanCommandTest.php +++ b/tests/Console/ArtisanCommandTest.php @@ -5,7 +5,7 @@ namespace Hypervel\Tests\Console\Testing; use Hypervel\Support\Facades\Artisan; -use Hypervel\Tests\Foundation\Testing\ApplicationTestCase; +use Hypervel\Testbench\TestCase; use Mockery as m; use Mockery\Exception\InvalidCountException; use Mockery\Exception\InvalidOrderException; @@ -15,7 +15,7 @@ * @internal * @coversNothing */ -class ArtisanCommandTest extends ApplicationTestCase +class ArtisanCommandTest extends TestCase { public function testConsoleCommandPasses() { diff --git a/tests/Core/EloquentBroadcastingTest.php b/tests/Core/EloquentBroadcastingTest.php index d4352b1e3..ff5dcd85a 100644 --- a/tests/Core/EloquentBroadcastingTest.php +++ b/tests/Core/EloquentBroadcastingTest.php @@ -18,14 +18,14 @@ use Hypervel\Foundation\Testing\RefreshDatabase; use Hypervel\Support\Facades\Event; use Hypervel\Support\Facades\Schema; -use Hypervel\Tests\Foundation\Testing\ApplicationTestCase; +use Hypervel\Testbench\TestCase; use Mockery; /** * @internal * @coversNothing */ -class EloquentBroadcastingTest extends ApplicationTestCase +class EloquentBroadcastingTest extends TestCase { use RefreshDatabase; diff --git a/tests/Foundation/Testing/ApplicationTestCase.php b/tests/Foundation/Testing/ApplicationTestCase.php deleted file mode 100644 index f2b02d8ef..000000000 --- a/tests/Foundation/Testing/ApplicationTestCase.php +++ /dev/null @@ -1,84 +0,0 @@ -bootstrapApplication(); - static::$hasBootstrappedApplication = true; - } - - $this->afterApplicationCreated(function () { - Timer::clearAll(); - CoordinatorManager::until(Constants::WORKER_EXIT)->resume(); - }); - - parent::setUp(); - } - - protected function bootstrapApplication(): void - { - ! defined('BASE_PATH') && define('BASE_PATH', dirname(__DIR__, 3) . '/tests/Foundation/fixtures/hyperf'); - ! defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', SWOOLE_HOOK_ALL); - - $this->generateComposerLock(); - - ClassLoader::init(null, null, new TestScanHandler()); - } - - protected function createApplication(): ApplicationContract - { - $app = new Application(); - $app->define(KernelContract::class, ConsoleKernel::class); - - ApplicationContext::setContainer($app); - - return $app; - } - - protected function generateComposerLock(): void - { - $content = [ - 'packages' => [ - [ - 'name' => 'hypervel-testing', - 'extra' => [ - 'hyperf' => [ - 'config' => BootstrapConfigProvider::get(), - ], - ], - ], - ], - 'packages-dev' => [], - ]; - - (new Filesystem())->replace( - BASE_PATH . '/composer.lock', - json_encode($content, JSON_PRETTY_PRINT) - ); - } -} diff --git a/tests/Foundation/Testing/BootTraitsTest.php b/tests/Foundation/Testing/BootTraitsTest.php index 511c5d73d..f35aacd82 100644 --- a/tests/Foundation/Testing/BootTraitsTest.php +++ b/tests/Foundation/Testing/BootTraitsTest.php @@ -4,6 +4,7 @@ namespace Hypervel\Tests\Foundation\Testing; +use Hypervel\Testbench\TestCase as TestbenchTestCase; use Hypervel\Tests\TestCase; use ReflectionMethod; @@ -35,7 +36,7 @@ public function testSetUpTraits() * @internal * @coversNothing */ -class TestCaseWithTrait extends ApplicationTestCase +class TestCaseWithTrait extends TestbenchTestCase { use TestTrait; } diff --git a/tests/Foundation/Testing/Concerns/InteractsWithAuthenticationTest.php b/tests/Foundation/Testing/Concerns/InteractsWithAuthenticationTest.php index e201551aa..9a4d18ebb 100644 --- a/tests/Foundation/Testing/Concerns/InteractsWithAuthenticationTest.php +++ b/tests/Foundation/Testing/Concerns/InteractsWithAuthenticationTest.php @@ -10,14 +10,14 @@ use Hypervel\Auth\Contracts\FactoryContract as AuthManagerContract; use Hypervel\Auth\Contracts\Guard; use Hypervel\Foundation\Testing\Concerns\InteractsWithAuthentication; -use Hypervel\Tests\Foundation\Testing\ApplicationTestCase; +use Hypervel\Testbench\TestCase; use Mockery; /** * @internal * @coversNothing */ -class InteractsWithAuthenticationTest extends ApplicationTestCase +class InteractsWithAuthenticationTest extends TestCase { use InteractsWithAuthentication; diff --git a/tests/Foundation/Testing/Concerns/InteractsWithContainerTest.php b/tests/Foundation/Testing/Concerns/InteractsWithContainerTest.php index 865813e16..5e787ac9c 100644 --- a/tests/Foundation/Testing/Concerns/InteractsWithContainerTest.php +++ b/tests/Foundation/Testing/Concerns/InteractsWithContainerTest.php @@ -4,7 +4,7 @@ namespace Hypervel\Tests\Foundation\Testing\Concerns; -use Hypervel\Tests\Foundation\Testing\ApplicationTestCase; +use Hypervel\Testbench\TestCase; use Mockery as m; use Mockery\MockInterface; @@ -12,7 +12,7 @@ * @internal * @coversNothing */ -class InteractsWithContainerTest extends ApplicationTestCase +class InteractsWithContainerTest extends TestCase { public function testSwap() { diff --git a/tests/Foundation/Testing/Concerns/InteractsWithDatabaseTest.php b/tests/Foundation/Testing/Concerns/InteractsWithDatabaseTest.php index 6d36c4e67..a70f16152 100644 --- a/tests/Foundation/Testing/Concerns/InteractsWithDatabaseTest.php +++ b/tests/Foundation/Testing/Concerns/InteractsWithDatabaseTest.php @@ -7,13 +7,13 @@ use Hyperf\Database\Model\Factory; use Hypervel\Database\Eloquent\Model; use Hypervel\Foundation\Testing\RefreshDatabase; -use Hypervel\Tests\Foundation\Testing\ApplicationTestCase; +use Hypervel\Testbench\TestCase; /** * @internal * @coversNothing */ -class InteractsWithDatabaseTest extends ApplicationTestCase +class InteractsWithDatabaseTest extends TestCase { use RefreshDatabase; diff --git a/tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php b/tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php index f9d85a1f5..520caee22 100644 --- a/tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php +++ b/tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php @@ -14,14 +14,14 @@ use Hypervel\Router\RouteFileCollector; use Hypervel\Session\ArraySessionHandler; use Hypervel\Session\Store; -use Hypervel\Tests\Foundation\Testing\ApplicationTestCase; +use Hypervel\Testbench\TestCase; use PHPUnit\Framework\AssertionFailedError; /** * @internal * @coversNothing */ -class MakesHttpRequestsTest extends ApplicationTestCase +class MakesHttpRequestsTest extends TestCase { use RunTestsInCoroutine; @@ -121,7 +121,7 @@ public function testWithCookiesSetsCookiesAndOverwritesPreviousValues() public function testFollowingRedirects() { $this->app->get(RouteFileCollector::class) - ->addRouteFile(BASE_PATH . '/routes/test-api.php'); + ->addRouteFile(dirname(__DIR__, 2) . '/fixtures/routes/test-api.php'); $response = (new ServerResponse()) ->withStatus(301) @@ -141,7 +141,7 @@ public function testGetNotFound() public function testGetFoundRoute() { $this->app->get(RouteFileCollector::class) - ->addRouteFile(BASE_PATH . '/routes/test-api.php'); + ->addRouteFile(dirname(__DIR__, 2) . '/fixtures/routes/test-api.php'); $this->get('/foo') ->assertSuccessFul() @@ -151,7 +151,7 @@ public function testGetFoundRoute() public function testGetFoundRouteWithTrailingSlash() { $this->app->get(RouteFileCollector::class) - ->addRouteFile(BASE_PATH . '/routes/test-api.php'); + ->addRouteFile(dirname(__DIR__, 2) . '/fixtures/routes/test-api.php'); $this->get('/foo/') ->assertSuccessFul() @@ -161,7 +161,7 @@ public function testGetFoundRouteWithTrailingSlash() public function testGetServerParams() { $this->app->get(RouteFileCollector::class) - ->addRouteFile(BASE_PATH . '/routes/test-api.php'); + ->addRouteFile(dirname(__DIR__, 2) . '/fixtures/routes/test-api.php'); $this->get('/server-params?foo=bar') ->assertSuccessful() @@ -175,7 +175,7 @@ public function testGetServerParams() public function testGetStreamedContent() { $this->app->get(RouteFileCollector::class) - ->addRouteFile(BASE_PATH . '/routes/test-api.php'); + ->addRouteFile(dirname(__DIR__, 2) . '/fixtures/routes/test-api.php'); $this->get('/stream') ->assertSuccessFul() @@ -185,7 +185,7 @@ public function testGetStreamedContent() public function testWithHeaders() { $this->app->get(RouteFileCollector::class) - ->addRouteFile(BASE_PATH . '/routes/test-api.php'); + ->addRouteFile(dirname(__DIR__, 2) . '/fixtures/routes/test-api.php'); $this->withHeaders([ 'X-Header' => 'Value', diff --git a/tests/Foundation/Testing/DatabaseMigrationsTest.php b/tests/Foundation/Testing/DatabaseMigrationsTest.php index 0f9c75ff4..1346c0451 100644 --- a/tests/Foundation/Testing/DatabaseMigrationsTest.php +++ b/tests/Foundation/Testing/DatabaseMigrationsTest.php @@ -9,6 +9,7 @@ use Hypervel\Foundation\Console\Contracts\Kernel as KernelContract; use Hypervel\Foundation\Testing\Concerns\InteractsWithConsole; use Hypervel\Foundation\Testing\DatabaseMigrations; +use Hypervel\Testbench\TestCase; use Hypervel\Tests\Foundation\Concerns\HasMockedApplication; use Mockery as m; @@ -16,7 +17,7 @@ * @internal * @coversNothing */ -class DatabaseMigrationsTest extends ApplicationTestCase +class DatabaseMigrationsTest extends TestCase { use HasMockedApplication; use DatabaseMigrations; diff --git a/tests/Foundation/Testing/RefreshDatabaseTest.php b/tests/Foundation/Testing/RefreshDatabaseTest.php index 0e0247d5e..e4bfb4c0e 100644 --- a/tests/Foundation/Testing/RefreshDatabaseTest.php +++ b/tests/Foundation/Testing/RefreshDatabaseTest.php @@ -12,6 +12,7 @@ use Hypervel\Foundation\Testing\Concerns\InteractsWithConsole; use Hypervel\Foundation\Testing\RefreshDatabase; use Hypervel\Foundation\Testing\RefreshDatabaseState; +use Hypervel\Testbench\TestCase; use Hypervel\Tests\Foundation\Concerns\HasMockedApplication; use Mockery as m; use PDO; @@ -21,7 +22,7 @@ * @internal * @coversNothing */ -class RefreshDatabaseTest extends ApplicationTestCase +class RefreshDatabaseTest extends TestCase { use HasMockedApplication; use RefreshDatabase; diff --git a/tests/Foundation/fixtures/hyperf/.env b/tests/Foundation/fixtures/hyperf/.env deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/Foundation/fixtures/hyperf/routes/test-api.php b/tests/Foundation/fixtures/routes/test-api.php similarity index 100% rename from tests/Foundation/fixtures/hyperf/routes/test-api.php rename to tests/Foundation/fixtures/routes/test-api.php diff --git a/tests/Queue/DatabaseFailedJobProviderTest.php b/tests/Queue/DatabaseFailedJobProviderTest.php index b36bb954b..401c2d355 100644 --- a/tests/Queue/DatabaseFailedJobProviderTest.php +++ b/tests/Queue/DatabaseFailedJobProviderTest.php @@ -10,14 +10,14 @@ use Hypervel\Foundation\Testing\RefreshDatabase; use Hypervel\Queue\Failed\DatabaseFailedJobProvider; use Hypervel\Support\Carbon; -use Hypervel\Tests\Foundation\Testing\ApplicationTestCase; +use Hypervel\Testbench\TestCase; use RuntimeException; /** * @internal * @coversNothing */ -class DatabaseFailedJobProviderTest extends ApplicationTestCase +class DatabaseFailedJobProviderTest extends TestCase { use RefreshDatabase; diff --git a/tests/Queue/DatabaseUuidFailedJobProviderTest.php b/tests/Queue/DatabaseUuidFailedJobProviderTest.php index 6dfefc3a7..06db8c04c 100644 --- a/tests/Queue/DatabaseUuidFailedJobProviderTest.php +++ b/tests/Queue/DatabaseUuidFailedJobProviderTest.php @@ -9,14 +9,14 @@ use Hypervel\Foundation\Testing\RefreshDatabase; use Hypervel\Queue\Failed\DatabaseUuidFailedJobProvider; use Hypervel\Support\Carbon; -use Hypervel\Tests\Foundation\Testing\ApplicationTestCase; +use Hypervel\Testbench\TestCase; use RuntimeException; /** * @internal * @coversNothing */ -class DatabaseUuidFailedJobProviderTest extends ApplicationTestCase +class DatabaseUuidFailedJobProviderTest extends TestCase { use RefreshDatabase; diff --git a/tests/Queue/PruneBatchesCommandTest.php b/tests/Queue/PruneBatchesCommandTest.php index 9cf57c903..fe57273d5 100644 --- a/tests/Queue/PruneBatchesCommandTest.php +++ b/tests/Queue/PruneBatchesCommandTest.php @@ -7,7 +7,7 @@ use Hypervel\Bus\Contracts\BatchRepository; use Hypervel\Bus\DatabaseBatchRepository; use Hypervel\Queue\Console\PruneBatchesCommand; -use Hypervel\Tests\Foundation\Testing\ApplicationTestCase; +use Hypervel\Testbench\TestCase; use Mockery as m; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\NullOutput; @@ -16,7 +16,7 @@ * @internal * @coversNothing */ -class PruneBatchesCommandTest extends ApplicationTestCase +class PruneBatchesCommandTest extends TestCase { protected function tearDown(): void { diff --git a/tests/Queue/QueueDatabaseQueueIntegrationTest.php b/tests/Queue/QueueDatabaseQueueIntegrationTest.php index 3bb3168af..98b613bc0 100644 --- a/tests/Queue/QueueDatabaseQueueIntegrationTest.php +++ b/tests/Queue/QueueDatabaseQueueIntegrationTest.php @@ -12,7 +12,7 @@ use Hypervel\Queue\Events\JobQueued; use Hypervel\Queue\Events\JobQueueing; use Hypervel\Support\Carbon; -use Hypervel\Tests\Foundation\Testing\ApplicationTestCase; +use Hypervel\Testbench\TestCase; use Mockery as m; use Psr\EventDispatcher\EventDispatcherInterface; use Ramsey\Uuid\Uuid; @@ -23,7 +23,7 @@ * @internal * @coversNothing */ -class QueueDatabaseQueueIntegrationTest extends ApplicationTestCase +class QueueDatabaseQueueIntegrationTest extends TestCase { use RefreshDatabase; diff --git a/tests/Queue/QueueSizeTest.php b/tests/Queue/QueueSizeTest.php index 8cd1242af..a06e9c9fc 100644 --- a/tests/Queue/QueueSizeTest.php +++ b/tests/Queue/QueueSizeTest.php @@ -7,13 +7,13 @@ use Hypervel\Bus\Queueable; use Hypervel\Queue\Contracts\ShouldQueue; use Hypervel\Support\Facades\Queue; -use Hypervel\Tests\Foundation\Testing\ApplicationTestCase; +use Hypervel\Testbench\TestCase; /** * @internal * @coversNothing */ -class QueueSizeTest extends ApplicationTestCase +class QueueSizeTest extends TestCase { public function testQueueSize() { diff --git a/tests/Telescope/FeatureTestCase.php b/tests/Telescope/FeatureTestCase.php index f5a0634f7..f299831d1 100644 --- a/tests/Telescope/FeatureTestCase.php +++ b/tests/Telescope/FeatureTestCase.php @@ -24,13 +24,13 @@ use Hypervel\Telescope\Telescope; use Hypervel\Telescope\TelescopeApplicationServiceProvider; use Hypervel\Telescope\TelescopeServiceProvider; -use Hypervel\Tests\Foundation\Testing\ApplicationTestCase; +use Hypervel\Testbench\TestCase; /** * @internal * @coversNothing */ -class FeatureTestCase extends ApplicationTestCase +class FeatureTestCase extends TestCase { use RefreshDatabase; use RunTestsInCoroutine;