Skip to content

Commit ec645f5

Browse files
committed
Merge branch 'improve-test-coverage' into clean-dump-command
2 parents 9894a06 + a00e8f1 commit ec645f5

File tree

4 files changed

+76
-29
lines changed

4 files changed

+76
-29
lines changed

src/PHPCR/Util/Console/Command/BaseCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22

33
namespace PHPCR\Util\Console\Command;
44

5+
use PHPCR\SessionInterface;
56
use Symfony\Component\Console\Command\Command;
67
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Input\InputOption;
79
use Symfony\Component\Console\Output\OutputInterface;
810
use PHPCR\Util\Console\Helper\PhpcrCliHelper;
9-
use Symfony\Component\Console\Input\InputOption;
1011

1112
abstract class BaseCommand extends Command
1213
{
1314
/**
14-
* @return PHPCR\SessionInterface
15+
* @return SessionInterface
1516
*/
1617
protected function getPhpcrSession()
1718
{
1819
return $this->getHelper('phpcr')->getSession();
1920
}
2021

2122
/**
22-
* @return PHPCR\Util\Console\Helper\PhpcrCliHelper
23+
* @return PhpcrCliHelper
2324
*/
2425
protected function getPhpcrCliHelper()
2526
{

src/PHPCR/Util/NodeHelper.php

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

2424
use PHPCR\ItemInterface;
2525
use PHPCR\NodeInterface;
26+
use PHPCR\PropertyInterface;
2627
use PHPCR\PropertyType;
2728
use PHPCR\SessionInterface;
2829
use PHPCR\RepositoryException;
@@ -50,7 +51,7 @@ private function __construct()
5051
* @param SessionInterface $session the PHPCR session to create the path
5152
* @param string $path full path, like /content/jobs/data
5253
*
53-
* @return \PHPCR\NodeInterface the last node of the path, i.e. data
54+
* @return NodeInterface the last node of the path, i.e. data
5455
*/
5556
public static function createPath(SessionInterface $session, $path)
5657
{
@@ -87,12 +88,14 @@ public static function purgeWorkspace(SessionInterface $session)
8788
{
8889
$root = $session->getRootNode();
8990

91+
/** @var $property PropertyInterface */
9092
foreach ($root->getProperties() as $property) {
9193
if (! self::isSystemItem($property)) {
9294
$property->remove();
9395
}
9496
}
9597

98+
/** @var $node NodeInterface */
9699
foreach ($root->getNodes() as $node) {
97100
if (! self::isSystemItem($node)) {
98101
$node->remove();
@@ -111,13 +114,17 @@ public static function deleteAllNodes(SessionInterface $session)
111114
}
112115

113116
/**
114-
* Determine whether this item has a namespace that is to be considered
115-
* a system namespace
117+
* Determine whether this item is to be considered a system item that you
118+
* usually want to hide and that should not be removed when purging the
119+
* repository.
116120
*
117121
* @param ItemInterface $item
118122
*/
119123
public static function isSystemItem(ItemInterface $item)
120124
{
125+
if ($item->getDepth() > 1) {
126+
return false;
127+
}
121128
$name = $item->getName();
122129

123130
return strpos($name, 'jcr:') === 0 || strpos($name, 'rep:') === 0;

tests/PHPCR/Tests/Util/Console/Command/BaseCommandTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace PHPCR\Tests\Util\Console\Command;
44

5+
use PHPCR\NodeInterface;
6+
use PHPCR\Query\QueryManagerInterface;
7+
use PHPCR\Query\RowInterface;
58
use PHPCR\RepositoryInterface;
69
use Symfony\Component\Console\Application;
710
use Symfony\Component\Console\Tester\CommandTester;
@@ -24,6 +27,12 @@ abstract class BaseCommandTest extends \PHPUnit_Framework_TestCase
2427
protected $workspace;
2528
/** @var RepositoryInterface|\PHPUnit_Framework_MockObject_MockObject */
2629
protected $repository;
30+
/** @var NodeInterface|\PHPUnit_Framework_MockObject_MockObject */
31+
protected $node1;
32+
/** @var RowInterface|\PHPUnit_Framework_MockObject_MockObject */
33+
protected $row1;
34+
/** @var QueryManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
35+
protected $queryManager;
2736
/** @var PhpcrConsoleDumperHelper|\PHPUnit_Framework_MockObject_MockObject */
2837
protected $dumperHelper;
2938
/** @var HelperSet */
@@ -86,7 +95,7 @@ public function executeCommand($name, $args, $status = 0)
8695
$args = array_merge(array(
8796
'command' => $command->getName(),
8897
), $args);
89-
$this->assertEquals(0, $commandTester->execute($args));
98+
$this->assertEquals($status, $commandTester->execute($args));
9099

91100
return $commandTester;
92101
}

tests/PHPCR/Tests/Util/PathHelperTest.php

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public function testAssertValidPathIndexed()
2828
$this->assertTrue(PathHelper::assertValidAbsolutePath('/parent[7]/child'));
2929
}
3030

31+
public function testAssertValidPathIndexedAtEnd()
32+
{
33+
$this->assertTrue(PathHelper::assertValidAbsolutePath('/parent[7]/child[3]'));
34+
}
35+
3136
/**
3237
* @expectedException \PHPCR\RepositoryException
3338
*/
@@ -138,43 +143,40 @@ public function testNormalizePath($inputPath, $outputPath)
138143
public static function dataproviderNormalizePath()
139144
{
140145
return array(
141-
array('/../foo', '/foo'),
142-
array('/../', '/'),
143-
array('/foo/../bar', '/bar'),
144-
array('/foo/./bar', '/foo/bar'),
146+
array('/', '/'),
147+
array('/../foo', '/foo'),
148+
array('/../', '/'),
149+
array('/foo/../bar', '/bar'),
150+
array('/foo/./bar', '/foo/bar'),
145151
);
146152
}
147153

148-
/**
149-
* @expectedException \PHPCR\RepositoryException
150-
*/
151-
public function testNormalizePathInvalid()
152-
{
153-
PathHelper::normalizePath('foo/bar');
154-
}
155-
156-
/**
157-
* @expectedException \PHPCR\RepositoryException
158-
*/
159-
public function testNormalizePathShortInvalid()
154+
public static function dataproviderNormalizePathInvalid()
160155
{
161-
PathHelper::normalizePath('bar');
156+
return array(
157+
array('foo/bar'),
158+
array('bar'),
159+
array('/foo/bar/'),
160+
array(''),
161+
array(new \stdClass()),
162+
);
162163
}
163164

164165
/**
166+
* @dataProvider dataproviderNormalizePathInvalid
165167
* @expectedException \PHPCR\RepositoryException
166168
*/
167-
public function testNormalizePathTrailing()
169+
public function testNormalizePathInvalidThrow($input)
168170
{
169-
PathHelper::normalizePath('/foo/bar/');
171+
PathHelper::normalizePath($input);
170172
}
171173

172174
/**
173-
* @expectedException \PHPCR\RepositoryException
175+
* @dataProvider dataproviderNormalizePathInvalid
174176
*/
175-
public function testNormalizePathEmpty()
177+
public function testNormalizePathInvalidNoThrow($input)
176178
{
177-
PathHelper::normalizePath('');
179+
$this->assertFalse(PathHelper::normalizePath($input, true, false));
178180
}
179181

180182
// absolutizePath tests
@@ -197,6 +199,34 @@ public static function dataproviderAbsolutizePath()
197199
);
198200
}
199201

202+
/**
203+
* @expectedException \PHPCR\RepositoryException
204+
* @dataProvider dataproviderAbsolutizePathInvalid
205+
*/
206+
public function testAbsolutizePathInvalidThrow($inputPath, $context, $target)
207+
{
208+
PathHelper::absolutizePath($inputPath, $context, $target);
209+
}
210+
211+
/**
212+
* @dataProvider dataproviderAbsolutizePathInvalid
213+
*/
214+
public function testAbsolutizePathInvalidNoThrow($inputPath, $context, $target)
215+
{
216+
$this->assertFalse(PathHelper::absolutizePath($inputPath, $context, $target, false));
217+
}
218+
219+
public static function dataproviderAbsolutizePathInvalid()
220+
{
221+
return array(
222+
array('', '/context', false),
223+
array(null, '/context', false),
224+
array('foo', null, false),
225+
array(new \stdClass(), '/context', false),
226+
array('foo[2]', '/bar', true),
227+
);
228+
}
229+
200230
// getParentPath tests
201231

202232
public function testGetParentPath()

0 commit comments

Comments
 (0)