-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delete data from database before running tests
- Loading branch information
1 parent
497ed50
commit d49fca1
Showing
3 changed files
with
26 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,28 +19,14 @@ | |
|
||
trait LiipAcmeFixturesTrait | ||
{ | ||
public function schemaUpdate(): void | ||
{ | ||
// Create database | ||
$kernel = $this->getContainer()->get('kernel'); | ||
|
||
$application = new Application($kernel); | ||
|
||
$command = $application->find('doctrine:schema:update'); | ||
$commandTester = new CommandTester($command); | ||
$return = $commandTester->execute([ | ||
'--force' => true, | ||
]); | ||
|
||
$this->assertSame(0, $return, $commandTester->getDisplay()); | ||
} | ||
|
||
public function loadTestFixtures(): User | ||
{ | ||
$this->resetSchema(); | ||
|
||
$user1 = new User(); | ||
$user1->setId(1); | ||
$user1->setName('foo bar'); | ||
$user1->setEmail('foo@bar.com'); | ||
$user1->setEmail('foo@example'); | ||
$user1->setPassword('12341234'); | ||
$user1->setAlgorithm('plaintext'); | ||
$user1->setEnabled(true); | ||
|
@@ -52,10 +38,33 @@ public function loadTestFixtures(): User | |
$user2 = clone $user1; | ||
|
||
$user2->setId(2); | ||
$user2->setName('alice bob'); | ||
$user2->setEmail('[email protected]'); | ||
|
||
$manager->persist($user2); | ||
$manager->flush(); | ||
|
||
return $user1; | ||
} | ||
|
||
private function resetSchema(): void | ||
{ | ||
// Create database | ||
$kernel = $this->getContainer()->get('kernel'); | ||
|
||
$application = new Application($kernel); | ||
|
||
$command = $application->find('doctrine:schema:update'); | ||
$commandTester = new CommandTester($command); | ||
$return = $commandTester->execute([ | ||
'--force' => true, | ||
]); | ||
|
||
$this->assertSame(0, $return, $commandTester->getDisplay()); | ||
|
||
$manager = $this->getContainer()->get('doctrine')->getManager(); | ||
|
||
$connection = $manager->getConnection(); | ||
$connection->query('DELETE FROM liip_user'); | ||
} | ||
} |