Skip to content

Commit 18abb37

Browse files
committed
use objects as objects rather than with array functions to be hhvm friendly
1 parent a687521 commit 18abb37

File tree

8 files changed

+94
-64
lines changed

8 files changed

+94
-64
lines changed

inc/BaseCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ protected function initProperties()
191191
$this->rootNode = $this->session->getRootNode();
192192

193193
$children = $this->rootNode->getNodes("tests_*");
194-
$child = current($children);
195-
if (false !== $child && $child->hasNode($this->getName())) {
194+
$child = $children->current();
195+
if ($child && $child->hasNode($this->getName())) {
196196
$this->node = $child->getNode($this->getName());
197197
}
198198
}

tests/05_Reading/PropertyReadMethodsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ public function testGetPropertyMulti()
438438
}
439439

440440
/**
441-
* @expectedException PHPCR\ValueFormatException
441+
* @expectedException \PHPCR\ValueFormatException
442442
*/
443443
public function testGetPropertyNoPath()
444444
{

tests/10_Writing/AddMethodsTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function testAddNodeAutoNamedEmptyNamehint()
104104
$this->assertInstanceOf('PHPCR\\NodeInterface', $new);
105105
$nodes = $node->getNodes();
106106
$this->assertCount(1, $nodes);
107-
$newnode = current($nodes);
107+
$newnode = $nodes->current();
108108
$name = $newnode->getName();
109109
$this->assertEquals(0, substr_count(':', $name));
110110

@@ -123,7 +123,7 @@ public function testAddNodeAutoNamedNullNamehint()
123123
$this->assertInstanceOf('PHPCR\\NodeInterface', $new);
124124
$nodes = $node->getNodes();
125125
$this->assertCount(1, $nodes);
126-
$newnode = current($nodes);
126+
$newnode = $nodes->current();
127127
$name = $newnode->getName();
128128

129129
$this->session->save();
@@ -141,7 +141,7 @@ public function testAddNodeAutoNamedValidNamespaceNamehint()
141141
$this->assertInstanceOf('PHPCR\\NodeInterface', $new);
142142
$nodes = $node->getNodes();
143143
$this->assertCount(1, $nodes);
144-
$newnode = current($nodes);
144+
$newnode = $nodes->current();
145145
$name = $newnode->getName();
146146
$this->assertEquals('jcr:', substr($name, 0, 4));
147147

tests/13_WorkspaceManagement/WorkspaceManagementTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function testCreateWorkspace()
2020

2121
/**
2222
* @depends testCreateWorkspace
23-
* @expectedException PHPCR\RepositoryException
23+
* @expectedException \PHPCR\RepositoryException
2424
*/
2525
public function testCreateWorkspaceExisting($workspacename)
2626
{
@@ -40,7 +40,7 @@ public function testCreateWorkspaceWithSource()
4040
}
4141

4242
/**
43-
* @expectedException PHPCR\NoSuchWorkspaceException
43+
* @expectedException \PHPCR\NoSuchWorkspaceException
4444
*/
4545
public function testCreateWorkspaceWithInvalidSource()
4646
{

tests/15_Versioning/VersionHistoryTest.php

Lines changed: 54 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
22
namespace PHPCR\Tests\Versioning;
33

4+
use PHPCR\Util\PathHelper;
45
use PHPCR\Version\VersionHistoryInterface;
6+
use PHPCR\Version\VersionManagerInterface;
57

68
require_once(__DIR__ . '/../../inc/BaseCase.php');
79

@@ -12,6 +14,16 @@
1214
*/
1315
class VersionHistoryTest extends \PHPCR\Test\BaseCase
1416
{
17+
/**
18+
* @var VersionManagerInterface
19+
*/
20+
private $vm;
21+
22+
/**
23+
* @var VersionHistoryInterface
24+
*/
25+
private $history;
26+
1527
public static function setupBeforeClass($fixtures = '15_Versioning/base')
1628
{
1729
parent::setupBeforeClass($fixtures);
@@ -45,15 +57,15 @@ public function testGetAllLinearFrozenNodes()
4557
$frozenNodes = $this->history->getAllLinearFrozenNodes();
4658
$this->assertTraversableImplemented($frozenNodes);
4759

48-
$this->assertEquals(5, count($frozenNodes));
60+
$this->assertCount(5, $frozenNodes);
4961

62+
$lastNode = null;
5063
foreach ($frozenNodes as $name => $node) {
5164
$this->assertInstanceOf('PHPCR\NodeInterface', $node);
5265
$this->assertInternalType('string', $name);
66+
$lastNode = $node;
5367
}
5468

55-
$firstNode = reset($frozenNodes);
56-
$lastNode = end($frozenNodes);
5769
$currentNode = $this->vm->getBaseVersion('/tests_version_base/versioned')->getFrozenNode();
5870

5971
$this->assertSame($currentNode, $lastNode);
@@ -65,15 +77,15 @@ public function testGetAllFrozenNodes()
6577
$frozenNodes = $this->history->getAllFrozenNodes();
6678
$this->assertTraversableImplemented($frozenNodes);
6779

68-
$this->assertEquals(5, count($frozenNodes));
80+
$this->assertCount(5, $frozenNodes);
6981

82+
$lastNode = null;
7083
foreach ($frozenNodes as $name => $node) {
7184
$this->assertInstanceOf('PHPCR\NodeInterface', $node);
7285
$this->assertInternalType('string', $name);
86+
$lastNode = $node;
7387
}
7488

75-
$firstNode = reset($frozenNodes);
76-
$lastNode = end($frozenNodes);
7789
$currentNode = $this->vm->getBaseVersion('/tests_version_base/versioned')->getFrozenNode();
7890

7991
$this->assertSame($currentNode, $lastNode);
@@ -86,22 +98,23 @@ public function testGetAllLinearVersions()
8698
$versions = $this->history->getAllLinearVersions();
8799
$this->assertTraversableImplemented($versions);
88100

89-
$this->assertEquals(5, count($versions));
101+
$this->assertCount(5, $versions);
90102

103+
$firstVersion = $versions->current();
104+
$lastVersion = null;
91105
foreach ($versions as $name => $version) {
92106
$this->assertInstanceOf('PHPCR\Version\VersionInterface', $version);
93107
$this->assertEquals($version->getName(), $name);
108+
$lastVersion = $version;
94109
}
95110

96-
$firstVersion = reset($versions);
97-
$lastVersion = end($versions);
98111
$currentVersion = $this->vm->getBaseVersion('/tests_version_base/versioned');
99112

100113
$this->assertSame($currentVersion, $lastVersion);
101-
$this->assertEquals(0, count($firstVersion->getPredecessors()));
102-
$this->assertEquals(1, count($firstVersion->getSuccessors()));
103-
$this->assertEquals(1, count($lastVersion->getPredecessors()));
104-
$this->assertEquals(0, count($lastVersion->getSuccessors()));
114+
$this->assertCount(0, $firstVersion->getPredecessors());
115+
$this->assertCount(1, $firstVersion->getSuccessors());
116+
$this->assertCount(1, $lastVersion->getPredecessors());
117+
$this->assertCount(0, $lastVersion->getSuccessors());
105118
}
106119

107120
public function testGetAllVersions()
@@ -110,22 +123,23 @@ public function testGetAllVersions()
110123
$versions = $this->history->getAllVersions();
111124
$this->assertTraversableImplemented($versions);
112125

113-
$this->assertEquals(5, count($versions));
126+
$this->assertCount(5, $versions);
114127

128+
$firstVersion = $versions->current();
129+
$lastVersion = null;
115130
foreach ($versions as $name => $version) {
116131
$this->assertInstanceOf('PHPCR\Version\VersionInterface', $version);
117132
$this->assertEquals($version->getName(), $name);
133+
$lastVersion = $version;
118134
}
119135

120-
$firstVersion = reset($versions);
121-
$lastVersion = end($versions);
122136
$currentVersion = $this->vm->getBaseVersion('/tests_version_base/versioned');
123137

124138
$this->assertSame($currentVersion, $lastVersion);
125-
$this->assertEquals(0, count($firstVersion->getPredecessors()));
126-
$this->assertEquals(1, count($firstVersion->getSuccessors()));
127-
$this->assertEquals(1, count($lastVersion->getPredecessors()));
128-
$this->assertEquals(0, count($lastVersion->getSuccessors()));
139+
$this->assertCount(0, $firstVersion->getPredecessors());
140+
$this->assertCount(1, $firstVersion->getSuccessors());
141+
$this->assertCount(1, $lastVersion->getPredecessors());
142+
$this->assertCount(0, $lastVersion->getSuccessors());
129143
}
130144

131145
/**
@@ -156,21 +170,22 @@ public function testMixingCreateAndGetAllVersions()
156170
$vm->checkin('/tests_version_base/versioned_all');
157171
$this->assertCount(3, $history->getAllVersions());
158172

159-
foreach ($history->getAllVersions() as $name => $version) {
173+
$finalVersions = $history->getAllVersions();
174+
$firstVersion = $finalVersions->current();
175+
$lastVersion = null;
176+
foreach ($finalVersions as $name => $version) {
160177
$this->assertInstanceOf('PHPCR\Version\VersionInterface', $version);
161178
$this->assertEquals($version->getName(), $name);
179+
$lastVersion = $version;
162180
}
163181

164-
$finalVersions = $history->getAllVersions();
165-
$firstVersion = reset($finalVersions);
166-
$lastVersion = end($finalVersions);
167182
$currentVersion = $this->vm->getBaseVersion('/tests_version_base/versioned_all');
168183

169184
$this->assertSame($currentVersion, $lastVersion);
170-
$this->assertEquals(0, count($firstVersion->getPredecessors()));
171-
$this->assertEquals(1, count($firstVersion->getSuccessors()));
172-
$this->assertEquals(1, count($lastVersion->getPredecessors()));
173-
$this->assertEquals(0, count($lastVersion->getSuccessors()));
185+
$this->assertCount(0, $firstVersion->getPredecessors());
186+
$this->assertCount(1, $firstVersion->getSuccessors());
187+
$this->assertCount(1, $lastVersion->getPredecessors());
188+
$this->assertCount(0, $lastVersion->getSuccessors());
174189
}
175190

176191
/**
@@ -197,28 +212,29 @@ public function testMixingCreateAndGetAllLinearVersions()
197212
$vm->checkin('/tests_version_base/versioned_all_linear');
198213
$this->assertCount(3, $history->getAllLinearVersions());
199214

200-
foreach ($history->getAllLinearVersions() as $name => $version) {
215+
$finalVersions = $history->getAllLinearVersions();
216+
$firstVersion = $finalVersions->current();
217+
$lastVersion = null;
218+
foreach ($finalVersions as $name => $version) {
201219
$this->assertInstanceOf('PHPCR\Version\VersionInterface', $version);
202220
$this->assertEquals($version->getName(), $name);
221+
$lastVersion = $version;
203222
}
204223

205-
$finalVersions = $history->getAllLinearVersions();
206-
$firstVersion = reset($finalVersions);
207-
$lastVersion = end($finalVersions);
208224
$currentVersion = $this->vm->getBaseVersion('/tests_version_base/versioned_all_linear');
209225

210226
$this->assertSame($currentVersion, $lastVersion);
211-
$this->assertEquals(0, count($firstVersion->getPredecessors()));
212-
$this->assertEquals(1, count($firstVersion->getSuccessors()));
213-
$this->assertEquals(1, count($lastVersion->getPredecessors()));
214-
$this->assertEquals(0, count($lastVersion->getSuccessors()));
227+
$this->assertCount(0, $firstVersion->getPredecessors());
228+
$this->assertCount(1, $firstVersion->getSuccessors());
229+
$this->assertCount(1, $lastVersion->getPredecessors());
230+
$this->assertCount(0, $lastVersion->getSuccessors());
215231
}
216232

217233
public function testGetRootVersion()
218234
{
219235
$rootVersion = $this->history->getRootVersion();
220236
$this->assertInstanceOf('PHPCR\\Version\\VersionInterface', $rootVersion);
221-
$this->assertEquals($this->history->getPath(), dirname($rootVersion->getPath()));
237+
$this->assertEquals($this->history->getPath(), PathHelper::getParentPath($rootVersion->getPath()));
222238
}
223239

224240
public function testGetVersionableIdentifier()
@@ -282,7 +298,7 @@ public function testDeleteLatestVersion()
282298
*/
283299
public function testDeleteUnexistingVersion()
284300
{
285-
$version = $this->vm->checkpoint('/tests_version_base/versioned');
301+
$this->vm->checkpoint('/tests_version_base/versioned');
286302
$history = $this->vm->getVersionHistory('/tests_version_base/versioned');
287303
$history->removeVersion('unexisting');
288304
}

tests/15_Versioning/VersionManagerTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testWriteNotCheckedOutVersion()
6060
}
6161

6262
/**
63-
* @expectedException PHPCR\InvalidItemStateException
63+
* @expectedException \PHPCR\InvalidItemStateException
6464
*/
6565
public function testCheckinModifiedNode()
6666
{
@@ -108,15 +108,15 @@ public function testGetBaseVersion()
108108
}
109109

110110
/**
111-
* @expectedException PHPCR\UnsupportedRepositoryOperationException
111+
* @expectedException \PHPCR\UnsupportedRepositoryOperationException
112112
*/
113113
public function testGetBaseVersionNonversionable()
114114
{
115115
$version = $this->vm->getBaseVersion('/tests_version_base/unversionable');
116116
}
117117

118118
/**
119-
* @expectedException PHPCR\RepositoryException
119+
* @expectedException \PHPCR\RepositoryException
120120
*/
121121
public function testGetBaseVersionNotfound()
122122
{
@@ -132,15 +132,15 @@ public function testGetVersionHistory()
132132
}
133133

134134
/**
135-
* @expectedException PHPCR\UnsupportedRepositoryOperationException
135+
* @expectedException \PHPCR\UnsupportedRepositoryOperationException
136136
*/
137137
public function testGetVersionHistoryNonversionable()
138138
{
139139
$this->vm->getVersionHistory('/tests_version_base/unversionable');
140140
}
141141

142142
/**
143-
* @expectedException PHPCR\RepositoryException
143+
* @expectedException \PHPCR\RepositoryException
144144
*/
145145
public function testGetVersionHistoryNotfound()
146146
{
@@ -160,14 +160,14 @@ public function testIsCheckedOut()
160160
}
161161

162162
/**
163-
* @expectedException PHPCR\UnsupportedRepositoryOperationException
163+
* @expectedException \PHPCR\UnsupportedRepositoryOperationException
164164
*/
165165
public function testIsCheckedOutNonversionable()
166166
{
167167
$this->vm->isCheckedOut('/tests_version_base/unversionable');
168168
}
169169
/**
170-
* @expectedException PHPCR\RepositoryException
170+
* @expectedException \PHPCR\RepositoryException
171171
*/
172172
public function testIsCheckedOutNotExisting()
173173
{
@@ -256,7 +256,7 @@ public function testRestoreByVersionObject()
256256
}
257257

258258
/**
259-
* @expectedException PHPCR\InvalidItemStateException
259+
* @expectedException \PHPCR\InvalidItemStateException
260260
*/
261261
public function testRestorePendingChanges()
262262
{
@@ -280,21 +280,21 @@ public function testRestorePendingChanges()
280280
// TODO: testRestoreByVersionArray, testRestoreVersionToPath, testRestoreVersionToExistingPath (expect exception)
281281

282282
/**
283-
* @expectedException PHPCR\UnsupportedRepositoryOperationException
283+
* @expectedException \PHPCR\UnsupportedRepositoryOperationException
284284
*/
285285
public function testRestoreNonversionablePath()
286286
{
287287
$this->vm->restore(true, 'something', '/tests_version_base/unversionable');
288288
}
289289
/**
290-
* @expectedException PHPCR\RepositoryException
290+
* @expectedException \PHPCR\RepositoryException
291291
*/
292292
public function testRestoreNonexistingPath()
293293
{
294294
$this->vm->restore(true, 'something', '/tests_version_base/not_existing');
295295
}
296296
/**
297-
* @expectedException PHPCR\Version\VersionException
297+
* @expectedException \PHPCR\Version\VersionException
298298
*/
299299
public function testRestoreNonexistingName()
300300
{
@@ -316,7 +316,7 @@ public function testRestoreNonsenseArguments()
316316
}
317317
}
318318
/**
319-
* @expectedException PHPCR\Version\VersionException
319+
* @expectedException \PHPCR\Version\VersionException
320320
*/
321321
public function testRestoreRootVersion()
322322
{

0 commit comments

Comments
 (0)