/
FixtureFactory.php
64 lines (55 loc) · 1.9 KB
/
FixtureFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace ScriptFUSIONTest\Porter\Provider\Steam;
use Amp\Promise;
use Mockery\MockInterface;
use Psr\Container\ContainerInterface;
use ScriptFUSION\Porter\Porter;
use ScriptFUSION\Porter\Provider\StaticDataProvider;
use ScriptFUSION\Porter\Provider\Steam\Cookie\SecureLoginCookie;
use ScriptFUSION\Porter\Provider\Steam\Resource\Curator\CuratorSession;
use ScriptFUSION\Porter\Provider\Steam\SteamProvider;
use ScriptFUSION\StaticClass;
use function Amp\call;
final class FixtureFactory
{
use StaticClass;
private static $savedSession;
public static function createPorter(): Porter
{
return new Porter(self::mockPorterContainer());
}
/**
* @return ContainerInterface|MockInterface
*/
public static function mockPorterContainer(): ContainerInterface
{
return \Mockery::mock(ContainerInterface::class)
->shouldReceive('has')
->with(SteamProvider::class)
->andReturn(true)
->shouldReceive('has')
->with(StaticDataProvider::class)
->andReturn(false)
->shouldReceive('get')
->with(SteamProvider::class)
->andReturn(new SteamProvider)
->byDefault()
->getMock()
;
}
public static function createSession(Porter $porter): Promise
{
if (self::$savedSession) {
return self::$savedSession;
}
return self::$savedSession = call(static function () use ($porter): \Generator {
if (isset($_SERVER['STEAM_USER'], $_SERVER['STEAM_PASSWORD'])) {
return yield CuratorSession::create($porter, $_SERVER['STEAM_USER'], $_SERVER['STEAM_PASSWORD']);
}
return yield CuratorSession::createFromCookie(
SecureLoginCookie::create($_SERVER['STEAM_COOKIE']),
$porter
);
});
}
}