Skip to content

Commit 8218d46

Browse files
committed
FIX: Videorecorder needs to be closed before starting again
1 parent 6bc5328 commit 8218d46

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/VCRBundle.php

+25-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33

44
namespace VCR\VCRBundle;
55

6+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
67
use Symfony\Component\Filesystem\Filesystem;
78
use Symfony\Component\HttpKernel\Bundle\Bundle;
9+
use VCR\Videorecorder;
810

911
class VCRBundle extends Bundle
1012
{
@@ -17,12 +19,33 @@ public function boot(): void
1719
$fs->mkdir($cassettePath);
1820
}
1921

20-
if ($this->container->getParameter('vcr.enabled')) {
21-
$recorder = $this->container->get('vcr.recorder');
22+
if ($this->isEnabled()) {
23+
$recorder = $this->getVideoRecorder();
2224
$cassetteName = $this->container->getParameter('vcr.cassette.name');
2325

2426
$recorder->turnOn();
2527
$recorder->insertCassette($cassetteName);
2628
}
2729
}
30+
31+
public function shutdown(): void
32+
{
33+
if ($this->isEnabled()) {
34+
$this->getVideoRecorder()->turnOff();
35+
}
36+
}
37+
38+
private function isEnabled(): bool
39+
{
40+
try {
41+
return $this->container->getParameter('vcr.enabled');
42+
} catch (InvalidArgumentException $e) {
43+
return false;
44+
}
45+
}
46+
47+
private function getVideoRecorder(): Videorecorder
48+
{
49+
return $this->container->get('vcr.recorder');
50+
}
2851
}

0 commit comments

Comments
 (0)