Completed
Push — dev ( 735e11...beed57 )
by Julien
20:45
created

AbstractApplicationTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 107
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createApplication() 0 23 1
B setUp() 0 33 1
A tearDown() 0 7 1
A createOAuth2Token() 0 4 1
1
<?php
2
3
namespace Tests\Eole\RestApi;
4
5
use Silex\WebTestCase;
6
use Eole\Core\Model\Player;
7
use Eole\Core\Model\Game;
8
use Eole\Core\Service\PlayerManager;
9
use Eole\RestApi\Application;
10
use Tests\Eole\RestApi\stubs\OAuth\ClientStorageMock;
11
use Tests\Eole\RestApi\stubs\OAuth\ResourceServerMock;
12
13
abstract class AbstractApplicationTest extends WebTestCase
14
{
15
    /**
16
     * @var PlayerManager
17
     */
18
    protected $playerManager;
19
20
    /**
21
     * @var Game[]
22
     */
23
    protected $games;
24
25
    /**
26
     * @var Player
27
     */
28
    protected $player;
29
30
    /**
31
     * @var Player
32
     */
33
    protected $player2;
34
35
    /**
36
     * {@InheritDoc}
37
     */
38
    public function createApplication()
39
    {
40
        $app = new Application(array(
41
            'project.root' => __DIR__.'/../../..',
42
            'env' => 'test',
43
            'debug' => true,
44
        ));
45
46
        $app['sandstone.oauth.storage.client'] = function () {
47
            return new ClientStorageMock();
48
        };
49
50
        $app['sandstone.oauth.resource_server'] = function () use ($app) {
51
            return new ResourceServerMock(
52
                $app['sandstone.oauth.storage.session'],
53
                $app['sandstone.oauth.storage.access_token'],
54
                $app['sandstone.oauth.storage.client'],
55
                $app['sandstone.oauth.storage.scope']
56
            );
57
        };
58
59
        return $app;
60
    }
61
62
    /**
63
     * {@InheritDoc}
64
     */
65
    protected function setUp()
66
    {
67
        parent::setUp();
68
69
        $this->playerManager = $this->app['eole.player_manager'];
70
71
        $this->app['db']->executeQuery('delete from eole_core_player');
72
        $this->app['db']->executeQuery('delete from eole_core_game');
73
74
        $player = new Player();
75
        $player->setUsername('existing-player');
76
        $this->playerManager->updatePassword($player, 'good-password');
77
78
        $player2 = new Player();
79
        $player2->setUsername('another-existing-player');
80
        $this->playerManager->updatePassword($player2, 'good-password');
81
82
        $game0 = new Game();
83
        $game0->setName('game-0');
84
85
        $game1 = new Game();
86
        $game1->setName('game-1');
87
88
        $this->games = array($game0, $game1);
89
        $this->player = $player;
90
        $this->player2 = $player2;
91
92
        $this->app['orm.em']->persist($game0);
93
        $this->app['orm.em']->persist($game1);
94
        $this->app['orm.em']->persist($player);
95
        $this->app['orm.em']->persist($player2);
96
        $this->app['orm.em']->flush();
97
    }
98
99
    /**
100
     * {@InheritDoc}
101
     */
102
    protected function tearDown()
103
    {
104
        parent::tearDown();
105
106
        $this->app['db']->executeQuery('delete from eole_core_player');
107
        $this->app['db']->executeQuery('delete from eole_core_game');
108
    }
109
110
    /**
111
     * @param string $username
112
     *
113
     * @return string
114
     */
115
    protected static function createOAuth2Token($username)
116
    {
117
        return 'Bearer goodtoken-'.$username;
118
    }
119
}
120