-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove resetDatabase trait from tests
- Loading branch information
1 parent
fcf1555
commit cc2b417
Showing
8 changed files
with
155 additions
and
122 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Starfleet Project. | ||
* | ||
* (c) Starfleet <[email protected]> | ||
* | ||
* For the full copyright and license information, | ||
* please view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace App\Tests\Controller\UserAccount; | ||
|
||
use App\Entity\User; | ||
use App\Factory\UserFactory; | ||
use Doctrine\Common\DataFixtures\Purger\ORMPurger; | ||
use Symfony\Bundle\FrameworkBundle\KernelBrowser; | ||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
use Zenstruck\Foundry\Test\Factories; | ||
|
||
abstract class AbstractBaseFactories extends WebTestCase | ||
{ | ||
use Factories; | ||
|
||
private ?KernelBrowser $client = null; | ||
|
||
protected function setUp(): void | ||
{ | ||
$purger = new ORMPurger($this->getEntityManager()); | ||
$purger->purge(); | ||
$this->generateData(); | ||
} | ||
|
||
protected function getClient(?User $user = null) | ||
{ | ||
if (!$this->client) { | ||
$this->ensureKernelShutdown(); | ||
$this->client = $this->createClient(); | ||
$this->client->followRedirects(); | ||
$this->client->loginUser($user ?: $this->getTestUser()); | ||
} | ||
|
||
return $this->client; | ||
} | ||
|
||
protected function getTestUser() | ||
{ | ||
$user = UserFactory::repository()->findOneBy([ | ||
'email' => '[email protected]', | ||
]); | ||
|
||
if (!$user) { | ||
$user = UserFactory::createOne([ | ||
'name' => 'Starfleet User', | ||
'email' => '[email protected]', | ||
'password' => 'password', | ||
]); | ||
} | ||
|
||
$user = $user->object(); | ||
|
||
return $user; | ||
} | ||
|
||
protected function getAdminUser() | ||
{ | ||
$user = $this->getTestUser() | ||
->addRole('ROLE_ADMIN') | ||
->setName('Starfleet Admin') | ||
->setEmail('[email protected]') | ||
->setPassword('password') | ||
; | ||
|
||
$this->getEntityManager()->flush(); | ||
|
||
return $user; | ||
} | ||
|
||
/** | ||
* This method must create all the entities your test will need. | ||
*/ | ||
abstract protected function generateData(); | ||
|
||
private function getEntityManager() | ||
{ | ||
return $this->getContainer()->get('doctrine')->getManager(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.