66
77use GuzzleHttp \Psr7 \Response ;
88use Http \Client \Plugin \Vcr \Recorder \FilesystemRecorder ;
9- use PHPUnit \Framework \MockObject \ MockObject ;
10- use Psr \Log \LoggerInterface ;
11- use Symfony \Component \Filesystem \Tests \ FilesystemTestCase ;
9+ use PHPUnit \Framework \TestCase ;
10+ use Psr \Log \Test \ TestLogger ;
11+ use Symfony \Component \Filesystem \Filesystem ;
1212
1313/**
1414 * @internal
1515 */
16- class FilesystemRecorderTest extends FilesystemTestCase
16+ class FilesystemRecorderTest extends TestCase
1717{
1818 /**
1919 * @var FilesystemRecorder
2020 */
2121 private $ recorder ;
2222
23+ /**
24+ * @var int
25+ */
26+ private $ umask ;
27+
28+ /**
29+ * @var Filesystem
30+ */
31+ private $ filesystem ;
32+
33+ /**
34+ * @var string
35+ */
36+ private $ workspace ;
37+
38+ /**
39+ * @var TestLogger
40+ */
41+ private $ logger ;
42+
43+ /**
44+ * @see https://github.com/symfony/symfony/blob/5.x/src/Symfony/Component/Filesystem/Tests/FilesystemTestCase.php
45+ */
2346 protected function setUp (): void
2447 {
25- parent ::setUp ();
48+ $ this ->umask = umask (0 );
49+ $ this ->filesystem = new Filesystem ();
50+ $ this ->workspace = sys_get_temp_dir ().'/ ' .microtime (true ).'. ' .mt_rand ();
51+ mkdir ($ this ->workspace , 0777 , true );
52+ $ this ->workspace = realpath ($ this ->workspace );
53+ $ this ->logger = new TestLogger ();
2654
2755 $ this ->recorder = new FilesystemRecorder ($ this ->workspace , $ this ->filesystem );
56+ $ this ->recorder ->setLogger ($ this ->logger );
2857 }
2958
3059 public function testReplay (): void
3160 {
32- /** @var LoggerInterface|MockObject $logger */
33- $ logger = $ this ->createMock (LoggerInterface::class);
34-
35- $ logger ->expects ($ this ->once ())
36- ->method ('debug ' )
37- ->with ('[VCR-PLUGIN][FilesystemRecorder] Unable to replay {filename} ' , ['filename ' => "$ this ->workspace /file_not_found.txt " ]);
38-
39- $ this ->recorder ->setLogger ($ logger );
40-
4161 $ this ->assertNull ($ this ->recorder ->replay ('file_not_found ' ), 'No response should be returned ' );
62+ $ this ->assertTrue (
63+ $ this ->logger ->hasDebug ('[VCR-PLUGIN][FilesystemRecorder] Unable to replay {filename} ' ),
64+ 'Cache miss should be logged '
65+ );
4266 }
4367
4468 public function testRecord (): void
@@ -56,4 +80,17 @@ public function testRecord(): void
5680 $ this ->assertSame ($ original ->getHeaders (), $ replayed ->getHeaders ());
5781 $ this ->assertSame ((string ) $ original ->getBody (), (string ) $ replayed ->getBody ());
5882 }
83+
84+ protected function tearDown (): void
85+ {
86+ if (!empty ($ this ->longPathNamesWindows )) {
87+ foreach ($ this ->longPathNamesWindows as $ path ) {
88+ exec ('DEL ' .$ path );
89+ }
90+ $ this ->longPathNamesWindows = [];
91+ }
92+
93+ $ this ->filesystem ->remove ($ this ->workspace );
94+ umask ($ this ->umask );
95+ }
5996}
0 commit comments