mirror of
https://github.com/maximebf/php-debugbar.git
synced 2025-07-25 10:41:55 +02:00
Refactor browser test, test monolog bridge
This commit is contained in:
43
.github/workflows/run-integration.yml
vendored
Normal file
43
.github/workflows/run-integration.yml
vendored
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
name: Tests
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
- 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:
|
jobs:
|
||||||
php-tests:
|
php-tests:
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
env:
|
env:
|
||||||
COMPOSER_NO_INTERACTION: 1
|
COMPOSER_NO_INTERACTION: 1
|
||||||
@@ -38,4 +38,4 @@ jobs:
|
|||||||
run: composer update --prefer-dist --no-progress
|
run: composer update --prefer-dist --no-progress
|
||||||
|
|
||||||
- name: Execute Unit Tests
|
- name: Execute Unit Tests
|
||||||
run: vendor/bin/phpunit
|
run: vendor/bin/phpunit --testsuite=Unit
|
||||||
|
@@ -115,4 +115,9 @@ To run the demo, clone this repository and start the Built-In PHP webserver from
|
|||||||
php -S localhost:8000
|
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": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"DebugBar\\": "tests/DebugBar/"
|
"DebugBar\\Tests\\": "tests/DebugBar/Tests"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
|
@@ -1,8 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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">
|
<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>
|
<testsuites>
|
||||||
<testsuite name="DebugBar Test Suite">
|
<testsuite name="Unit">
|
||||||
<directory>./tests/DebugBar/</directory>
|
<directory>./tests/DebugBar/Tests</directory>
|
||||||
|
<exclude>./tests/DebugBar/Tests/Browser</exclude>
|
||||||
|
</testsuite>
|
||||||
|
<testsuite name="Browser">
|
||||||
|
<directory>./tests/DebugBar/Tests/Browser</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
<extensions>
|
<extensions>
|
||||||
|
@@ -1,13 +1,7 @@
|
|||||||
<?php
|
<?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\DomCrawler\Crawler;
|
||||||
use Symfony\Component\Panther\DomCrawler\Link;
|
use Symfony\Component\Panther\DomCrawler\Link;
|
||||||
use Symfony\Component\Panther\PantherTestCase;
|
use Symfony\Component\Panther\PantherTestCase;
|
||||||
@@ -18,7 +12,7 @@ abstract class AbstractBrowserTest extends PantherTestCase
|
|||||||
{
|
{
|
||||||
$node = $crawler->filter('a.phpdebugbar-tab[data-collector="'.$tab.'"]');
|
$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
|
public function getTabLink(Crawler $crawler, $tab): Link
|
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 DebugbarTest 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
|
<?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 Facebook\WebDriver\WebDriverElement;
|
||||||
use Symfony\Component\Panther\PantherTestCase;
|
|
||||||
|
|
||||||
class BasicBrowserTest extends AbstractBrowserTest
|
class DebugbarTest extends AbstractBrowserTest
|
||||||
{
|
{
|
||||||
public function testDebugbarTab(): void
|
public function testDebugbarTab(): void
|
||||||
{
|
{
|
||||||
@@ -20,7 +14,10 @@ class BasicBrowserTest extends AbstractBrowserTest
|
|||||||
// Wait for Debugbar to load
|
// Wait for Debugbar to load
|
||||||
$crawler = $client->waitFor('.phpdebugbar-body');
|
$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');
|
$crawler = $client->waitForVisibility('.phpdebugbar-panel[data-collector=messages] .phpdebugbar-widgets-list');
|
||||||
|
|
||||||
@@ -44,8 +41,11 @@ class BasicBrowserTest extends AbstractBrowserTest
|
|||||||
|
|
||||||
// Wait for Debugbar to load
|
// Wait for Debugbar to load
|
||||||
$crawler = $client->waitFor('.phpdebugbar-body');
|
$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');
|
$crawler = $client->waitForVisibility('.phpdebugbar-widgets-messages .phpdebugbar-widgets-list');
|
||||||
|
|
Reference in New Issue
Block a user