Skip to content

Move test db connection to env#41

Open
fadrian06 wants to merge 9 commits into
leafsphp:v4.xfrom
fadrian06:move-test-db-connection-to-env
Open

Move test db connection to env#41
fadrian06 wants to merge 9 commits into
leafsphp:v4.xfrom
fadrian06:move-test-db-connection-to-env

Conversation

@fadrian06

Copy link
Copy Markdown

What kind of change does this PR introduce? (pls check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe below

Description

This PR addresses an issue I ran into while running tests to continue contributing to the project, caused by hardcoded database connection literals in the tests. These literals are now refactored to pull from .env.example.php with customization possible via .env.php. Before all tests could pass, I spotted a syntax problem in the Db class: the docblock for the first whereJson method was missing the starting /, and that method along with its variants appeared twice. Removing the duplicates fixed the issue, and now all tests pass locally. I’m hoping this PR gets merged soon so I can keep contributing, particularly by helping resolve issues, enhancing sqlite support, and fixing problems when using the database without the Leaf core.

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

Copilot AI review requested due to automatic review settings June 21, 2026 03:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors MySQL tests to use environment-based DB connection settings (via .env.example.php with optional .env.php overrides) and removes a duplicated whereJson/JSON helper method block from src/Db.php.

Changes:

  • Replace hardcoded MySQL connection literals in tests with values read from $_ENV.
  • Add .env.example.php and ignore .env.php to allow local test configuration without committing secrets.
  • Remove duplicated JSON-where methods in src/Db.php.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/mysql/leaf-builder.test.php Switches to env-based DB connection, but currently lacks its own env/fixture setup.
tests/mysql/connect.test.php Loads env config for tests and updates connection assertion to use connectSync.
src/Db.php Removes duplicate JSON-where methods; remaining docblock needs correction.
.gitignore Ignores .env.php to prevent committing local secrets.
.env.example.php Introduces an env template for DB config (currently contains what appear to be real credentials).
Comments suppressed due to low confidence (1)

src/Db.php:362

  • The docblock on whereJson says "Fetch current query with all related data", but the method actually adds a JSON where clause. This mismatch is confusing for IDEs and generated docs; update the summary to reflect the method’s behavior.
    /**
     * Fetch current query with all related data
     *
     * @param string $column The JSON column
     * @param string $jsonKey The key within the JSON structure

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/mysql/connect.test.php
Comment thread tests/mysql/leaf-builder.test.php
Comment thread .env.example.php

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

Comment thread tests/mysql/connect.test.php

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 6 comments.

Comment thread tests/mysql/connect.test.php
Comment thread tests/mysql/leaf-builder.test.php
Comment thread tests/mysql/leaf-builder.test.php
Comment thread tests/mysql/leaf-builder.test.php
Comment thread tests/mysql/leaf-builder.test.php
Comment thread tests/mysql/leaf-builder.test.php

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 7 comments.

Comment thread tests/mysql/connect.test.php
Comment thread tests/mysql/leaf-builder.test.php
Comment thread tests/mysql/leaf-builder.test.php
Comment thread tests/mysql/leaf-builder.test.php
Comment thread tests/mysql/leaf-builder.test.php
Comment thread tests/mysql/leaf-builder.test.php
Comment thread tests/mysql/leaf-builder.test.php
@fadrian06

Copy link
Copy Markdown
Author

Copilot stresses me out; I’m waiting for the opinion of real intelligence.

P.S. The tests need a more thorough refactoring so that if they’re going to depend on order, it’s clearly defined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants