-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
106 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Tests\Functional\Neusta\Pimcore\TestingFramework; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
use Neusta\Pimcore\TestingFramework\Database\PimcoreDatabaseResetter; | ||
use Pimcore\Console\Application; | ||
use Pimcore\Test\KernelTestCase; | ||
use Pimcore\Version; | ||
|
||
final class ResetDatabaseTest extends KernelTestCase | ||
{ | ||
/** | ||
* @test | ||
* | ||
* @dataProvider databaseResetModeProvider | ||
*/ | ||
public function it_resets_database(string $dumpLocation): void | ||
{ | ||
$_SERVER['DATABASE_DUMP_LOCATION'] = $dumpLocation; | ||
|
||
$application = new Application(self::bootKernel()); | ||
$application->setAutoExit(false); | ||
|
||
/** @var ManagerRegistry $registry */ | ||
$registry = self::getContainer()->get('doctrine'); | ||
|
||
/** @var Connection $connection */ | ||
$connection = $registry->getConnection(); | ||
|
||
$resetter = new PimcoreDatabaseResetter($application, $registry); | ||
$resetter->resetDatabase(); | ||
|
||
self::assertCount(1, $connection->fetchAllNumeric('SELECT * FROM assets')); | ||
self::assertCount(1, $connection->fetchAllNumeric('SELECT * FROM documents')); | ||
self::assertCount(1, $connection->fetchAllNumeric('SELECT * FROM objects')); | ||
self::assertCount(2, $users = $connection->fetchAllAssociative('SELECT * FROM users')); | ||
self::assertSame('system', $users[0]['name']); | ||
self::assertSame('admin', $users[1]['name']); | ||
} | ||
|
||
public function databaseResetModeProvider(): iterable | ||
{ | ||
yield 'Default mode' => ['']; | ||
yield 'Dump mode' => [self::isPimcore10() ? 'dump-10' : 'dump']; | ||
} | ||
|
||
private static function isPimcore10(): bool | ||
{ | ||
return !method_exists(Version::class, 'getMajorVersion') || 10 === Version::getMajorVersion(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
INSERT INTO `assets` | ||
VALUES (1, 0, 'folder', '', '/', NULL, 1710529075, 1710529075, 1, 1, NULL, 0, 0); | ||
|
||
INSERT INTO `documents` | ||
VALUES (1, 0, 'page', '', '/', 999999, 1, 1710529075, 1710529075, 1, 1, 0); | ||
|
||
INSERT INTO `documents_page` | ||
VALUES (1, 'App\\Controller\\DefaultController::defaultAction', '', '', '', '', NULL, NULL, '', NULL, NULL, NULL); | ||
|
||
INSERT INTO `objects` | ||
VALUES (1, 0, 'folder', '', '/', 999999, 1, 1710529075, 1710529075, 1, 1, NULL, NULL, NULL, NULL, 0); | ||
|
||
INSERT INTO `users` (id, parentId, type, name, admin, active) | ||
VALUES (0, 0, 'user', 'system', 1, 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
INSERT INTO `assets` | ||
VALUES (1, 0, 'folder', '', '/', NULL, 1710529075, 1710529075, NULL, 1, 1, NULL, 0, 0); | ||
|
||
INSERT INTO `documents` | ||
VALUES (1, 0, 'page', '', '/', 999999, 1, 1710529075, 1710529075, 1, 1, 0); | ||
|
||
INSERT INTO `documents_page` | ||
VALUES (1, 'App\\Controller\\DefaultController::defaultAction', '', '', '', NULL, NULL, '', NULL, NULL, NULL); | ||
|
||
INSERT INTO `objects` | ||
VALUES (1, 0, 'folder', '', '/', 999999, 1, 1710529075, 1710529075, 1, 1, NULL, NULL, NULL, NULL, 0); |