Skip to content

Commit 490a766

Browse files
committed
minor #7329 Delete an unused test which would not work anymore and replace it wit… (michaelKaefer)
This PR was merged into the 4.x branch. Discussion ---------- Delete an unused test which would not work anymore and replace it wit… …h a rewrite Commits ------- 1fc8a70 Delete an unused test which would not work anymore and replace it with a rewrite
2 parents 5cdc9a3 + 1fc8a70 commit 490a766

File tree

4 files changed

+111
-78
lines changed

4 files changed

+111
-78
lines changed

phpunit.xml.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
<testsuite name="EasyAdmin Test Suite">
2020
<directory>tests/</directory>
2121
<exclude>tests/Controller/PrettyUrls/</exclude>
22-
<exclude>tests/DataCollector/</exclude>
2322
<exclude>tests/EventListener/</exclude>
2423
<exclude>tests/Form/</exclude>
2524
</testsuite>

tests/DataCollector/EasyAdminDataCollectorTest.php

Lines changed: 0 additions & 77 deletions
This file was deleted.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
3+
namespace EasyCorp\Bundle\EasyAdminBundle\Tests\Inspector;
4+
5+
use Doctrine\ORM\EntityRepository;
6+
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
7+
use EasyCorp\Bundle\EasyAdminBundle\Config\Option\EA;
8+
use EasyCorp\Bundle\EasyAdminBundle\Inspector\DataCollector;
9+
use EasyCorp\Bundle\EasyAdminBundle\Test\AbstractCrudTestCase;
10+
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Controller\CategoryCrudController;
11+
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Controller\SecureDashboardController;
12+
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\Category;
13+
use Symfony\Component\VarDumper\Cloner\Data;
14+
15+
class DataCollectorTest extends AbstractCrudTestCase
16+
{
17+
protected EntityRepository $categories;
18+
19+
protected function setUp(): void
20+
{
21+
parent::setUp();
22+
23+
$this->categories = $this->entityManager->getRepository(Category::class);
24+
25+
$this->client->enableProfiler();
26+
$this->client->setServerParameters(['PHP_AUTH_USER' => 'admin', 'PHP_AUTH_PW' => '1234']);
27+
}
28+
29+
protected function getControllerFqcn(): string
30+
{
31+
return CategoryCrudController::class;
32+
}
33+
34+
protected function getDashboardFqcn(): string
35+
{
36+
return SecureDashboardController::class;
37+
}
38+
39+
public function testIndex(): void
40+
{
41+
$sort = ['name' => 'DESC', 'slug' => 'ASC'];
42+
$this->client->request('GET', $this->generateIndexUrl().'&'.http_build_query([EA::SORT => $sort]));
43+
44+
/** @var DataCollector $collector */
45+
$collector = $this->client->getProfile()->getCollector('easyadmin');
46+
47+
$this->assertTrue($collector->isEasyAdminRequest());
48+
49+
$this->assertSame(
50+
[
51+
'CRUD Controller FQCN' => CategoryCrudController::class,
52+
'CRUD Action' => Action::INDEX,
53+
'Entity ID' => null,
54+
'Sort' => $sort,
55+
],
56+
array_map(static fn (Data $d) => $d->getValue(true), $collector->getData()),
57+
);
58+
}
59+
60+
public function testEdit(): void
61+
{
62+
/** @var Category $category */
63+
$category = $this->categories->findOneBy([]);
64+
65+
$this->client->request('GET', $this->generateEditFormUrl($category->getId()));
66+
67+
/** @var DataCollector $collector */
68+
$collector = $this->client->getProfile()->getCollector('easyadmin');
69+
70+
$this->assertTrue($collector->isEasyAdminRequest());
71+
72+
$this->assertSame(
73+
[
74+
'CRUD Controller FQCN' => CategoryCrudController::class,
75+
'CRUD Action' => Action::EDIT,
76+
'Entity ID' => (string) $category->getId(),
77+
'Sort' => null,
78+
],
79+
array_map(static fn (Data $d) => $d->getValue(true), $collector->getData()),
80+
);
81+
}
82+
83+
public function testReset(): void
84+
{
85+
$this->client->request('GET', $this->generateIndexUrl());
86+
87+
/** @var DataCollector $collector */
88+
$collector = $this->client->getProfile()->getCollector('easyadmin');
89+
90+
$this->assertSame(
91+
[
92+
'CRUD Controller FQCN' => CategoryCrudController::class,
93+
'CRUD Action' => Action::INDEX,
94+
'Entity ID' => null,
95+
'Sort' => null,
96+
],
97+
array_map(static fn (Data $d) => $d->getValue(true), $collector->getData()),
98+
);
99+
100+
$collector->reset();
101+
102+
$this->assertSame(
103+
[],
104+
array_map(static fn (Data $d) => $d->getValue(true), $collector->getData()),
105+
);
106+
}
107+
}

tests/TestApplication/config/packages/framework.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
'default_uuid_version' => 7,
2323
'time_based_uuid_version' => 7,
2424
],
25+
'profiler' => [
26+
'enabled' => true,
27+
'collect' => false,
28+
],
2529
];
2630

2731
if (EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Kernel::VERSION_ID < 60000) {

0 commit comments

Comments
 (0)