mirror of
https://github.com/maximebf/php-debugbar.git
synced 2025-07-23 17:51:56 +02:00
Refactor browser test, test monolog bridge (#641)
* Refactor browser test, test monolog bridge * Rename * Add Doctrine
This commit is contained in:
45
.github/workflows/run-integration.yml
vendored
Normal file
45
.github/workflows/run-integration.yml
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
name: Integration
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- "*"
|
||||
schedule:
|
||||
- cron: '0 0 * * *'
|
||||
|
||||
jobs:
|
||||
php-tests:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
env:
|
||||
COMPOSER_NO_INTERACTION: 1
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
php: [8.3, 7.4]
|
||||
|
||||
name: PHP${{ matrix.php }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php }}
|
||||
coverage: none
|
||||
extensions: pdo_sqlite
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
composer update --prefer-dist --no-progress
|
||||
composer update --prefer-dist --no-progress --working-dir=demo/bridge/monolog
|
||||
composer update --prefer-dist --no-progress --working-dir=demo/bridge/doctrine
|
||||
composer run --working-dir=demo/bridge/doctrine install-schema
|
||||
|
||||
- name: Execute Unit Tests
|
||||
run: vendor/bin/phpunit --testsuite=Browser
|
4
.github/workflows/run-tests.yml
vendored
4
.github/workflows/run-tests.yml
vendored
@@ -12,7 +12,7 @@ on:
|
||||
|
||||
jobs:
|
||||
php-tests:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
env:
|
||||
COMPOSER_NO_INTERACTION: 1
|
||||
@@ -38,4 +38,4 @@ jobs:
|
||||
run: composer update --prefer-dist --no-progress
|
||||
|
||||
- name: Execute Unit Tests
|
||||
run: vendor/bin/phpunit
|
||||
run: vendor/bin/phpunit --testsuite=Unit
|
||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,7 +1,8 @@
|
||||
composer.lock
|
||||
/vendor
|
||||
/demo/bridge/*/vendor
|
||||
/demo/bridge/doctrine/db.sqlite
|
||||
/src/DebugBar/Resources/vendor
|
||||
.phpunit.result.cache
|
||||
/drivers
|
||||
.phpunit.cache/
|
||||
.phpunit.cache/
|
||||
|
@@ -115,4 +115,9 @@ To run the demo, clone this repository and start the Built-In PHP webserver from
|
||||
php -S localhost:8000
|
||||
```
|
||||
|
||||
Then visit http://localhost:8000/demo/
|
||||
Then visit http://localhost:8000/demo/
|
||||
|
||||
## Testing
|
||||
|
||||
To test, run `php vendor/bin/phpunit`.
|
||||
To debug Browser tests, you can run `PANTHER_NO_HEADLESS=1 vendor/bin/phpunit --debug`
|
@@ -34,7 +34,7 @@
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"DebugBar\\": "tests/DebugBar/"
|
||||
"DebugBar\\Tests\\": "tests/DebugBar/Tests"
|
||||
}
|
||||
},
|
||||
"suggest": {
|
||||
|
@@ -7,3 +7,5 @@ $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
|
||||
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
|
||||
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
|
||||
));
|
||||
|
||||
return $helperSet;
|
@@ -1,9 +1,13 @@
|
||||
{
|
||||
"require": {
|
||||
"doctrine/orm": "2.*",
|
||||
"doctrine/cache": "1.11.*",
|
||||
"symfony/yaml": "2.*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {"": "src/"}
|
||||
},
|
||||
"scripts": {
|
||||
"install-schema": "@php vendor/bin/doctrine orm:schema-tool:update --force"
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="tests/bootstrap.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
|
||||
<testsuites>
|
||||
<testsuite name="DebugBar Test Suite">
|
||||
<directory>./tests/DebugBar/</directory>
|
||||
<testsuite name="Unit">
|
||||
<directory>./tests/DebugBar/Tests</directory>
|
||||
<exclude>./tests/DebugBar/Tests/Browser</exclude>
|
||||
</testsuite>
|
||||
<testsuite name="Browser">
|
||||
<directory>./tests/DebugBar/Tests/Browser</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<extensions>
|
||||
|
@@ -1,13 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace DebugBar\Tests;
|
||||
namespace DebugBar\Tests\Browser;
|
||||
|
||||
use DebugBar\DebugBar;
|
||||
use DebugBar\DebugBarException;
|
||||
use DebugBar\Tests\DataCollector\MockCollector;
|
||||
use DebugBar\Tests\Storage\MockStorage;
|
||||
use DebugBar\RandomRequestIdGenerator;
|
||||
use Facebook\WebDriver\WebDriverElement;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
use Symfony\Component\Panther\DomCrawler\Link;
|
||||
use Symfony\Component\Panther\PantherTestCase;
|
||||
@@ -18,7 +12,7 @@ abstract class AbstractBrowserTest extends PantherTestCase
|
||||
{
|
||||
$node = $crawler->filter('a.phpdebugbar-tab[data-collector="'.$tab.'"]');
|
||||
|
||||
return strpos($node->attr('class'), 'phpdebugbar-active"') !== false;
|
||||
return strpos($node->attr('class'), 'phpdebugbar-active') !== false;
|
||||
}
|
||||
|
||||
public function getTabLink(Crawler $crawler, $tab): Link
|
39
tests/DebugBar/Tests/Browser/Bridge/DoctrineTest.php
Normal file
39
tests/DebugBar/Tests/Browser/Bridge/DoctrineTest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace DebugBar\Tests\Browser\Bridge;
|
||||
|
||||
use DebugBar\Browser\Bridge\WebDriverElement;
|
||||
use DebugBar\Tests\Browser\AbstractBrowserTest;
|
||||
|
||||
class DoctrineTest extends AbstractBrowserTest
|
||||
{
|
||||
public function testMonologCollector(): void
|
||||
{
|
||||
if (!file_exists(__DIR__ . '/../../../../../demo/bridge/doctrine/vendor/autoload.php')) {
|
||||
$this->markTestSkipped('Doctrine is not installed');
|
||||
}
|
||||
|
||||
$client = static::createPantherClient();
|
||||
|
||||
$client->request('GET', '/demo/bridge/doctrine');
|
||||
|
||||
// Wait for Debugbar to load
|
||||
$crawler = $client->waitFor('.phpdebugbar-body');
|
||||
usleep(1000);
|
||||
|
||||
if (!$this->isTabActive($crawler, 'database')) {
|
||||
$client->click($this->getTabLink($crawler, 'database'));
|
||||
}
|
||||
|
||||
$crawler = $client->waitForVisibility('.phpdebugbar-panel[data-collector=database]');
|
||||
|
||||
$statements = $crawler->filter('.phpdebugbar-panel[data-collector=database] .phpdebugbar-widgets-sql')
|
||||
->each(function($node){
|
||||
return $node->getText();
|
||||
});
|
||||
|
||||
$this->assertEquals('INSERT INTO products (name) VALUES (?)', $statements[1]);
|
||||
$this->assertCount(3, $statements);
|
||||
}
|
||||
|
||||
}
|
38
tests/DebugBar/Tests/Browser/Bridge/MonologTest.php
Normal file
38
tests/DebugBar/Tests/Browser/Bridge/MonologTest.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace DebugBar\Tests\Browser\Bridge;
|
||||
|
||||
use DebugBar\Browser\Bridge\WebDriverElement;
|
||||
use DebugBar\Tests\Browser\AbstractBrowserTest;
|
||||
|
||||
class MonologTest extends AbstractBrowserTest
|
||||
{
|
||||
public function testMonologCollector(): void
|
||||
{
|
||||
if (!file_exists(__DIR__ . '/../../../../../demo/bridge/monolog/vendor/autoload.php')) {
|
||||
$this->markTestSkipped('Monolog is not installed');
|
||||
}
|
||||
|
||||
$client = static::createPantherClient();
|
||||
|
||||
$client->request('GET', '/demo/bridge/monolog');
|
||||
|
||||
// Wait for Debugbar to load
|
||||
$crawler = $client->waitFor('.phpdebugbar-body');
|
||||
usleep(1000);
|
||||
|
||||
if (!$this->isTabActive($crawler, 'monolog')) {
|
||||
$client->click($this->getTabLink($crawler, 'monolog'));
|
||||
}
|
||||
|
||||
$crawler = $client->waitForVisibility('.phpdebugbar-panel[data-collector=monolog]');
|
||||
|
||||
$messages = $crawler->filter('.phpdebugbar-panel[data-collector=monolog] .phpdebugbar-widgets-value')
|
||||
->each(function($node){
|
||||
return $node->getText();
|
||||
});
|
||||
|
||||
$this->assertStringContainsString('demo.INFO: hello world [] []', $messages[0]);
|
||||
}
|
||||
|
||||
}
|
@@ -1,16 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace DebugBar\Tests;
|
||||
namespace DebugBar\Tests\Browser;
|
||||
|
||||
use DebugBar\DebugBar;
|
||||
use DebugBar\DebugBarException;
|
||||
use DebugBar\Tests\DataCollector\MockCollector;
|
||||
use DebugBar\Tests\Storage\MockStorage;
|
||||
use DebugBar\RandomRequestIdGenerator;
|
||||
use Facebook\WebDriver\WebDriverElement;
|
||||
use Symfony\Component\Panther\PantherTestCase;
|
||||
|
||||
class BasicBrowserTest extends AbstractBrowserTest
|
||||
class DebugbarTest extends AbstractBrowserTest
|
||||
{
|
||||
public function testDebugbarTab(): void
|
||||
{
|
||||
@@ -20,7 +14,10 @@ class BasicBrowserTest extends AbstractBrowserTest
|
||||
// Wait for Debugbar to load
|
||||
$crawler = $client->waitFor('.phpdebugbar-body');
|
||||
|
||||
$client->click($this->getTabLink($crawler, 'messages'));
|
||||
usleep(1000);
|
||||
if (!$this->isTabActive($crawler, 'messages')) {
|
||||
$client->click($this->getTabLink($crawler, 'messages'));
|
||||
}
|
||||
|
||||
$crawler = $client->waitForVisibility('.phpdebugbar-panel[data-collector=messages] .phpdebugbar-widgets-list');
|
||||
|
||||
@@ -44,8 +41,11 @@ class BasicBrowserTest extends AbstractBrowserTest
|
||||
|
||||
// Wait for Debugbar to load
|
||||
$crawler = $client->waitFor('.phpdebugbar-body');
|
||||
usleep(1000);
|
||||
|
||||
$client->click($this->getTabLink($crawler, 'messages'));
|
||||
if (!$this->isTabActive($crawler, 'messages')) {
|
||||
$client->click($this->getTabLink($crawler, 'messages'));
|
||||
}
|
||||
|
||||
$crawler = $client->waitForVisibility('.phpdebugbar-widgets-messages .phpdebugbar-widgets-list');
|
||||
|
Reference in New Issue
Block a user