Skip to content

Commit 648c8a7

Browse files
pavelvondrasekdbu
authored andcommitted
increased min PHP version to 5.6 and updated phpunit tests
1 parent 157634b commit 648c8a7

File tree

81 files changed

+2300
-1794
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+2300
-1794
lines changed

.styleci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
preset: psr2
22

33
enabled:
4-
- long_array_syntax
4+
- short_array_syntax
55
- duplicate_semicolon

composer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
}
2828
],
2929
"require": {
30-
"php": ">=5.3.0",
31-
"phpcr/phpcr-implementation": "2.1.*"
30+
"php": "^5.6|7.0.x",
31+
"phpcr/phpcr-implementation": "2.1.*",
32+
"phpunit/phpunit": "^5.7"
3233
},
3334
"autoload": {
3435
"psr-4": {

inc/AbstractLoader.php

+43-18
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@
1111

1212
namespace PHPCR\Test;
1313

14+
use Exception;
15+
use PHPCR\CredentialsInterface;
1416
use PHPCR\NoSuchWorkspaceException;
1517
use PHPCR\RepositoryFactoryInterface;
18+
use PHPCR\RepositoryInterface;
19+
use PHPCR\SessionInterface;
20+
use PHPUnit_Framework_SkippedTestSuiteError;
1621

1722
/**
1823
* Base class for the bootstrapping to load your phpcr implementation for the
@@ -22,22 +27,35 @@
2227
*/
2328
abstract class AbstractLoader
2429
{
30+
/**
31+
* @var string
32+
*/
2533
protected $factoryclass;
34+
35+
/**
36+
* @var string
37+
*/
2638
protected $workspacename;
39+
40+
/**
41+
* @var string
42+
*/
2743
protected $otherWorkspacename;
2844

2945
/**
3046
* array with chapter names to skip all test cases in (without the numbers).
3147
*/
32-
protected $unsupportedChapters = array();
48+
protected $unsupportedChapters = [];
49+
3350
/**
3451
* array in the format Chapter\FeatureTest with all cases to skip.
3552
*/
36-
protected $unsupportedCases = array();
53+
protected $unsupportedCases = [];
54+
3755
/**
3856
* array in the format Chapter\FeatureTest::testName with all single tests to skip.
3957
*/
40-
protected $unsupportedTests = array();
58+
protected $unsupportedTests = [];
4159

4260
/**
4361
* Create the loader.
@@ -63,10 +81,12 @@ protected function __construct($factoryclass, $workspacename = 'tests', $otherWo
6381
* configured to provide things from your implementation.
6482
*
6583
* @return AbstractLoader loader for your implementation
84+
*
85+
* @throws Exception
6686
*/
6787
public static function getInstance()
6888
{
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.');
7090
}
7191

7292
/**
@@ -89,26 +109,28 @@ abstract public function getRepositoryFactoryParameters();
89109
* The default implementation uses the factory, but if the factory has an
90110
* error, you will get failing tests all over.
91111
*
92-
* @return \PHPCR\RepositoryInterface the repository instance
112+
* @return RepositoryInterface the repository instance
93113
*/
94114
public function getRepository()
95115
{
96116
$factoryclass = $this->getRepositoryFactoryClass();
97117
$factory = new $factoryclass();
118+
98119
if (!$factory instanceof RepositoryFactoryInterface) {
99-
throw new \Exception("$factoryclass is not of type RepositoryFactoryInterface");
120+
throw new Exception("$factoryclass is not of type RepositoryFactoryInterface");
100121
}
122+
101123
/* @var $factory RepositoryFactoryInterface */
102124
return $factory->getRepository($this->getRepositoryFactoryParameters());
103125
}
104126

105127
/**
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
107129
*/
108130
abstract public function getCredentials();
109131

110132
/**
111-
* @return \PHPCR\CredentialsInterface the login credentials that lead to login failure
133+
* @return CredentialsInterface the login credentials that lead to login failure
112134
*/
113135
abstract public function getInvalidCredentials();
114136

@@ -118,7 +140,7 @@ abstract public function getInvalidCredentials();
118140
*
119141
* The user may not have write access to /tests_general_base/numberPropertyNode/jcr:content/foo
120142
*
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
122144
*/
123145
abstract public function getRestrictedCredentials();
124146

@@ -165,9 +187,9 @@ public function getOtherWorkspaceName()
165187
/**
166188
* Get a session for this implementation.
167189
*
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
169191
*
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
171193
*/
172194
public function getSession($credentials = false)
173195
{
@@ -177,9 +199,9 @@ public function getSession($credentials = false)
177199
/**
178200
* Get a session corresponding to the additional workspace for this implementation.
179201
*
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
181203
*
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
183205
*/
184206
public function getAdditionalSession($credentials = false)
185207
{
@@ -192,9 +214,9 @@ public function getAdditionalSession($credentials = false)
192214
*
193215
* Otherwise, the test regarding this feature is skipped.
194216
*
195-
* @return \PHPCR\SessionInterface
217+
* @return SessionInterface
196218
*
197-
* @throws \PHPUnit_Framework_SkippedTestSuiteError to make whole test
219+
* @throws PHPUnit_Framework_SkippedTestSuiteError to make whole test
198220
* suite skip if implementation does not support updating the
199221
* properties automatically.
200222
*/
@@ -204,7 +226,7 @@ public function getSessionWithLastModified()
204226
return $this->getSession();
205227
}
206228

207-
throw new \PHPUnit_Framework_SkippedTestSuiteError('Not supported');
229+
throw new PHPUnit_Framework_SkippedTestSuiteError('Not supported');
208230
}
209231

210232
/**
@@ -240,7 +262,7 @@ public function getTestSupported($chapter, $case, $name)
240262
}
241263

242264
/**
243-
* @return \PHPCR\Test\FixtureLoaderInterface implementation that is used to load test fixtures
265+
* @return FixtureLoaderInterface implementation that is used to load test fixtures
244266
*/
245267
abstract public function getFixtureLoader();
246268

@@ -249,6 +271,8 @@ abstract public function getFixtureLoader();
249271
* @param $workspaceName
250272
*
251273
* @return mixed
274+
*
275+
* @throws Exception
252276
*/
253277
private function getSessionForWorkspace($credentials, $workspaceName)
254278
{
@@ -263,8 +287,9 @@ private function getSessionForWorkspace($credentials, $workspaceName)
263287
$adminRepository = $this->getRepository(); // get a new repository to log into
264288
$session = $adminRepository->login($this->getCredentials(), 'default');
265289
$workspace = $session->getWorkspace();
290+
266291
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);
268293
}
269294
$workspace->createWorkspace($workspaceName);
270295

inc/BaseCase.php

+27-25
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@
1111

1212
namespace PHPCR\Test;
1313

14+
use ImplementationLoader;
15+
use Iterator;
16+
use IteratorAggregate;
17+
use PHPCR\RepositoryException;
1418
use PHPCR\SessionInterface;
1519
use PHPCR\NodeInterface;
1620
use DateTime;
17-
18-
// PHPUnit 3.4 compat
19-
if (method_exists('PHPUnit_Util_Filter', 'addDirectoryToFilter')) {
20-
require_once 'PHPUnit/Framework.php';
21-
}
21+
use PHPUnit_Framework_SkippedTestSuiteError;
22+
use PHPUnit_Framework_TestCase;
2223

2324
/**
2425
* Base class for all phpcr api tests.
2526
*/
26-
abstract class BaseCase extends \PHPUnit_Framework_TestCase
27+
abstract class BaseCase extends PHPUnit_Framework_TestCase
2728
{
2829
/**
2930
* Describes the path to the node for this test, used with writing tests.
@@ -40,14 +41,14 @@ abstract class BaseCase extends \PHPUnit_Framework_TestCase
4041
/**
4142
* The root node of the fixture, initialized for each test.
4243
*
43-
* @var \PHPCR\NodeInterface
44+
* @var NodeInterface
4445
*/
4546
protected $rootNode = null;
4647

4748
/**
4849
* The node in the current fixture at /test_class_name/testMethod.
4950
*
50-
* @var \PHPCR\NodeInterface
51+
* @var NodeInterface
5152
*/
5253
protected $node = null;
5354

@@ -75,7 +76,7 @@ abstract class BaseCase extends \PHPUnit_Framework_TestCase
7576
/**
7677
* Same as staticSharedFixture, loaded in setUp for your convenience.
7778
*/
78-
protected $sharedFixture = array();
79+
protected $sharedFixture = [];
7980

8081
/**
8182
* the loader can throw a PHPCR\RepositoryException
@@ -97,16 +98,16 @@ abstract class BaseCase extends \PHPUnit_Framework_TestCase
9798
*/
9899
public static function setupBeforeClass($fixtures = 'general/base')
99100
{
100-
self::$loader = \ImplementationLoader::getInstance();
101+
self::$loader = ImplementationLoader::getInstance();
101102

102103
$fqn = get_called_class();
103104
list($phpcr, $tests, $chapter, $case) = explode('\\', $fqn);
104105
$case = "$chapter\\$case";
105106
if (!self::$loader->getTestSupported($chapter, $case, null)) {
106-
throw new \PHPUnit_Framework_SkippedTestSuiteError('Test case not supported by this implementation');
107+
throw new PHPUnit_Framework_SkippedTestSuiteError('Test case not supported by this implementation');
107108
}
108109

109-
self::$staticSharedFixture = array();
110+
self::$staticSharedFixture = [];
110111
date_default_timezone_set('Europe/Zurich'); //TODO put this here?
111112
112113
self::$staticSharedFixture['ie'] = self::$loader->getFixtureLoader();
@@ -156,7 +157,7 @@ public static function tearDownAfterClass()
156157
*
157158
* Logout from the old session but does *NOT* save the session
158159
*
159-
* @return \PHPCR\SessionInterface The new session
160+
* @return SessionInterface The new session
160161
*/
161162
protected function renewSession()
162163
{
@@ -176,7 +177,7 @@ protected function renewSession()
176177
*
177178
* Saves the old session and logs it out.
178179
*
179-
* @return \PHPCR\SessionInterface The new session
180+
* @return SessionInterface The new session
180181
*/
181182
protected function saveAndRenewSession()
182183
{
@@ -217,28 +218,29 @@ protected function initProperties()
217218
* this is similar to doing self::$loader->getSession($credentials) but
218219
* does error handling and asserts the session is a valid SessionInterface
219220
*
220-
* @return \PHPCR\SessionInterface the session from the login
221+
* @return SessionInterface the session from the login
221222
*/
222223
protected function assertSession($credentials = false)
223224
{
224225
try {
225-
$ses = self::$loader->getSession($credentials);
226-
} catch (\PHPCR\RepositoryException $e) {
227-
if ($e->getMessage() == self::NOTSUPPORTEDLOGIN) {
226+
$session = self::$loader->getSession($credentials);
227+
} catch (RepositoryException $e) {
228+
if ($e->getMessage() === self::NOTSUPPORTEDLOGIN) {
228229
$this->markTestSkipped('This implementation does not support this type of login.');
229230
} else {
230231
throw $e;
231232
}
232233
}
233-
$this->assertInstanceOf('PHPCR\SessionInterface', $ses);
234234

235-
return $ses;
235+
$this->assertInstanceOf(SessionInterface::class, $session);
236+
237+
return $session;
236238
}
237239

238240
/** assert that this is an object that is traversable */
239241
protected function assertTraversableImplemented($obj)
240242
{
241-
$this->assertTrue($obj instanceof \Iterator || $obj instanceof \IteratorAggregate, 'To provide Traversable, you have to either implement Iterator or IteratorAggregate');
243+
$this->assertTrue($obj instanceof Iterator || $obj instanceof IteratorAggregate, 'To provide Traversable, you have to either implement Iterator or IteratorAggregate');
242244
}
243245

244246
/**
@@ -269,13 +271,13 @@ protected function assertEqualDateTime(DateTime $date1, DateTime $date2)
269271
* other. Use this rather than plain "Equal" when checking application
270272
* generated dates.
271273
*
272-
* @param \DateTime $expected
273-
* @param \DateTime $data
274+
* @param DateTime $expected
275+
* @param DateTime $data
274276
*/
275277
protected function assertSimilarDateTime($expected, $data)
276278
{
277-
$this->assertInstanceOf('\DateTime', $expected);
278-
$this->assertInstanceOf('\DateTime', $data);
279+
$this->assertInstanceOf(DateTime::class, $expected);
280+
$this->assertInstanceOf(DateTime::class, $data);
279281
$this->assertTrue(abs($expected->getTimestamp() - $data->getTimestamp()) <= 3,
280282
$data->format('c').' is not close to the expected '.$expected->format('c')
281283
);

tests/Connecting/RepositoryDescriptorsTest.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@
1111

1212
namespace PHPCR\Tests\Connecting;
1313

14-
class RepositoryDescriptorsTest extends \PHPCR\Test\BaseCase
14+
use PHPCR\Test\BaseCase;
15+
16+
class RepositoryDescriptorsTest extends BaseCase
1517
{
1618
public static function setupBeforeClass($fixtures = false)
1719
{
18-
//don't care about fixtures
20+
// Don't care about fixtures
1921
parent::setupBeforeClass($fixtures);
2022
}
2123

22-
//Those constants need to be defined in the bootstrap file
23-
protected $expectedDescriptors = array(
24+
// Those constants need to be defined in the bootstrap file
25+
protected $expectedDescriptors = [
2426
SPEC_VERSION_DESC,
2527
SPEC_NAME_DESC,
2628
REP_VENDOR_DESC,
@@ -32,7 +34,7 @@ public static function setupBeforeClass($fixtures = false)
3234
OPTION_OBSERVATION_SUPPORTED,
3335
OPTION_LOCKING_SUPPORTED,
3436
// TODO: complete with the list from jcr 2
35-
);
37+
];
3638

3739
// 24.2 Repository Descriptors
3840
public function testDescriptorKeys()

0 commit comments

Comments
 (0)