Skip to content

Commit ca80e25

Browse files
committed
test: Add failing test for profiler
1 parent c704332 commit ca80e25

File tree

7 files changed

+84
-4
lines changed

7 files changed

+84
-4
lines changed

composer.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,20 @@
1919
"symfony/config": "^5.4 || ^6.0 || ^7.0"
2020
},
2121
"require-dev": {
22+
"friendsofphp/php-cs-fixer": "^3.30",
23+
"kubawerlos/php-cs-fixer-custom-fixers": "^3.0",
2224
"matthiasnoback/symfony-dependency-injection-test": "^4.3 || ^5.0",
2325
"phpunit/phpunit": "^9.5",
26+
"psalm/plugin-phpunit": "^0.18",
2427
"psalm/plugin-symfony": "^5.0",
2528
"symfony/console": "^5.4 || ^6.0 || ^7.0",
2629
"symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0",
2730
"symfony/http-kernel": "^5.4 || ^6.0 || ^7.0",
31+
"symfony/routing": "^6.4",
2832
"symfony/test-pack": "^1.1",
33+
"symfony/twig-bundle": "^6.4",
2934
"symfony/yaml": "^5.4 || ^6.0 || ^7.0",
30-
"vimeo/psalm": "^5.15.0",
31-
"kubawerlos/php-cs-fixer-custom-fixers": "^3.0",
32-
"friendsofphp/php-cs-fixer": "^3.30",
33-
"psalm/plugin-phpunit": "^0.18"
35+
"vimeo/psalm": "^5.15.0"
3436
},
3537
"autoload": {
3638
"psr-4": {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Neo4j\Neo4jBundle\Tests\App\Controller;
4+
5+
use Laudis\Neo4j\Contracts\ClientInterface;
6+
use Laudis\Neo4j\Neo4j\Neo4jDriver;
7+
use Neo4j\Neo4jBundle\SymfonyClient;
8+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
9+
use Symfony\Component\HttpFoundation\Response;
10+
use Symfony\Component\Routing\Attribute\Route;
11+
12+
class TestController extends AbstractController
13+
{
14+
public function __construct(
15+
private readonly ClientInterface $client
16+
) {
17+
}
18+
19+
#[Route("/", methods: ["GET"])]
20+
public function index(): Response
21+
{
22+
$this->client->run('MATCH (n) RETURN n');
23+
$this->client->run('MATCH (n) RETURN n');
24+
return $this->render('index.twig.html');
25+
}
26+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>Hello Neo4j</h1>

tests/App/TestKernel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Neo4j\Neo4jBundle\Neo4jBundle;
88
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
9+
use Symfony\Bundle\TwigBundle\TwigBundle;
910
use Symfony\Component\Config\Loader\LoaderInterface;
1011
use Symfony\Component\HttpKernel\Kernel;
1112

@@ -15,6 +16,7 @@ public function registerBundles(): array
1516
{
1617
return [
1718
new FrameworkBundle(),
19+
new TwigBundle(),
1820
new Neo4jBundle(),
1921
];
2022
}

tests/App/config/default.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
1+
2+
services:
3+
Neo4j\Neo4jBundle\Tests\App\Controller\TestController:
4+
public: true
5+
autoconfigure: true
6+
autowire: true
7+
tags: ['controller.service_arguments']
8+
19
framework:
210
secret: test
311
test: true
12+
profiler: { enabled: true, collect: false }
13+
router:
14+
resource: '%kernel.project_dir%/tests/App/config/routes.yaml'
15+
type: 'yaml'
16+
17+
twig:
18+
paths:
19+
- '%kernel.project_dir%/tests/App/Controller/Twig'
420

521
parameters:
622
neo4j.dsn.badname: bolt://localhost

tests/App/config/routes.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
controllers:
2+
resource: '../Controller/'
3+
type: annotation

tests/Functional/ProfilerTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Functional;
4+
5+
use Neo4j\Neo4jBundle\Tests\App\TestKernel;
6+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
7+
8+
class ProfilerTest extends WebTestCase
9+
{
10+
protected static function getKernelClass(): string
11+
{
12+
return TestKernel::class;
13+
}
14+
15+
public function testProfiler()
16+
{
17+
$client = static::createClient();
18+
$client->enableProfiler();
19+
20+
$client->request('GET', '/');
21+
22+
$this->assertResponseIsSuccessful();
23+
if ($profile = $client->getProfile()) {
24+
$this->assertEquals(
25+
2,
26+
$profile->getCollector('neo4j')->getQueryCount()
27+
);
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)