From 8f7a343a6699191be64a3f3291ce3c405a7fc391 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 27 Mar 2015 12:25:05 +0100 Subject: [PATCH] non-changing cleanups --- inc/BaseCase.php | 9 ++--- tests/08_NodeTypeDiscovery/NodeTypeTest.php | 28 +++++++++++-- tests/10_Writing/AddMethodsTest.php | 18 +++++---- tests/10_Writing/CloneMethodsTest.php | 7 +++- .../TransactionMethodsTest.php | 39 ++++++++----------- 5 files changed, 60 insertions(+), 41 deletions(-) diff --git a/inc/BaseCase.php b/inc/BaseCase.php index c09b254f..b4a27643 100644 --- a/inc/BaseCase.php +++ b/inc/BaseCase.php @@ -271,17 +271,16 @@ protected function assertSimilarDateTime($expected, $data) } /** - * Check to see if the given descriptor evaluates to false, if it does - * mark the test as skipped and return False, else return True. + * Check whether the repository supports this descriptor and skip the test if it is not supported. * - * @param sting $descriptor - * @return boolean + * @param string $descriptor + * + * @return boolean True if the test can be done. Otherwise the test is skipped. */ protected function skipIfNotSupported($descriptor) { if (false === $this->session->getRepository()->getDescriptor($descriptor)) { $this->markTestSkipped('Descriptor "' . $descriptor . '" not supported'); - return false; } return true; diff --git a/tests/08_NodeTypeDiscovery/NodeTypeTest.php b/tests/08_NodeTypeDiscovery/NodeTypeTest.php index 0fa4e936..316e4087 100644 --- a/tests/08_NodeTypeDiscovery/NodeTypeTest.php +++ b/tests/08_NodeTypeDiscovery/NodeTypeTest.php @@ -1,6 +1,9 @@ getRepository()->getDescriptor('option.versioning.supported')) { - $this->markTestSkipped('PHPCR repository doesn\'t support versioning'); - } + $this->skipIfNotSupported(RepositoryInterface::OPTION_VERSIONING_SUPPORTED); - $ntm = self::$staticSharedFixture['session']->getWorkspace()->getNodeTypeManager(); + $ntm = $this->session->getWorkspace()->getNodeTypeManager(); $versionable = $ntm->getNodeType('mix:versionable'); $this->assertTrue($versionable->isNodeType('mix:versionable')); $this->assertTrue($versionable->isNodeType('mix:referenceable')); diff --git a/tests/10_Writing/AddMethodsTest.php b/tests/10_Writing/AddMethodsTest.php index b406ab52..699fa751 100644 --- a/tests/10_Writing/AddMethodsTest.php +++ b/tests/10_Writing/AddMethodsTest.php @@ -3,8 +3,10 @@ require_once(__DIR__ . '/../../inc/BaseCase.php'); -use PHPCR\PropertyType as Type; +use PHPCR\NodeType\ConstraintViolationException; +use PHPCR\PropertyType; use PHPCR\RepositoryInterface; +use PHPCR\ValueFormatException; /** * Covering jcr-283 spec $10.4 @@ -58,9 +60,9 @@ public function testAddNodeFileType() $path = $this->node->getPath(); $newNode = $this->node->addNode('newFileNode', 'nt:file'); $contentNode = $newNode->addNode('jcr:content', 'nt:resource'); - $contentNode->setProperty('jcr:mimeType', 'text/plain', Type::STRING); - $contentNode->setProperty('jcr:data', 'Hello', Type::BINARY); - $contentNode->setProperty('jcr:lastModified', new \DateTime('2010-12-12'), Type::DATE); + $contentNode->setProperty('jcr:mimeType', 'text/plain', PropertyType::STRING); + $contentNode->setProperty('jcr:data', 'Hello', PropertyType::BINARY); + $contentNode->setProperty('jcr:lastModified', new \DateTime('2010-12-12'), PropertyType::DATE); $this->assertNotNull($newNode, 'Node newFileNode was not created'); $this->assertTrue($newNode->isNew(), 'Node newFileNode is not marked dirty'); @@ -274,7 +276,7 @@ public function testAddNodeInParallel() */ public function testAddNodePathNotFound() { - $parent = $this->node->addNode('nonExistent/newNode', 'nt:unstructured'); + $this->node->addNode('nonExistent/newNode', 'nt:unstructured'); } /** @@ -297,10 +299,10 @@ public function testAddPropertyWrongType() try { $data->setProperty('jcr:lastModified', true); $this->saveAndRenewSession(); - } catch (\PHPCR\ValueFormatException $e) { + } catch (ValueFormatException $e) { //correct according to JSR-287 3.6.4 Property Type Conversion return; - } catch (\PHPCR\NodeType\ConstraintViolationException $e) { + } catch (ConstraintViolationException $e) { //also correct return; } @@ -344,7 +346,7 @@ public function testAddNodeChildProperties() $parent = $this->node->addNode('parent', 'nt:folder'); $child = $parent->addNode('child', 'nt:file'); $content = $child->addNode('jcr:content', 'nt:resource'); - $content->setProperty('jcr:data', '1234', \PHPCR\PropertyType::BINARY); + $content->setProperty('jcr:data', '1234', PropertyType::BINARY); $path = $child->getPath(); $this->saveAndRenewSession(); diff --git a/tests/10_Writing/CloneMethodsTest.php b/tests/10_Writing/CloneMethodsTest.php index 987ca122..9d10f698 100644 --- a/tests/10_Writing/CloneMethodsTest.php +++ b/tests/10_Writing/CloneMethodsTest.php @@ -1,6 +1,7 @@ getWorkspace(); } + /** + * Some of the tests in this test case assume that same name siblings are *not* supported. + * Those would fail if the repository supports same name siblings, so we skip them in that case. + */ private function skipIfSameNameSiblingsSupported() { - if ($this->session->getRepository()->getDescriptor('node.type.management.same.name.siblings.supported')) { + if ($this->session->getRepository()->getDescriptor(RepositoryInterface::NODE_TYPE_MANAGEMENT_SAME_NAME_SIBLINGS_SUPPORTED)) { $this->markTestSkipped('Test does not yet cover repositories that support same name siblings.'); } } diff --git a/tests/21_Transactions/TransactionMethodsTest.php b/tests/21_Transactions/TransactionMethodsTest.php index 35ca5dea..8976e084 100644 --- a/tests/21_Transactions/TransactionMethodsTest.php +++ b/tests/21_Transactions/TransactionMethodsTest.php @@ -3,6 +3,7 @@ require_once(__DIR__ . '/../../inc/BaseCase.php'); +use PHPCR\RepositoryInterface; use \PHPCR\Transaction; /** @@ -25,23 +26,21 @@ public function setUp() public function testGetTransactionManager() { - $session = self::$staticSharedFixture['session']; - $utx = $session->getWorkspace()->getTransactionManager(); + $utx = $this->session->getWorkspace()->getTransactionManager(); $this->assertInstanceOf('\PHPCR\Transaction\UserTransactionInterface', $utx); } public function testTransactionCommit() { - $session = self::$staticSharedFixture['session']; - $utx = $session->getWorkspace()->getTransactionManager(); + $utx = $this->session->getWorkspace()->getTransactionManager(); $utx->begin(); $child = $this->node->addNode('insideTransaction'); $this->assertEquals($this->node->getPath() . '/insideTransaction', $child->getPath()); - $session->save(); + $this->session->save(); $sessionbeforesave = self::$loader->getSession(); $this->assertFalse($sessionbeforesave->nodeExists($child->getPath())); @@ -55,19 +54,17 @@ public function testTransactionCommit() public function testTransactionRollback() { - $session = self::$staticSharedFixture['session']; - $copy = $this->node->addNode('copyTransaction'); $copiedNodePath = $this->node->getPath()."/copyTransactionCopy"; - $session->save(); + $this->session->save(); - $utx = $session->getWorkspace()->getTransactionManager(); + $utx = $this->session->getWorkspace()->getTransactionManager(); $child = $this->node->addNode('insideTransaction'); $utx->begin(); //workspace operation - $session->getWorkspace()->copy($copy->getPath(),$copiedNodePath); - $session->save(); + $this->session->getWorkspace()->copy($copy->getPath(),$copiedNodePath); + $this->session->save(); $this->assertFalse($child->isNew()); $utx->rollback(); @@ -79,7 +76,7 @@ public function testTransactionRollback() // semantics of rollback is that the local session state does not roll back // this must work - $session->save(); + $this->session->save(); $sessionaftersave = self::$loader->getSession(); $this->assertFalse($sessionaftersave->nodeExists($child->getPath())); @@ -88,20 +85,19 @@ public function testTransactionRollback() public function testInTransaction() { - $session = self::$staticSharedFixture['session']; - $utx= $session->getWorkspace()->getTransactionManager(); + $utx= $this->session->getWorkspace()->getTransactionManager(); $this->assertFalse($utx->inTransaction()); $utx->begin(); $this->node->addNode('insideTransaction0'); - $session->save(); + $this->session->save(); $this->assertTrue($utx->inTransaction()); $utx->commit(); $this->assertFalse($utx->inTransaction()); $utx->begin(); $this->node->addNode('insideTransaction1'); - $session->save(); + $this->session->save(); $this->assertTrue($utx->inTransaction()); $utx->rollback(); $this->assertFalse($utx->inTransaction()); @@ -114,19 +110,16 @@ public function testInTransaction() */ public function testIllegalCheckin() { - if (!self::$staticSharedFixture['session']->getRepository()->getDescriptor('option.versioning.supported')) { - $this->markTestSkipped('PHPCR repository doesn\'t support versioning'); - } + $this->skipIfNotSupported(RepositoryInterface::OPTION_VERSIONING_SUPPORTED); - $session = self::$staticSharedFixture['session']; - $vm = $session->getWorkspace()->getVersionManager(); + $vm = $this->session->getWorkspace()->getVersionManager(); - $utx= $session->getWorkspace()->getTransactionManager(); + $utx= $this->session->getWorkspace()->getTransactionManager(); $vm->checkout($this->node->getPath()); $this->node->setProperty('foo', 'bar2'); $utx->begin(); - $session->save(); + $this->session->save(); $vm->checkin($this->node->getPath()); }