1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace ApiClients\Tools\ResourceTestUtilities; |
5
|
|
|
|
6
|
|
|
use GeneratedHydrator\Configuration; |
7
|
|
|
use Phake; |
8
|
|
|
use ApiClients\Foundation\Transport\Client; |
9
|
|
|
use ApiClients\Foundation\Transport\Hydrator; |
10
|
|
|
|
11
|
|
|
abstract class TestCase extends \PHPUnit_Framework_TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
private $tmpDir; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
private $tmpNamespace; |
22
|
|
|
|
23
|
|
|
public function setUp() |
24
|
|
|
{ |
25
|
|
|
parent::setUp(); |
26
|
|
|
$this->tmpDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('api-clients-tests-') . DIRECTORY_SEPARATOR; |
27
|
|
|
mkdir($this->tmpDir, 0777, true); |
28
|
|
|
$this->tmpNamespace = Configuration::DEFAULT_GENERATED_CLASS_NAMESPACE . uniqid('ApiClientsTestNamespace'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function tearDown() |
32
|
|
|
{ |
33
|
|
|
parent::tearDown(); |
34
|
|
|
$this->rmdir($this->tmpDir); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
protected function rmdir($dir) |
38
|
|
|
{ |
39
|
|
|
$directory = dir($dir); |
40
|
|
|
while (false !== ($entry = $directory->read())) { |
41
|
|
|
if (in_array($entry, ['.', '..'])) { |
42
|
|
|
continue; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if (is_dir($dir . $entry)) { |
46
|
|
|
$this->rmdir($dir . $entry . DIRECTORY_SEPARATOR); |
47
|
|
|
continue; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if (is_file($dir . $entry)) { |
51
|
|
|
unlink($dir . $entry); |
52
|
|
|
continue; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
$directory->close(); |
56
|
|
|
rmdir($dir); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
protected function getTmpDir(): string |
60
|
|
|
{ |
61
|
|
|
return $this->tmpDir; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
protected function getRandomNameSpace(): string |
65
|
|
|
{ |
66
|
|
|
return $this->tmpNamespace; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function hydrate($class, $json, $namespace) |
70
|
|
|
{ |
71
|
|
|
return (new Hydrator(Phake::mock(Client::class), [ |
|
|
|
|
72
|
|
|
'resource_namespace' => $namespace, |
73
|
|
|
'resource_hydrator_cache_dir' => $this->getTmpDir(), |
74
|
|
|
'resource_hydrator_namespace' => $this->getRandomNameSpace(), |
75
|
|
|
]))->hydrateFQCN($class, $json); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: