Skip to content

Commit

Permalink
Refactor browser test, test monolog bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvdh committed Mar 31, 2024
1 parent 0bf3a5f commit 89b61cc
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 24 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/run-integration.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"autoload-dev": {
"psr-4": {
"DebugBar\\": "tests/DebugBar/"
"DebugBar\\Tests\\": "tests/DebugBar/Tests"
}
},
"suggest": {
Expand Down
8 changes: 6 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,7 +12,7 @@ public function isTabActive(Crawler $crawler, $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
Expand Down
38 changes: 38 additions & 0 deletions tests/DebugBar/Tests/Browser/Bridge/MonologTest.php
Original file line number Diff line number Diff line change
@@ -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]);
}

}
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -20,7 +14,10 @@ public function testDebugbarTab(): void
// 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');

Expand All @@ -44,8 +41,11 @@ public function testDebugbarAjax(): void

// 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');

Expand Down

0 comments on commit 89b61cc

Please sign in to comment.