-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #476 from alexislefebvre/2.x-add-tests-with-mysql-…
…database-cache 2.x: Fix issues with MySQL database backup
- Loading branch information
Showing
14 changed files
with
233 additions
and
75 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
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 |
---|---|---|
|
@@ -13,15 +13,6 @@ | |
|
||
namespace Liip\FunctionalTestBundle\Tests\AppConfigLeanFramework; | ||
|
||
/* | ||
* This file is part of the Liip/FunctionalTestBundle | ||
* | ||
* (c) Lukas Kahwe Smith <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
use Liip\FunctionalTestBundle\Tests\App\AppKernel; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
|
||
|
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 |
---|---|---|
|
@@ -13,15 +13,6 @@ | |
|
||
namespace Liip\FunctionalTestBundle\Tests\AppConfigMysql; | ||
|
||
/* | ||
* This file is part of the Liip/FunctionalTestBundle | ||
* | ||
* (c) Lukas Kahwe Smith <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
use Liip\FunctionalTestBundle\Tests\App\AppKernel; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
|
||
|
32 changes: 32 additions & 0 deletions
32
tests/AppConfigMysqlCacheDb/AppConfigMysqlKernelCacheDb.php
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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Liip/FunctionalTestBundle | ||
* | ||
* (c) Lukas Kahwe Smith <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Liip\FunctionalTestBundle\Tests\AppConfigMysqlCacheDb; | ||
|
||
use Liip\FunctionalTestBundle\Tests\AppConfigMysql\AppConfigMysqlKernel; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
|
||
class AppConfigMysqlKernelCacheDb extends AppConfigMysqlKernel | ||
{ | ||
/** | ||
* Load the config.yml from the current directory. | ||
*/ | ||
public function registerContainerConfiguration(LoaderInterface $loader): void | ||
{ | ||
// Load the default file. | ||
parent::registerContainerConfiguration($loader); | ||
|
||
// Load the file with MySQL configuration | ||
$loader->load(__DIR__.'/config.yml'); | ||
} | ||
} |
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,5 @@ | ||
# inherits configuration from ../AppConfigMysql/config.yml | ||
|
||
liip_functional_test: | ||
cache_db: | ||
mysql: liip_functional_test.services_database_backup.mysql |
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 |
---|---|---|
|
@@ -13,15 +13,6 @@ | |
|
||
namespace Liip\FunctionalTestBundle\Tests\AppConfigPhpcr; | ||
|
||
/* | ||
* This file is part of the Liip/FunctionalTestBundle | ||
* | ||
* (c) Lukas Kahwe Smith <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
use Liip\FunctionalTestBundle\Tests\App\AppKernel; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
|
||
|
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,120 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Liip/FunctionalTestBundle | ||
* | ||
* (c) Lukas Kahwe Smith <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Liip\FunctionalTestBundle\Tests\Test; | ||
|
||
use Liip\FunctionalTestBundle\Tests\AppConfigMysqlCacheDb\AppConfigMysqlKernelCacheDb; | ||
|
||
/** | ||
* Test MySQL database with database caching enabled. | ||
* | ||
* The following tests require a connection to a MySQL database, | ||
* they are disabled by default (see phpunit.xml.dist). | ||
* | ||
* In order to run them, you have to set the MySQL connection | ||
* parameters in the Tests/AppConfigMysql/config.yml file and | ||
* add “--exclude-group ""” when running PHPUnit. | ||
* | ||
* Use Tests/AppConfigMysql/AppConfigMysqlKernelCacheDb.php instead of | ||
* Tests/App/AppKernel.php. | ||
* So it must be loaded in a separate process. | ||
* | ||
* @runTestsInSeparateProcesses | ||
* @preserveGlobalState disabled | ||
*/ | ||
class WebTestCaseConfigMysqlCacheDbTest extends WebTestCaseConfigMysqlTest | ||
{ | ||
protected static function getKernelClass(): string | ||
{ | ||
return AppConfigMysqlKernelCacheDb::class; | ||
} | ||
|
||
/** | ||
* @group mysql | ||
*/ | ||
public function testLoadFixturesAndCheckBackup(): void | ||
{ | ||
$this->loadFixtures([ | ||
'Liip\FunctionalTestBundle\Tests\App\DataFixtures\ORM\LoadUserData', | ||
]); | ||
|
||
// Load data from database | ||
$em = $this->getContainer() | ||
->get('doctrine.orm.entity_manager'); | ||
|
||
$users = $em->getRepository('LiipFunctionalTestBundle:User') | ||
->findAll(); | ||
|
||
// Check that all User have been saved to database | ||
$this->assertCount( | ||
2, | ||
$users | ||
); | ||
|
||
/** @var \Liip\FunctionalTestBundle\Tests\App\Entity\User $user1 */ | ||
$user1 = $em->getRepository('LiipFunctionalTestBundle:User') | ||
->findOneBy([ | ||
'id' => 1, | ||
]); | ||
|
||
$this->assertSame( | ||
'[email protected]', | ||
$user1->getEmail() | ||
); | ||
|
||
$this->assertTrue( | ||
$user1->getEnabled() | ||
); | ||
|
||
// Store salt for later use | ||
$salt = $user1->getSalt(); | ||
|
||
// Clean database | ||
$this->loadFixtures(); | ||
|
||
$users = $em->getRepository('LiipFunctionalTestBundle:User') | ||
->findAll(); | ||
|
||
// Check that all User have been removed from database | ||
$this->assertCount( | ||
0, | ||
$users | ||
); | ||
|
||
// Load fixtures again | ||
$this->loadFixtures([ | ||
'Liip\FunctionalTestBundle\Tests\App\DataFixtures\ORM\LoadUserData', | ||
]); | ||
|
||
$users = $em->getRepository('LiipFunctionalTestBundle:User') | ||
->findAll(); | ||
|
||
// Check that all User have been loaded again in database | ||
$this->assertCount( | ||
2, | ||
$users | ||
); | ||
|
||
$user1 = $em->getRepository('LiipFunctionalTestBundle:User') | ||
->findOneBy([ | ||
'id' => 1, | ||
]); | ||
|
||
// Salt is a random string, if it's the same as before it means that the backup has been saved and loaded | ||
// successfully | ||
$this->assertSame( | ||
$salt, | ||
$user1->getSalt() | ||
); | ||
} | ||
} |
Oops, something went wrong.