Skip to content

Commit

Permalink
feat: update phpunit 11
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhelias committed Apr 3, 2024
1 parent 50f11f4 commit 9ed2add
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 64 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
"symfony/http-kernel": "^5.4 || ^6.4 || ^7.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"symfony/phpunit-bridge": "^7.0"
"phpunit/phpunit": "^11.0",
"symfony/browser-kit": "^5.4 || ^6.4 || ^7.0",
"symfony/yaml": "^5.4 || ^6.4 || ^7.0"
},
"suggest": {
"perftools/xhgui": "To view the profiling results in a web interface"
Expand Down
26 changes: 11 additions & 15 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
verbose="true"
bootstrap="./vendor/autoload.php"
>
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="tests/bootstrap.php"
colors="true" >

<php>
<ini name="display_errors" value="1" />
<ini name="error_reporting" value="-1" />
<server name="KERNEL_CLASS" value="Odandb\XhprofBundle\Tests\Fixtures\Kernel" />
<server name="APP_ENV" value="test" force="true" />
<server name="APP_DEBUG" value="false" />
<server name="SHELL_VERBOSITY" value="-1" />
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
<server name="SYMFONY_DEPRECATIONS_HELPER" value="999999" />
<server name="SYMFONY_PHPUNIT_VERSION" value="9.5" />
<env name="BOOTSTRAP_CLEAR_CACHE_ENV" value="true"/>
</php>

<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
<testsuite name="XhprofBundle test suite">
<directory>tests/Functional</directory>
</testsuite>
</testsuites>

<coverage processUncoveredFiles="true">
<source>
<include>
<directory>./src/</directory>
<directory>src</directory>
</include>
</coverage>
</source>
</phpunit>
1 change: 0 additions & 1 deletion src/OdandbXhprofBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

declare(strict_types=1);


namespace Odandb\XhprofBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;
Expand Down
2 changes: 0 additions & 2 deletions src/Service/ConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

declare(strict_types=1);


namespace Odandb\XhprofBundle\Service;


use Xhgui\Profiler\Config;

class ConfigFactory
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/var
15 changes: 15 additions & 0 deletions tests/Fixtures/Controller/TestController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Odandb\XhprofBundle\Tests\Fixtures\Controller;

use Symfony\Component\HttpFoundation\JsonResponse;

class TestController
{
public function profile(): JsonResponse
{
return new JsonResponse();
}
}
29 changes: 29 additions & 0 deletions tests/Fixtures/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Odandb\XhprofBundle\Tests\Fixtures;

use Odandb\XhprofBundle\OdandbXhprofBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;

class Kernel extends BaseKernel
{
public function registerBundles(): iterable
{
return [
new FrameworkBundle(),
new OdandbXhprofBundle(),
];
}

public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__ . '/config.yaml');
}

public function getProjectDir(): string
{
return __DIR__;
}
}
13 changes: 13 additions & 0 deletions tests/Fixtures/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
imports:
- { resource: services.yaml }

framework:
secret: '123456789'
http_method_override: false
router:
utf8: true
resource: '%kernel.project_dir%/routing.yaml'
strict_requirements: ~
test: ~
profiler:
collect: false
19 changes: 19 additions & 0 deletions tests/Fixtures/php_xhgui_config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

// Configuration for the profiler to send data to XHGui.
// Set the callable of "profiler.enable" to return false in order to disable the profiler.
return [
'profiler.enable' => function() {
return false;
},

'save.handler' => 'file',
'save.handler.file' => array(
'filename' => 'var/xhgui/data.jsonl',
),
'profiler.simple_url' => null,
'profiler.options' => [],
'date.format' => 'M jS H:i:s',
'detail.count' => 6,
'page.limit' => 25,
];
3 changes: 3 additions & 0 deletions tests/Fixtures/routing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
person_list:
path: /profile
controller: Odandb\XhprofBundle\Tests\Fixtures\Controller\TestController::profile
8 changes: 8 additions & 0 deletions tests/Fixtures/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
_defaults:
autowire: true
autoconfigure: true

Odandb\XhprofBundle\Tests\Fixtures\Controller\:
resource: 'Controller'
tags: ['controller.service_arguments']
43 changes: 43 additions & 0 deletions tests/Functional/FunctionalTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);


namespace Odandb\XhprofBundle\Tests\Functional;


use Odandb\XhprofBundle\EventSubscriber\KernelEventSubscriber;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* This is a functional test to check if the service wiring is correct.
* It is based on https://symfonycasts.com/screencast/symfony-bundle.
*/
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);
self::assertInstanceOf(KernelEventSubscriber::class, $service);
}

public function testProfile()
{
$this->client->request('GET', '/profile');

self::assertResponseIsSuccessful();
}
}
44 changes: 0 additions & 44 deletions tests/FunctionalTest.php

This file was deleted.

13 changes: 13 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

use Symfony\Component\ErrorHandler\ErrorHandler;

require __DIR__ . '/../vendor/autoload.php';

set_exception_handler([new ErrorHandler(), 'handleException']);

// Clean up from previous runs
@exec('rm -rf ' . escapeshellarg(__DIR__ . '/Fixtures/var'));
@exec('mkdir -p ' . escapeshellarg(__DIR__ . '/Fixtures/var/xhgui'));

0 comments on commit 9ed2add

Please sign in to comment.