|
2 | 2 |
|
3 | 3 | namespace Beelab\TestBundle\Test; |
4 | 4 |
|
| 5 | +use Doctrine\Common\DataFixtures\AbstractFixture; |
| 6 | +use Doctrine\Common\DataFixtures\DependentFixtureInterface; |
5 | 7 | use Doctrine\Common\DataFixtures\Executor\ORMExecutor; |
6 | 8 | use Doctrine\Common\DataFixtures\Purger\ORMPurger; |
7 | 9 | use Doctrine\ORM\EntityManagerInterface; |
8 | 10 | use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader as Loader; |
9 | 11 | use Symfony\Bundle\FrameworkBundle\Console\Application; |
| 12 | +use Symfony\Bundle\FrameworkBundle\KernelBrowser; |
10 | 13 | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as SymfonyWebTestCase; |
11 | 14 | use Symfony\Component\BrowserKit\Cookie; |
12 | 15 | use Symfony\Component\Console\Command\Command; |
|
21 | 24 |
|
22 | 25 | abstract class WebTestCase extends SymfonyWebTestCase |
23 | 26 | { |
24 | | - /** |
25 | | - * @var EntityManagerInterface|null |
26 | | - */ |
27 | | - protected static $em; |
| 27 | + protected static ?EntityManagerInterface $em = null; |
28 | 28 |
|
29 | | - /** |
30 | | - * @var \Symfony\Bundle\FrameworkBundle\KernelBrowser |
31 | | - */ |
32 | | - protected static $client; |
| 29 | + protected static ?KernelBrowser $client = null; |
33 | 30 |
|
34 | | - /** |
35 | | - * @var \Doctrine\Common\DataFixtures\AbstractFixture|null |
36 | | - */ |
37 | | - private $fixture; |
| 31 | + private ?AbstractFixture $fixture = null; |
38 | 32 |
|
39 | | - /** |
40 | | - * @var string|null |
41 | | - */ |
42 | | - protected static $authUser; |
| 33 | + protected static ?string $authUser = null; |
43 | 34 |
|
44 | | - /** |
45 | | - * @var string|null |
46 | | - */ |
47 | | - protected static $authPw; |
| 35 | + protected static ?string $authPw = null; |
48 | 36 |
|
49 | 37 | protected function setUp(): void |
50 | 38 | { |
@@ -221,13 +209,15 @@ protected function loadFixtures( |
221 | 209 | */ |
222 | 210 | protected static function assertMailSent(int $num, string $message = ''): void |
223 | 211 | { |
224 | | - if (false !== $profile = self::$client->getProfile()) { |
225 | | - /** @var \Symfony\Bundle\SwiftmailerBundle\DataCollector\MessageDataCollector $collector */ |
226 | | - $collector = $profile->getCollector('swiftmailer'); |
227 | | - self::assertEquals($num, $collector->getMessageCount(), $message); |
228 | | - } else { |
| 212 | + if (false === $profile = self::$client->getProfile()) { |
229 | 213 | self::markTestSkipped('Profiler not enabled.'); |
230 | 214 | } |
| 215 | + /** @var \Symfony\Bundle\SwiftmailerBundle\DataCollector\MessageDataCollector|null $collector */ |
| 216 | + $collector = $profile->getCollector('swiftmailer'); |
| 217 | + if (null === $collector) { |
| 218 | + self::markTestSkipped('Swiftmailer profiler not found.'); |
| 219 | + } |
| 220 | + self::assertEquals($num, $collector->getMessageCount(), $message); |
231 | 221 | } |
232 | 222 |
|
233 | 223 | /** |
@@ -288,6 +278,9 @@ protected function getReference(string $name) |
288 | 278 | if (null === $this->fixture) { |
289 | 279 | throw new \RuntimeException('Load some fixtures before.'); |
290 | 280 | } |
| 281 | + if (!$this->fixture instanceof DependentFixtureInterface) { |
| 282 | + throw new \RuntimeException('Fixture is not dependent.'); |
| 283 | + } |
291 | 284 | if (!$this->fixture->hasReference($name)) { |
292 | 285 | throw new \InvalidArgumentException(\sprintf('Reference "%s" not found.', $name)); |
293 | 286 | } |
|
0 commit comments