Skip to content

Commit 376e5e0

Browse files
committed
Merge pull request #156 from phpcr/cleanups
non-changing cleanups
2 parents a8071d7 + 8f7a343 commit 376e5e0

File tree

5 files changed

+60
-41
lines changed

5 files changed

+60
-41
lines changed

inc/BaseCase.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,17 +271,16 @@ protected function assertSimilarDateTime($expected, $data)
271271
}
272272

273273
/**
274-
* Check to see if the given descriptor evaluates to false, if it does
275-
* mark the test as skipped and return False, else return True.
274+
* Check whether the repository supports this descriptor and skip the test if it is not supported.
276275
*
277-
* @param sting $descriptor
278-
* @return boolean
276+
* @param string $descriptor
277+
*
278+
* @return boolean True if the test can be done. Otherwise the test is skipped.
279279
*/
280280
protected function skipIfNotSupported($descriptor)
281281
{
282282
if (false === $this->session->getRepository()->getDescriptor($descriptor)) {
283283
$this->markTestSkipped('Descriptor "' . $descriptor . '" not supported');
284-
return false;
285284
}
286285

287286
return true;

tests/08_NodeTypeDiscovery/NodeTypeTest.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22
namespace PHPCR\Tests\NodeTypeDiscovery;
33

4+
use PHPCR\NodeType\NodeTypeInterface;
5+
use PHPCR\RepositoryInterface;
6+
47
require_once(__DIR__ . '/../../inc/BaseCase.php');
58

69
/**
@@ -10,10 +13,29 @@
1013
*/
1114
class NodeTypeTest extends \PHPCR\Test\BaseCase
1215
{
16+
/**
17+
* @var NodeTypeInterface
18+
*/
1319
private static $base;
20+
21+
/**
22+
* @var NodeTypeInterface
23+
*/
1424
private static $hierarchyNode;
25+
26+
/**
27+
* @var NodeTypeInterface
28+
*/
1529
private static $file;
30+
31+
/**
32+
* @var NodeTypeInterface
33+
*/
1634
private static $resource;
35+
36+
/**
37+
* @var NodeTypeInterface
38+
*/
1739
private static $created;
1840

1941
public static function setupBeforeClass($fixtures = false)
@@ -155,11 +177,9 @@ public function testIsNodeTypeMixin()
155177
*/
156178
public function testIsNodeTypeMixinVersion()
157179
{
158-
if (!self::$staticSharedFixture['session']->getRepository()->getDescriptor('option.versioning.supported')) {
159-
$this->markTestSkipped('PHPCR repository doesn\'t support versioning');
160-
}
180+
$this->skipIfNotSupported(RepositoryInterface::OPTION_VERSIONING_SUPPORTED);
161181

162-
$ntm = self::$staticSharedFixture['session']->getWorkspace()->getNodeTypeManager();
182+
$ntm = $this->session->getWorkspace()->getNodeTypeManager();
163183
$versionable = $ntm->getNodeType('mix:versionable');
164184
$this->assertTrue($versionable->isNodeType('mix:versionable'));
165185
$this->assertTrue($versionable->isNodeType('mix:referenceable'));

tests/10_Writing/AddMethodsTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33

44
require_once(__DIR__ . '/../../inc/BaseCase.php');
55

6-
use PHPCR\PropertyType as Type;
6+
use PHPCR\NodeType\ConstraintViolationException;
7+
use PHPCR\PropertyType;
78
use PHPCR\RepositoryInterface;
9+
use PHPCR\ValueFormatException;
810

911
/**
1012
* Covering jcr-283 spec $10.4
@@ -58,9 +60,9 @@ public function testAddNodeFileType()
5860
$path = $this->node->getPath();
5961
$newNode = $this->node->addNode('newFileNode', 'nt:file');
6062
$contentNode = $newNode->addNode('jcr:content', 'nt:resource');
61-
$contentNode->setProperty('jcr:mimeType', 'text/plain', Type::STRING);
62-
$contentNode->setProperty('jcr:data', 'Hello', Type::BINARY);
63-
$contentNode->setProperty('jcr:lastModified', new \DateTime('2010-12-12'), Type::DATE);
63+
$contentNode->setProperty('jcr:mimeType', 'text/plain', PropertyType::STRING);
64+
$contentNode->setProperty('jcr:data', 'Hello', PropertyType::BINARY);
65+
$contentNode->setProperty('jcr:lastModified', new \DateTime('2010-12-12'), PropertyType::DATE);
6466

6567
$this->assertNotNull($newNode, 'Node newFileNode was not created');
6668
$this->assertTrue($newNode->isNew(), 'Node newFileNode is not marked dirty');
@@ -274,7 +276,7 @@ public function testAddNodeInParallel()
274276
*/
275277
public function testAddNodePathNotFound()
276278
{
277-
$parent = $this->node->addNode('nonExistent/newNode', 'nt:unstructured');
279+
$this->node->addNode('nonExistent/newNode', 'nt:unstructured');
278280
}
279281

280282
/**
@@ -297,10 +299,10 @@ public function testAddPropertyWrongType()
297299
try {
298300
$data->setProperty('jcr:lastModified', true);
299301
$this->saveAndRenewSession();
300-
} catch (\PHPCR\ValueFormatException $e) {
302+
} catch (ValueFormatException $e) {
301303
//correct according to JSR-287 3.6.4 Property Type Conversion
302304
return;
303-
} catch (\PHPCR\NodeType\ConstraintViolationException $e) {
305+
} catch (ConstraintViolationException $e) {
304306
//also correct
305307
return;
306308
}
@@ -344,7 +346,7 @@ public function testAddNodeChildProperties()
344346
$parent = $this->node->addNode('parent', 'nt:folder');
345347
$child = $parent->addNode('child', 'nt:file');
346348
$content = $child->addNode('jcr:content', 'nt:resource');
347-
$content->setProperty('jcr:data', '1234', \PHPCR\PropertyType::BINARY);
349+
$content->setProperty('jcr:data', '1234', PropertyType::BINARY);
348350
$path = $child->getPath();
349351

350352
$this->saveAndRenewSession();

tests/10_Writing/CloneMethodsTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace PHPCR\Tests\Writing;
33

4+
use PHPCR\RepositoryInterface;
45
use PHPCR\WorkspaceInterface;
56
use PHPCR\Test\BaseCase;
67

@@ -567,9 +568,13 @@ private function renewDestinationSession()
567568
self::$destWs = $destSession->getWorkspace();
568569
}
569570

571+
/**
572+
* Some of the tests in this test case assume that same name siblings are *not* supported.
573+
* Those would fail if the repository supports same name siblings, so we skip them in that case.
574+
*/
570575
private function skipIfSameNameSiblingsSupported()
571576
{
572-
if ($this->session->getRepository()->getDescriptor('node.type.management.same.name.siblings.supported')) {
577+
if ($this->session->getRepository()->getDescriptor(RepositoryInterface::NODE_TYPE_MANAGEMENT_SAME_NAME_SIBLINGS_SUPPORTED)) {
573578
$this->markTestSkipped('Test does not yet cover repositories that support same name siblings.');
574579
}
575580
}

tests/21_Transactions/TransactionMethodsTest.php

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
require_once(__DIR__ . '/../../inc/BaseCase.php');
55

6+
use PHPCR\RepositoryInterface;
67
use \PHPCR\Transaction;
78

89
/**
@@ -25,23 +26,21 @@ public function setUp()
2526

2627
public function testGetTransactionManager()
2728
{
28-
$session = self::$staticSharedFixture['session'];
29-
$utx = $session->getWorkspace()->getTransactionManager();
29+
$utx = $this->session->getWorkspace()->getTransactionManager();
3030

3131
$this->assertInstanceOf('\PHPCR\Transaction\UserTransactionInterface', $utx);
3232
}
3333

3434
public function testTransactionCommit()
3535
{
36-
$session = self::$staticSharedFixture['session'];
37-
$utx = $session->getWorkspace()->getTransactionManager();
36+
$utx = $this->session->getWorkspace()->getTransactionManager();
3837

3938
$utx->begin();
4039
$child = $this->node->addNode('insideTransaction');
4140

4241
$this->assertEquals($this->node->getPath() . '/insideTransaction', $child->getPath());
4342

44-
$session->save();
43+
$this->session->save();
4544

4645
$sessionbeforesave = self::$loader->getSession();
4746
$this->assertFalse($sessionbeforesave->nodeExists($child->getPath()));
@@ -55,19 +54,17 @@ public function testTransactionCommit()
5554

5655
public function testTransactionRollback()
5756
{
58-
$session = self::$staticSharedFixture['session'];
59-
6057
$copy = $this->node->addNode('copyTransaction');
6158
$copiedNodePath = $this->node->getPath()."/copyTransactionCopy";
62-
$session->save();
59+
$this->session->save();
6360

64-
$utx = $session->getWorkspace()->getTransactionManager();
61+
$utx = $this->session->getWorkspace()->getTransactionManager();
6562

6663
$child = $this->node->addNode('insideTransaction');
6764
$utx->begin();
6865
//workspace operation
69-
$session->getWorkspace()->copy($copy->getPath(),$copiedNodePath);
70-
$session->save();
66+
$this->session->getWorkspace()->copy($copy->getPath(),$copiedNodePath);
67+
$this->session->save();
7168
$this->assertFalse($child->isNew());
7269
$utx->rollback();
7370

@@ -79,7 +76,7 @@ public function testTransactionRollback()
7976

8077
// semantics of rollback is that the local session state does not roll back
8178
// this must work
82-
$session->save();
79+
$this->session->save();
8380

8481
$sessionaftersave = self::$loader->getSession();
8582
$this->assertFalse($sessionaftersave->nodeExists($child->getPath()));
@@ -88,20 +85,19 @@ public function testTransactionRollback()
8885

8986
public function testInTransaction()
9087
{
91-
$session = self::$staticSharedFixture['session'];
92-
$utx= $session->getWorkspace()->getTransactionManager();
88+
$utx= $this->session->getWorkspace()->getTransactionManager();
9389

9490
$this->assertFalse($utx->inTransaction());
9591
$utx->begin();
9692
$this->node->addNode('insideTransaction0');
97-
$session->save();
93+
$this->session->save();
9894
$this->assertTrue($utx->inTransaction());
9995
$utx->commit();
10096
$this->assertFalse($utx->inTransaction());
10197

10298
$utx->begin();
10399
$this->node->addNode('insideTransaction1');
104-
$session->save();
100+
$this->session->save();
105101
$this->assertTrue($utx->inTransaction());
106102
$utx->rollback();
107103
$this->assertFalse($utx->inTransaction());
@@ -114,19 +110,16 @@ public function testInTransaction()
114110
*/
115111
public function testIllegalCheckin()
116112
{
117-
if (!self::$staticSharedFixture['session']->getRepository()->getDescriptor('option.versioning.supported')) {
118-
$this->markTestSkipped('PHPCR repository doesn\'t support versioning');
119-
}
113+
$this->skipIfNotSupported(RepositoryInterface::OPTION_VERSIONING_SUPPORTED);
120114

121-
$session = self::$staticSharedFixture['session'];
122-
$vm = $session->getWorkspace()->getVersionManager();
115+
$vm = $this->session->getWorkspace()->getVersionManager();
123116

124-
$utx= $session->getWorkspace()->getTransactionManager();
117+
$utx= $this->session->getWorkspace()->getTransactionManager();
125118
$vm->checkout($this->node->getPath());
126119
$this->node->setProperty('foo', 'bar2');
127120

128121
$utx->begin();
129-
$session->save();
122+
$this->session->save();
130123

131124
$vm->checkin($this->node->getPath());
132125
}

0 commit comments

Comments
 (0)