Skip to content

Commit 2ff502f

Browse files
authored
Merge pull request #9 from php-http/test-fixes
Fix tests
2 parents 1202f7f + f360aa5 commit 2ff502f

File tree

3 files changed

+54
-21
lines changed

3 files changed

+54
-21
lines changed

.php_cs.dist

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@ $finder = PhpCsFixer\Finder::create()
1212
;
1313
return PhpCsFixer\Config::create()
1414
->setRules([
15-
'@PSR2' => true,
1615
'@Symfony' => true,
17-
'array_syntax' => [
18-
'syntax' => 'short',
19-
],
20-
'no_empty_phpdoc' => true,
21-
'no_superfluous_phpdoc_tags' => true,
16+
'@Symfony:risky' => true,
2217
])
18+
->setRiskyAllowed(true)
2319
->setFinder($finder);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"php": "^7.1",
1515
"guzzlehttp/psr7": "^1.4",
1616
"php-http/client-common": "^2.0",
17-
"psr/log": "^1.0",
17+
"psr/log": "^1.1",
1818
"symfony/filesystem": "^3.4|^4.0|^5.0",
1919
"symfony/options-resolver": "^3.4|^4.0|^5.0"
2020
},

tests/Recorder/FilesystemRecorderTest.php

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,63 @@
66

77
use GuzzleHttp\Psr7\Response;
88
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;
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

Comments
 (0)