Skip to content

Commit

Permalink
FIX: Videorecorder needs to be closed before starting again
Browse files Browse the repository at this point in the history
  • Loading branch information
higidi committed Dec 15, 2022
1 parent 6bc5328 commit 8218d46
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/VCRBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

namespace VCR\VCRBundle;

use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use VCR\Videorecorder;

class VCRBundle extends Bundle
{
Expand All @@ -17,12 +19,33 @@ public function boot(): void
$fs->mkdir($cassettePath);
}

if ($this->container->getParameter('vcr.enabled')) {
$recorder = $this->container->get('vcr.recorder');
if ($this->isEnabled()) {
$recorder = $this->getVideoRecorder();
$cassetteName = $this->container->getParameter('vcr.cassette.name');

$recorder->turnOn();
$recorder->insertCassette($cassetteName);
}
}

public function shutdown(): void
{
if ($this->isEnabled()) {
$this->getVideoRecorder()->turnOff();
}
}

private function isEnabled(): bool
{
try {
return $this->container->getParameter('vcr.enabled');
} catch (InvalidArgumentException $e) {
return false;
}
}

private function getVideoRecorder(): Videorecorder
{
return $this->container->get('vcr.recorder');
}
}

0 comments on commit 8218d46

Please sign in to comment.