Skip to content

Commit

Permalink
DebugMode: polished doc, polished test
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Jan 11, 2025
1 parent 9c4b416 commit fd1e27b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
46 changes: 29 additions & 17 deletions .docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ extensions:
nettrine.dbal: Nettrine\DBAL\DI\DbalExtension
```

Debug mode can be passed in extension constructor `DbalExtension(%debugMode%)`, but it's optional and determined automatically from `Tracy\Debugger::$productionMode`.
For better integration with Nette Framework and Tracy, pass `%debugMode%` to the extension constructor. Learn more in [debug chapter](#debug).

```neon
extensions:
nettrine.dbal: Nettrine\DBAL\DI\DbalExtension(%debugMode%)
```

> [!NOTE]
> This is just **DBAL**, for **ORM** please use [nettrine/orm](https://github.com/contributte/doctrine-orm).
Expand All @@ -42,14 +47,6 @@ Debug mode can be passed in extension constructor `DbalExtension(%debugMode%)`,

### Minimal configuration

```neon
nettrine.dbal:
connections:
default:
driver: pdo_pgsql
url: "postgresql://user:password@localhost:5432/dbname"
```

**PostgreSQL**

```neon
Expand Down Expand Up @@ -316,15 +313,30 @@ nettrine.dbal:

### Debug

This library provides Tracy panel for debugging queries. You can enable it by setting `debug.panel` to `true`.
Default value is reversed value of `Tracy\Debugger::$productionMode`, or you can pass it to extension constructor.
You can also specify source paths for Tracy panel. This is useful when you want to see the source code of the query.
This library provides Tracy panel(s) for debugging queries.

```neon
nettrine.dbal:
debug:
panel: %debugMode%
```
You can enable Tracy panels(s) multiple ways:

1. Autodetect in development mode (`Tracy\Debugger::$productionMode = FALSE`). [Learn more about Nette & Tracy](https://doc.nette.org/en/application/bootstrap).

```php
$configurator->enableTracy(...);
```

2. Manually provide `%debugMode%` to the extension.

```neon
extensions:
nettrine.dbal: Nettrine\DBAL\DI\DbalExtension(%debugMode%)
```

3. Manually set `debug.panel` to `true` in NEON configuration.

```neon
nettrine.dbal:
debug:
panel: %debugMode%
```

![Tracy](https://raw.githubusercontent.com/nettrine/dbal/master/.docs/assets/tracy.png)

Expand Down
12 changes: 9 additions & 3 deletions tests/Cases/DI/DbalExtension.debugMode.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Toolkit::test(function (): void {
$blueScreen = Debugger::getBlueScreen();
$panels = Liberator::of($blueScreen)->panels;

Assert::count(0, $panels);
Assert::count(0, $panels); // no debug mode = no panel
});

// Debug mode auto-detection from Tracy/Debugger with multiple panels
Expand Down Expand Up @@ -72,7 +72,10 @@ Toolkit::test(function (): void {
$blueScreen = Debugger::getBlueScreen();
$panels = Liberator::of($blueScreen)->panels;

Assert::count(2, $panels);
Assert::count(2, $panels); // 2 connections = 2 panels

// Cleanup panels
Liberator::of($blueScreen)->panels = [];
});

// Debug mode passed via constructor
Expand All @@ -97,7 +100,10 @@ Toolkit::test(function (): void {
$blueScreen = Debugger::getBlueScreen();
$panels = Liberator::of($blueScreen)->panels;

Assert::count(3, $panels); // 2 are from previous test
Assert::count(1, $panels); // 1 connection = 1 panel

// Cleanup panels
Liberator::of($blueScreen)->panels = [];
});

// Debug mode defined in debug.panel, testing DebugStack middleware
Expand Down

0 comments on commit fd1e27b

Please sign in to comment.