diff --git a/.github/workflows/run-integration.yml b/.github/workflows/run-integration.yml new file mode 100644 index 0000000..6737595 --- /dev/null +++ b/.github/workflows/run-integration.yml @@ -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 diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 39f2e04..51a5bb3 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -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 diff --git a/README.md b/README.md index 810a45b..54add9a 100644 --- a/README.md +++ b/README.md @@ -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/ \ No newline at end of file +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` \ No newline at end of file diff --git a/composer.json b/composer.json index f1703a2..2c5a7c2 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ }, "autoload-dev": { "psr-4": { - "DebugBar\\": "tests/DebugBar/" + "DebugBar\\Tests\\": "tests/DebugBar/Tests" } }, "suggest": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d302284..890afc9 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,8 +1,12 @@ - - ./tests/DebugBar/ + + ./tests/DebugBar/Tests + ./tests/DebugBar/Tests/Browser + + + ./tests/DebugBar/Tests/Browser diff --git a/tests/DebugBar/Browser/AbstractBrowserTest.php b/tests/DebugBar/Tests/Browser/AbstractBrowserTest.php similarity index 61% rename from tests/DebugBar/Browser/AbstractBrowserTest.php rename to tests/DebugBar/Tests/Browser/AbstractBrowserTest.php index 30752de..c9bb177 100644 --- a/tests/DebugBar/Browser/AbstractBrowserTest.php +++ b/tests/DebugBar/Tests/Browser/AbstractBrowserTest.php @@ -1,13 +1,7 @@ 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 diff --git a/tests/DebugBar/Tests/Browser/Bridge/MonologTest.php b/tests/DebugBar/Tests/Browser/Bridge/MonologTest.php new file mode 100644 index 0000000..8921a87 --- /dev/null +++ b/tests/DebugBar/Tests/Browser/Bridge/MonologTest.php @@ -0,0 +1,38 @@ +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]); + } + +} \ No newline at end of file diff --git a/tests/DebugBar/Browser/BasicBrowserTest.php b/tests/DebugBar/Tests/Browser/DebugbarTest.php similarity index 83% rename from tests/DebugBar/Browser/BasicBrowserTest.php rename to tests/DebugBar/Tests/Browser/DebugbarTest.php index 4e11b59..bf6a122 100644 --- a/tests/DebugBar/Browser/BasicBrowserTest.php +++ b/tests/DebugBar/Tests/Browser/DebugbarTest.php @@ -1,16 +1,10 @@ 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');