Skip to content

Commit 23f8bbb

Browse files
Add test to check that the database backup has been used
1 parent 446e22e commit 23f8bbb

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

tests/Test/WebTestCaseConfigMysqlCacheDbTest.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,83 @@ protected static function getKernelClass(): string
3838
{
3939
return AppConfigMysqlKernelCacheDb::class;
4040
}
41+
42+
/**
43+
* @group mysql
44+
*/
45+
public function testLoadFixturesAndCheckBackup(): void
46+
{
47+
$this->loadFixtures([
48+
'Liip\FunctionalTestBundle\Tests\App\DataFixtures\ORM\LoadUserData',
49+
]);
50+
51+
// Load data from database
52+
$em = $this->getContainer()
53+
->get('doctrine.orm.entity_manager');
54+
55+
$users = $em->getRepository('LiipFunctionalTestBundle:User')
56+
->findAll();
57+
58+
// Check that all User have been saved to database
59+
$this->assertCount(
60+
2,
61+
$users
62+
);
63+
64+
/** @var \Liip\FunctionalTestBundle\Tests\App\Entity\User $user1 */
65+
$user1 = $em->getRepository('LiipFunctionalTestBundle:User')
66+
->findOneBy([
67+
'id' => 1,
68+
]);
69+
70+
$this->assertSame(
71+
'foo@bar.com',
72+
$user1->getEmail()
73+
);
74+
75+
$this->assertTrue(
76+
$user1->getEnabled()
77+
);
78+
79+
// Store salt for later use
80+
$salt = $user1->getSalt();
81+
82+
// Clean database
83+
$this->loadFixtures();
84+
85+
$users = $em->getRepository('LiipFunctionalTestBundle:User')
86+
->findAll();
87+
88+
// Check that all User have been removed from database
89+
$this->assertCount(
90+
0,
91+
$users
92+
);
93+
94+
// Load fixtures again
95+
$this->loadFixtures([
96+
'Liip\FunctionalTestBundle\Tests\App\DataFixtures\ORM\LoadUserData',
97+
]);
98+
99+
$users = $em->getRepository('LiipFunctionalTestBundle:User')
100+
->findAll();
101+
102+
// Check that all User have been loaded again in database
103+
$this->assertCount(
104+
2,
105+
$users
106+
);
107+
108+
$user1 = $em->getRepository('LiipFunctionalTestBundle:User')
109+
->findOneBy([
110+
'id' => 1,
111+
]);
112+
113+
// Salt is a random string, if it's the same as before it means that the backup has been saved and loaded
114+
// successfully
115+
$this->assertSame(
116+
$salt,
117+
$user1->getSalt()
118+
);
119+
}
41120
}

0 commit comments

Comments
 (0)