Skip to content

Commit

Permalink
fix: phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhelias committed Apr 3, 2024
1 parent 9ed2add commit 42b0cb9
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 9 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ jobs:
SYMFONY_REQUIRE: ${{ matrix.symfony }}

- name: Run tests
run: composer test
run: |
if [[ "${{ matrix.coverage }}" == 'pcov' ]]; then
composer test-coverage
else
composer test
fi
- name: Monitor coverage
if: matrix.coverage != 'none'
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"symfony/http-kernel": "^5.4 || ^6.4 || ^7.0"
},
"require-dev": {
"phpunit/phpunit": "^11.0",
"phpunit/phpunit": "^10.5 || ^11.0",
"symfony/browser-kit": "^5.4 || ^6.4 || ^7.0",
"symfony/yaml": "^5.4 || ^6.4 || ^7.0"
},
Expand All @@ -54,6 +54,7 @@
"sort-packages": true
},
"scripts": {
"test": "vendor/bin/phpunit --coverage-clover=coverage-report.xml"
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-clover=coverage-report.xml"
}
}
6 changes: 5 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
</php>

<testsuites>
<testsuite name="XhprofBundle test suite">
<testsuite name="XhprofBundle unit test suite">
<directory>tests/Unit</directory>
</testsuite>

<testsuite name="XhprofBundle functional test suite">
<directory>tests/Functional</directory>
</testsuite>
</testsuites>
Expand Down
6 changes: 1 addition & 5 deletions tests/Functional/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@ class FunctionalTest extends WebTestCase
{
protected ?KernelBrowser $client;

protected ?ContainerInterface $container;

protected function setUp() : void
{
$this->client = self::createClient();

$this->container = $this->client->getContainer();
}

public function testServiceWiring()
{
$service = $this->container->get(KernelEventSubscriber::class);
$service = self::getContainer()->get(KernelEventSubscriber::class);
self::assertInstanceOf(KernelEventSubscriber::class, $service);
}

Expand Down
50 changes: 50 additions & 0 deletions tests/Unit/XhprofCollectorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Odandb\XhprofBundle\Tests\Unit;

use Odandb\XhprofBundle\DataCollector\XhprofCollector;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Xhgui\Profiler\Config;

class XhprofCollectorTest extends TestCase
{
public function testCollectWithConfig(): void
{
$config = Config::create();
$config->load(__DIR__ . '/../Fixtures/php_xhgui_config.php');


$c = $this->createCollector($config);

$request = new Request();
$request->attributes->set('_xhprof_data', ['profile' => [
'main()==>strlen' => [
'ct' => 1,
'wt' => 279,
],
]]);

$c->collect($request, new Response());

self::assertFalse($c->getIsEnabled());
self::assertIsArray($c->getExtensionLoaded());
self::assertSame('file', $c->getSaverMethod());
self::assertIsArray($c->getUploadMethod());
self::assertIsArray($c->getProfileData());
}

public function testCollectWithoutConfig(): void
{
$this->expectException(\RuntimeException::class);

$c = $this->createCollector();
$c->collect(new Request(), new Response());
}

private function createCollector(?Config $config = null): XhprofCollector
{
return new XhprofCollector($config);
}
}

0 comments on commit 42b0cb9

Please sign in to comment.