6
6
7
7
use GuzzleHttp \Psr7 \Response ;
8
8
use 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 ;
12
12
13
13
/**
14
14
* @internal
15
15
*/
16
- class FilesystemRecorderTest extends FilesystemTestCase
16
+ class FilesystemRecorderTest extends TestCase
17
17
{
18
18
/**
19
19
* @var FilesystemRecorder
20
20
*/
21
21
private $ recorder ;
22
22
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
+ */
23
46
protected function setUp (): void
24
47
{
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 ();
26
54
27
55
$ this ->recorder = new FilesystemRecorder ($ this ->workspace , $ this ->filesystem );
56
+ $ this ->recorder ->setLogger ($ this ->logger );
28
57
}
29
58
30
59
public function testReplay (): void
31
60
{
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
-
41
61
$ 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
+ );
42
66
}
43
67
44
68
public function testRecord (): void
@@ -56,4 +80,17 @@ public function testRecord(): void
56
80
$ this ->assertSame ($ original ->getHeaders (), $ replayed ->getHeaders ());
57
81
$ this ->assertSame ((string ) $ original ->getBody (), (string ) $ replayed ->getBody ());
58
82
}
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
+ }
59
96
}
0 commit comments