-
Notifications
You must be signed in to change notification settings - Fork 0
/
RepoManagerTest.php
224 lines (198 loc) · 7.64 KB
/
RepoManagerTest.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
/*
* This file is part of the SnideTravinizer bundle.
*
* (c) Pascal DENIS <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Snide\Bundle\TravinizerBundle\Tests\Manager;
use Buzz\Browser;
use Doctrine\Common\Cache\ArrayCache;
use Snide\Bundle\TravinizerBundle\Helper\GithubHelper;
use Snide\Bundle\TravinizerBundle\Loader\ComposerLoader;
use Snide\Bundle\TravinizerBundle\Loader\ScrutinizerLoader;
use Snide\Bundle\TravinizerBundle\Loader\TravisLoader;
use Snide\Bundle\TravinizerBundle\Loader\VersionEyeLoader;
use Snide\Bundle\TravinizerBundle\Manager\CacheManager;
use Snide\Bundle\TravinizerBundle\Manager\RepoManager;
use Snide\Bundle\TravinizerBundle\Model\Repo;
use Snide\Bundle\TravinizerBundle\Reader\ComposerReader;
use Snide\Bundle\TravinizerBundle\Repository\Yaml\RepoRepository;
use Snide\Scrutinizer\Client as ScClient;
use Snide\Travis\Client as TravisClient;
/**
* Class RepoManagerTest
*
* @author Pascal DENIS <[email protected]>
*/
class RepoManagerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var RepoManager
*/
protected $object;
protected $class;
protected $repository;
protected $travisLoader;
protected $filename;
protected $scrutinizerLoader;
protected $composerReader;
protected $versionEyeLoader;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->filename = '/tmp/filename.yml';
$this->class = 'Snide\\Bundle\\TravinizerBundle\\Model\\Repo';
$this->repository = new RepoRepository($this->class, $this->filename);
$this->travisLoader = new TravisLoader(new TravisClient(), new CacheManager(new ArrayCache()));
$this->scrutinizerLoader = new ScrutinizerLoader(new ScClient(), new CacheManager(new ArrayCache()));
$this->composerReader = new ComposerReader(new CacheManager(new ArrayCache()), new GithubHelper());
$this->versionEyeLoader = new VersionEyeLoader(new ComposerLoader(new GithubHelper()), new \Snide\VersionEye\Client());
$this->object = new RepoManager($this->repository, $this->class, $this->travisLoader, $this->scrutinizerLoader, $this->composerReader, $this->versionEyeLoader);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
if (file_exists($this->filename)) {
unlink($this->filename);
}
}
public function testConstruct()
{
$this->object = new RepoManager($this->repository, $this->class, $this->travisLoader, $this->scrutinizerLoader, $this->composerReader, $this->versionEyeLoader);
$this->assertEquals($this->repository, $this->object->getRepository());
$this->assertInstanceOf($this->class, $this->object->createNew());
}
public function testCreate()
{
$repo = $this->object->createNew();
$repo->setSlug('pdenis/monitoring');
$repo->setType('g/3');
$repos = $this->object->findAll();
$repo->setId(sizeof($repos) + 1);
$repos[] = $repo;
$this->object->create($repo);
$this->assertEquals(sizeof($repos), sizeof($this->object->findAll()));
}
public function testDelete()
{
$repo = $this->object->createNew();
$repo->setSlug('pdenis/scrutinizer-client');
$repo->setType('g');
$this->object->create($repo);
$repo->setId(1);
$repoTwo = $this->object->createNew();
$repoTwo->setSlug('pdenis/scrutinizer-client');
$repoTwo->setType('g');
$this->object->create($repoTwo);
$repoTwo->setId(2);
$repos = $this->object->findAll();
$this->object->delete($repos[0]);
unset($repos[0]);
$this->assertEquals(sizeof($repos), sizeof($this->object->findAll()));
}
public function testLoadPackagistInfos()
{
$repo = new Repo();
$repo->setSlug('pdenis/monitoring');
$this->object->loadPackagistInfos($repo);
$this->assertEquals('snide/monitoring', $repo->getPackagistSlug());
$this->assertEquals(
array(array('name' => 'Pascal DENIS', 'email' => '[email protected]')),
$repo->getAuthors()
);
}
public function testFind()
{
$repo = $this->object->createNew();
$repo->setSlug('pdenis/scrutinizer-client');
$repo->setType('g');
$this->object->create($repo);
$repo->setId(1);
$repoTwo = $this->object->createNew();
$repoTwo->setSlug('pdenis/scrutinizer-client');
$repoTwo->setType('g');
$this->object->create($repoTwo);
$repoTwo->setId(2);
$this->assertNull($this->object->find(-1));
$repos = $this->object->findAll();
$this->assertNotNull($this->object->find($repos[1]->getId()));
}
public function testFindBySlug()
{
$repo = $this->object->createNew();
$repo->setSlug('pdenis/scrutinizer-client');
$repo->setType('g');
$this->object->create($repo);
$repo->setId(1);
$repoTwo = $this->object->createNew();
$repoTwo->setSlug('pdenis/scrutinizer-client');
$repoTwo->setType('g');
$this->object->create($repoTwo);
$this->assertNull($this->object->find('unknown'));
$repos = $this->object->findAll();
$this->assertNotNull($this->object->findBySlug($repos[1]->getSlug()));
}
public function testIsExists()
{
$repo = $this->object->createNew();
$repo->setSlug('pdenis/scrutinizer-client');
$repo->setType('g');
$this->object->create($repo);
$repo->setId(1);
$repoTwo = $this->object->createNew();
$repoTwo->setSlug('pdenis/scrutinizer-client');
$repoTwo->setType('g');
$this->object->create($repoTwo);
$repo->setId(10);
$this->assertTrue($this->object->isExists($repo));
$repo->setSlug('anotherSlug');
$this->assertFalse($this->object->isExists($repo));
}
public function testFindAll()
{
$this->assertEquals(array(), $this->object->findAll());
$repo = $this->object->createNew();
$repo->setSlug('pdenis/scrutinizer-client');
$repo->setType('g');
$this->object->create($repo);
$repo->setId(1);
$repoTwo = $this->object->createNew();
$repoTwo->setSlug('pdenis/scrutinizer-client');
$repoTwo->setType('g');
$this->object->create($repoTwo);
$repoTwo->setId(2);
$this->assertEquals(sizeof(array($repo, $repoTwo)), sizeof($this->object->findAll()));
}
public function testUpdate()
{
$repo = $this->object->createNew();
$repo->setSlug('pdenis/scrutinizer-client');
$repo->setType('g');
$this->object->create($repo);
$repo = $this->object->find(1);
$this->assertEquals('pdenis/scrutinizer-client', $repo->getSlug());
$repo->setSlug('pdenis/monitoring');
$this->object->update($repo);
$repo = $this->object->find(1);
$this->assertEquals('pdenis/monitoring', $repo->getSlug());
}
public function testLoadExtraInfos()
{
$repo = $this->object->createNew();
$repo->setSlug('pdenis/scrutinizer-client');
$repo->setType('g');
$this->object->loadExtraInfos($repo);
$this->assertNotNull($repo->getBuilds());
$this->assertNotNull($repo->getMetrics());
$this->assertNotNull($repo->getDescription());
}
}