11
11
12
12
namespace PHPCR \Test ;
13
13
14
+ use Exception ;
15
+ use PHPCR \CredentialsInterface ;
14
16
use PHPCR \NoSuchWorkspaceException ;
15
17
use PHPCR \RepositoryFactoryInterface ;
18
+ use PHPCR \RepositoryInterface ;
19
+ use PHPCR \SessionInterface ;
20
+ use PHPUnit_Framework_SkippedTestSuiteError ;
16
21
17
22
/**
18
23
* Base class for the bootstrapping to load your phpcr implementation for the
22
27
*/
23
28
abstract class AbstractLoader
24
29
{
30
+ /**
31
+ * @var string
32
+ */
25
33
protected $ factoryclass ;
34
+
35
+ /**
36
+ * @var string
37
+ */
26
38
protected $ workspacename ;
39
+
40
+ /**
41
+ * @var string
42
+ */
27
43
protected $ otherWorkspacename ;
28
44
29
45
/**
30
46
* array with chapter names to skip all test cases in (without the numbers).
31
47
*/
32
- protected $ unsupportedChapters = array ();
48
+ protected $ unsupportedChapters = [];
49
+
33
50
/**
34
51
* array in the format Chapter\FeatureTest with all cases to skip.
35
52
*/
36
- protected $ unsupportedCases = array ();
53
+ protected $ unsupportedCases = [];
54
+
37
55
/**
38
56
* array in the format Chapter\FeatureTest::testName with all single tests to skip.
39
57
*/
40
- protected $ unsupportedTests = array () ;
58
+ protected $ unsupportedTests = [] ;
41
59
42
60
/**
43
61
* Create the loader.
@@ -63,10 +81,12 @@ protected function __construct($factoryclass, $workspacename = 'tests', $otherWo
63
81
* configured to provide things from your implementation.
64
82
*
65
83
* @return AbstractLoader loader for your implementation
84
+ *
85
+ * @throws Exception
66
86
*/
67
87
public static function getInstance ()
68
88
{
69
- throw new \ Exception ('You need to overwrite this method, but php does not allow to declare it abstract. ' );
89
+ throw new Exception ('You need to overwrite this method, but php does not allow to declare it abstract. ' );
70
90
}
71
91
72
92
/**
@@ -89,26 +109,28 @@ abstract public function getRepositoryFactoryParameters();
89
109
* The default implementation uses the factory, but if the factory has an
90
110
* error, you will get failing tests all over.
91
111
*
92
- * @return \PHPCR\ RepositoryInterface the repository instance
112
+ * @return RepositoryInterface the repository instance
93
113
*/
94
114
public function getRepository ()
95
115
{
96
116
$ factoryclass = $ this ->getRepositoryFactoryClass ();
97
117
$ factory = new $ factoryclass ();
118
+
98
119
if (!$ factory instanceof RepositoryFactoryInterface) {
99
- throw new \ Exception ("$ factoryclass is not of type RepositoryFactoryInterface " );
120
+ throw new Exception ("$ factoryclass is not of type RepositoryFactoryInterface " );
100
121
}
122
+
101
123
/* @var $factory RepositoryFactoryInterface */
102
124
return $ factory ->getRepository ($ this ->getRepositoryFactoryParameters ());
103
125
}
104
126
105
127
/**
106
- * @return \PHPCR\ CredentialsInterface the login credentials that lead to successful login into the repository
128
+ * @return CredentialsInterface the login credentials that lead to successful login into the repository
107
129
*/
108
130
abstract public function getCredentials ();
109
131
110
132
/**
111
- * @return \PHPCR\ CredentialsInterface the login credentials that lead to login failure
133
+ * @return CredentialsInterface the login credentials that lead to login failure
112
134
*/
113
135
abstract public function getInvalidCredentials ();
114
136
@@ -118,7 +140,7 @@ abstract public function getInvalidCredentials();
118
140
*
119
141
* The user may not have write access to /tests_general_base/numberPropertyNode/jcr:content/foo
120
142
*
121
- * @return \PHPCR\ CredentialsInterface the login credentials with limited permissions for testing impersonate and access control
143
+ * @return CredentialsInterface the login credentials with limited permissions for testing impersonate and access control
122
144
*/
123
145
abstract public function getRestrictedCredentials ();
124
146
@@ -165,9 +187,9 @@ public function getOtherWorkspaceName()
165
187
/**
166
188
* Get a session for this implementation.
167
189
*
168
- * @param \PHPCR\ CredentialsInterface $credentials The credentials to log into the repository. If omitted, self::getCredentials should be used
190
+ * @param CredentialsInterface $credentials The credentials to log into the repository. If omitted, self::getCredentials should be used
169
191
*
170
- * @return \PHPCR\ SessionInterface the session resulting from logging into the repository with the provided credentials
192
+ * @return SessionInterface the session resulting from logging into the repository with the provided credentials
171
193
*/
172
194
public function getSession ($ credentials = false )
173
195
{
@@ -177,9 +199,9 @@ public function getSession($credentials = false)
177
199
/**
178
200
* Get a session corresponding to the additional workspace for this implementation.
179
201
*
180
- * @param \PHPCR\ CredentialsInterface $credentials The credentials to log into the repository. If omitted, self::getCredentials should be used
202
+ * @param CredentialsInterface $credentials The credentials to log into the repository. If omitted, self::getCredentials should be used
181
203
*
182
- * @return \PHPCR\ SessionInterface the session resulting from logging into the repository with the provided credentials
204
+ * @return SessionInterface the session resulting from logging into the repository with the provided credentials
183
205
*/
184
206
public function getAdditionalSession ($ credentials = false )
185
207
{
@@ -192,9 +214,9 @@ public function getAdditionalSession($credentials = false)
192
214
*
193
215
* Otherwise, the test regarding this feature is skipped.
194
216
*
195
- * @return \PHPCR\ SessionInterface
217
+ * @return SessionInterface
196
218
*
197
- * @throws \ PHPUnit_Framework_SkippedTestSuiteError to make whole test
219
+ * @throws PHPUnit_Framework_SkippedTestSuiteError to make whole test
198
220
* suite skip if implementation does not support updating the
199
221
* properties automatically.
200
222
*/
@@ -204,7 +226,7 @@ public function getSessionWithLastModified()
204
226
return $ this ->getSession ();
205
227
}
206
228
207
- throw new \ PHPUnit_Framework_SkippedTestSuiteError ('Not supported ' );
229
+ throw new PHPUnit_Framework_SkippedTestSuiteError ('Not supported ' );
208
230
}
209
231
210
232
/**
@@ -240,7 +262,7 @@ public function getTestSupported($chapter, $case, $name)
240
262
}
241
263
242
264
/**
243
- * @return \PHPCR\Test\ FixtureLoaderInterface implementation that is used to load test fixtures
265
+ * @return FixtureLoaderInterface implementation that is used to load test fixtures
244
266
*/
245
267
abstract public function getFixtureLoader ();
246
268
@@ -249,6 +271,8 @@ abstract public function getFixtureLoader();
249
271
* @param $workspaceName
250
272
*
251
273
* @return mixed
274
+ *
275
+ * @throws Exception
252
276
*/
253
277
private function getSessionForWorkspace ($ credentials , $ workspaceName )
254
278
{
@@ -263,8 +287,9 @@ private function getSessionForWorkspace($credentials, $workspaceName)
263
287
$ adminRepository = $ this ->getRepository (); // get a new repository to log into
264
288
$ session = $ adminRepository ->login ($ this ->getCredentials (), 'default ' );
265
289
$ workspace = $ session ->getWorkspace ();
290
+
266
291
if (in_array ($ workspaceName , $ workspace ->getAccessibleWorkspaceNames ())) {
267
- throw new \ Exception (sprintf ('Workspace "%s" already exists but could not login to it ' , $ workspaceName ), null , $ e );
292
+ throw new Exception (sprintf ('Workspace "%s" already exists but could not login to it ' , $ workspaceName ), null , $ e );
268
293
}
269
294
$ workspace ->createWorkspace ($ workspaceName );
270
295
0 commit comments