From 84e1914194b2df8284e8519c72cf46819b410352 Mon Sep 17 00:00:00 2001 From: lotyp Date: Sun, 26 May 2024 20:04:07 +0300 Subject: [PATCH 1/3] ci: fix php-stan error --- tests/src/Bridge/Laravel/LoggerFactoryTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/src/Bridge/Laravel/LoggerFactoryTest.php b/tests/src/Bridge/Laravel/LoggerFactoryTest.php index eedb725e..81420d82 100644 --- a/tests/src/Bridge/Laravel/LoggerFactoryTest.php +++ b/tests/src/Bridge/Laravel/LoggerFactoryTest.php @@ -48,6 +48,7 @@ public function it_should_return_custom_logger_from_factory(): void new DatabaseConfig(config('cycle.database')) ); + // @phpstan-ignore-next-line $logger = $loggerFactory->getLogger($mockDriver); $logger->info('Test log entry'); From 07e3337b7d0ec6b301a586a8ccd047f358762aee Mon Sep 17 00:00:00 2001 From: lotyp Date: Sun, 26 May 2024 20:04:44 +0300 Subject: [PATCH 2/3] test: test against sqlserver and fix failing tests --- tests/app/Entities/User.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/app/Entities/User.php b/tests/app/Entities/User.php index f094f3b4..2efdb950 100644 --- a/tests/app/Entities/User.php +++ b/tests/app/Entities/User.php @@ -26,19 +26,19 @@ class User #[Column(type: 'string', nullable: true)] public ?string $company = null; - #[BelongsTo(target: User::class, innerKey: 'userId', nullable: true)] + #[BelongsTo(target: User::class, innerKey: 'userId', nullable: true, fkAction: 'NO ACTION')] public ?User $friend = null; - #[HasMany(target: User::class, outerKey: 'userId', nullable: true)] + #[HasMany(target: User::class, outerKey: 'userId', nullable: true, fkAction: 'NO ACTION')] public ?iterable $friends = []; - #[HasMany(target: User::class, outerKey: 'userId', nullable: true, collection: 'array')] + #[HasMany(target: User::class, outerKey: 'userId', nullable: true, fkAction: 'NO ACTION', collection: 'array')] public ?array $friendsAsArray = []; #[HasMany(target: Role::class)] public ?Collection $roles; - #[HasMany(target: User::class, outerKey: 'userId', nullable: true, collection: 'illuminate')] + #[HasMany(target: User::class, outerKey: 'userId', nullable: true, fkAction: 'NO ACTION', collection: 'illuminate')] public ?Collection $friendsAsIlluminateCollection; #[Column(type: 'string', nullable: true)] From 2189a744f514d6d0703f141488569b7cafe9bf6a Mon Sep 17 00:00:00 2001 From: lotyp Date: Sun, 26 May 2024 20:05:21 +0300 Subject: [PATCH 3/3] ci: support testing against mysql, sqlserver, pgsql using Makefile --- .env.example | 30 +++++++++++++++++++++++------- Makefile | 18 +++++++++++++++++- composer.json | 23 +++++++++++++++++++++++ config/cycle.php | 17 +++++++++-------- docker-compose.yaml | 45 ++++++++++++++++++++++++++++++++++++++++----- 5 files changed, 112 insertions(+), 21 deletions(-) diff --git a/.env.example b/.env.example index 2a6b29e5..6072eb89 100644 --- a/.env.example +++ b/.env.example @@ -1,18 +1,34 @@ +# # https://docs.docker.com/compose/reference/envvars/#compose_project_name # With custom namespace provided, it will be used to prefix all services # in Docker network for current project +# COMPOSE_PROJECT_NAME=laravel-cycle-orm-adapter APP_ENV=production -DB_CONNECTION=pgsql -DB_HOST=pgsql -DB_PORT=5432 - -DB_DATABASE=default -DB_USERNAME=root -DB_PASSWORD=password +# +# You can override default .envs from config/cycle.php here +# +DB_CONNECTION=memory +DB_PASSWORD=wZ8__DMu5_GZjRL +# DB_CONNECTION=pgsql +# DB_HOST=pgsql +# DB_PORT=5432 +# DB_DATABASE=default +# DB_USERNAME=cycle DB_MYSQL_FORWARD_PORT=13306 DB_PGSQL_FORWARD_PORT=15432 +DB_SQLSERVER_FORWARD_PORT=11434 XDEBUG_MODE=coverage + +CYCLE_ADAPTER_QUEUE_INTEGRATION=false +CYCLE_ADAPTER_SESSION_INTEGRATION=false +CYCLE_ADAPTER_CACHE_INTEGRATION=false + +CYCLE_ATTRIBUTES_CACHE=true +CYCLE_ATTRIBUTES_CACHE_DRIVER=array + +CYCLE_SCHEMA_CACHE=true +CYCLE_SCHEMA_CACHE_DRIVER=array diff --git a/Makefile b/Makefile index 0e820b88..8547b731 100644 --- a/Makefile +++ b/Makefile @@ -264,10 +264,26 @@ infect-ci: ## Runs infection – mutation testing framework with github output ( $(APP_COMPOSER) infect:ci .PHONY: lint-infect-ci -test: ## Run project php-unit and pest tests +test: ## Run project php-unit and pest tests against sqlite in-memory database $(APP_COMPOSER) test .PHONY: test +test-pgsql: ## Run project php-unit and pest tests over pgsql database + $(APP_COMPOSER) test:pgsql +.PHONY: test-pgsql + +test-mysql: ## Run project php-unit and pest tests over mysql database + $(APP_COMPOSER) test:mysql +.PHONY: test-mysql + +test-sqlite: ## Run project php-unit and pest tests over sqlite in-file database + $(APP_COMPOSER) test:sqlite +.PHONY: test-sqlite + +test-sqlserver: ## Run project php-unit and pest tests over mssql (sqlserver) database + $(APP_COMPOSER) test:sqlserver +.PHONY: test-sqlserver + test-cc: ## Run project php-unit and pest tests in coverage mode and build report $(APP_COMPOSER) test:cc .PHONY: test-cc diff --git a/composer.json b/composer.json index 343cdc50..084541bc 100644 --- a/composer.json +++ b/composer.json @@ -164,6 +164,29 @@ "test:cc": [ "@putenv XDEBUG_MODE=coverage", "php vendor/bin/pest --coverage --coverage-clover=.build/phpunit/logs/clover.xml --color=always" + ], + "test:mysql": [ + "@putenv XDEBUG_MODE=coverage", + "@putenv DB_CONNECTION=mysql", + "@putenv DB_HOST=mysql", + "php vendor/bin/pest --color=always" + ], + "test:pgsql": [ + "@putenv XDEBUG_MODE=coverage", + "@putenv DB_CONNECTION=pgsql", + "@putenv DB_HOST=pgsql", + "php vendor/bin/pest --color=always" + ], + "test:sqlite": [ + "@putenv XDEBUG_MODE=coverage", + "@putenv DB_CONNECTION=sqlite", + "php vendor/bin/pest --color=always" + ], + "test:sqlserver": [ + "@putenv XDEBUG_MODE=coverage", + "@putenv DB_CONNECTION=sqlserver", + "@putenv DB_HOST=sqlserver", + "php vendor/bin/pest --color=always" ] } } diff --git a/config/cycle.php b/config/cycle.php index ad306524..461248ca 100644 --- a/config/cycle.php +++ b/config/cycle.php @@ -87,7 +87,7 @@ */ 'databases' => [ 'default' => [ - 'driver' => env('DB_CONNECTION', 'sqlite'), + 'driver' => env('DB_CONNECTION', 'memory'), ], ], @@ -111,7 +111,7 @@ 'sqlite' => new Config\SQLiteDriverConfig( connection: new Config\SQLite\FileConnectionConfig( - database: env('DB_DATABASE', database_path('database.sqlite')) + database: database_path(env('DB_DATABASE', 'database')) . '.sqlite' ), driver: Driver\SQLite\SQLiteDriver::class, reconnect: true, @@ -127,10 +127,10 @@ 'pgsql' => new Config\PostgresDriverConfig( connection: new Config\Postgres\TcpConnectionConfig( - database: env('DB_DATABASE', 'wod'), + database: env('DB_DATABASE', 'default'), host: env('DB_HOST', '127.0.0.1'), port: env('DB_PORT', 5432), - user: env('DB_USERNAME', 'wod'), + user: env('DB_USERNAME', 'cycle'), password: env('DB_PASSWORD', '') ), schema: Config\PostgresDriverConfig::DEFAULT_SCHEMA, @@ -148,10 +148,10 @@ 'mysql' => new Config\MySQLDriverConfig( connection: new Config\MySQL\TcpConnectionConfig( - database: env('DB_DATABASE', 'wod'), + database: env('DB_DATABASE', 'default'), host: env('DB_HOST', '127.0.0.1'), port: env('DB_PORT', 3306), - user: env('DB_USERNAME', 'wod'), + user: env('DB_USERNAME', 'cycle'), password: env('DB_PASSWORD', '') ), driver: Driver\MySQL\MySQLDriver::class, @@ -168,10 +168,11 @@ 'sqlserver' => new Config\SQLServerDriverConfig( connection: new Config\SQLServer\TcpConnectionConfig( - database: env('DB_DATABASE', 'wod'), + database: env('DB_DATABASE', 'tempdb'), host: env('DB_HOST', '127.0.0.1'), port: env('DB_PORT', 1433), - user: env('DB_USERNAME', 'wod'), + trustServerCertificate: true, + user: env('DB_USERNAME', 'SA'), password: env('DB_PASSWORD', '') ), driver: Driver\SQLServer\SQLServerDriver::class, diff --git a/docker-compose.yaml b/docker-compose.yaml index 1358e0e0..ea364d43 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -26,11 +26,16 @@ services: env_file: - .env environment: - POSTGRES_USER: ${DB_USERNAME} + POSTGRES_USER: ${DB_USERNAME:-cycle} POSTGRES_PASSWORD: ${DB_PASSWORD} - POSTGRES_DB: ${DB_DATABASE} + POSTGRES_DB: ${DB_DATABASE:-default} volumes: - pgsql-data:/var/lib/postgresql/data:cached + healthcheck: + test: ['CMD', 'pg_isready', '-U', '${DB_USERNAME:-cycle}', '-d', '${DB_DATABASE:-default}'] + interval: 3s + timeout: 1s + retries: 10 mysql: image: mysql:latest @@ -44,18 +49,48 @@ services: - .env environment: MYSQL_ROOT_HOST: '%' - MYSQL_USER: ${DB_USERNAME} + MYSQL_USER: ${DB_USERNAME:-cycle} + MYSQL_PASSWORD: ${DB_PASSWORD} MYSQL_ROOT_PASSWORD: ${DB_PASSWORD} - MYSQL_DATABASE: ${DB_DATABASE} + MYSQL_DATABASE: ${DB_DATABASE:-default} volumes: - mysql-data:/var/lib/mysql:cached - command: --default-authentication-plugin=mysql_native_password + healthcheck: + test: ['CMD', 'mysqladmin', 'ping', '-h', 'localhost'] + interval: 3s + timeout: 1s + retries: 10 + + sqlserver: + image: mcr.microsoft.com/mssql/server:2022-latest + platform: linux/amd64 + container_name: ${COMPOSE_PROJECT_NAME}-sqlserver + restart: on-failure + networks: + - default + ports: + - '${DB_SQLSERVER_FORWARD_PORT:-11434}:1433' + env_file: + - .env + environment: + SA_PASSWORD: ${DB_PASSWORD} + ACCEPT_EULA: 'Y' + volumes: + - sqlserver-data:/var/opt/mssql + healthcheck: + test: + ['CMD', '/opt/mssql-tools/bin/sqlcmd', '-S', 'localhost', '-U', 'SA', '-P', '${DB_PASSWORD}', '-l', '30', '-Q', 'SELECT 1'] + interval: 3s + timeout: 1s + retries: 10 volumes: pgsql-data: name: ${COMPOSE_PROJECT_NAME}-pgsql-data mysql-data: name: ${COMPOSE_PROJECT_NAME}-mysql-data + sqlserver-data: + name: ${COMPOSE_PROJECT_NAME}-sqlserver-data networks: default: