|
4 | 4 |
|
5 | 5 | use Liip\FunctionalTestBundle\Test\WebTestCase; |
6 | 6 | use Ojs\CoreBundle\Service\SampleObjectLoader; |
| 7 | +use Ojs\UserBundle\Entity\User; |
7 | 8 | use Symfony\Bundle\FrameworkBundle\Console\Application; |
8 | 9 | use Symfony\Bundle\FrameworkBundle\Client; |
9 | 10 | use Doctrine\ORM\EntityManager; |
@@ -53,6 +54,11 @@ abstract class BaseTestSetup extends WebTestCase |
53 | 54 | */ |
54 | 55 | protected static $isFirstTest = true; |
55 | 56 |
|
| 57 | + /** |
| 58 | + * @var bool | User |
| 59 | + */ |
| 60 | + protected static $testAdminUser = false; |
| 61 | + |
56 | 62 | protected function setUp() |
57 | 63 | { |
58 | 64 | static::$kernel = static::createKernel(); |
@@ -153,8 +159,20 @@ protected function runConsole($command, Array $options = array()) |
153 | 159 | return $this->app->run(new ArrayInput($options)); |
154 | 160 | } |
155 | 161 |
|
156 | | - protected function logIn($username = 'admin', $password = 'admin') |
| 162 | + protected function logIn($username = null, $password = 'admin') |
157 | 163 | { |
| 164 | + if($username === null && self::$testAdminUser === false){ |
| 165 | + self::$testAdminUser = $this->sampleObjectLoader->loadAdminUser(); |
| 166 | + $username = self::$testAdminUser->getUsername(); |
| 167 | + |
| 168 | + echo 'Created Admin User -> username -> '. $username."\n"; |
| 169 | + }elseif(self::$testAdminUser instanceof User){ |
| 170 | + |
| 171 | + $username = self::$testAdminUser->getUsername(); |
| 172 | + }else{ |
| 173 | + $username = 'admin'; |
| 174 | + } |
| 175 | + |
158 | 176 | $this->client->setServerParameter('PHP_AUTH_USER', $username); |
159 | 177 | $this->client->setServerParameter('PHP_AUTH_PW', $password); |
160 | 178 | } |
|
0 commit comments