Skip to content

Commit 6390ad1

Browse files
committed
Various fixes
1 parent a189ec6 commit 6390ad1

File tree

11 files changed

+114
-17
lines changed

11 files changed

+114
-17
lines changed

features/fixtures/cms.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,19 @@
1919
<sv:value>nt:unstructured</sv:value>
2020
</sv:property>
2121

22+
<sv:node sv:name="test">
23+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
24+
<sv:value>nt:unstructured</sv:value>
25+
</sv:property>
26+
</sv:node>
27+
2228
<sv:node sv:name="articles">
2329
<sv:property sv:name="jcr:primaryType" sv:type="Name">
2430
<sv:value>nt:unstructured</sv:value>
2531
</sv:property>
32+
<sv:property sv:name="jcr:mixinTypes" sv:type="name">
33+
<sv:value>mix:shareable</sv:value>
34+
</sv:property>
2635
<sv:node sv:name="article1">
2736
<sv:property sv:name="jcr:primaryType" sv:type="Name">
2837
<sv:value>nt:unstructured</sv:value>

features/phpcr_node_property_set.feature

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,18 @@ Feature: Set a node property
2222
| node:property:set thisisnew foobar --type=string | /properties/thisisnew | foobar |
2323

2424
Scenario: Update a property but do not specify the type
25-
Given I execute the "node:set /properties/decimal 1234" command
25+
Given I execute the "node:property:set /properties/decimal 1234" command
2626
And I execute the "node:list /properties" command
2727
Then I should see the following:
2828
"""
2929
decimal | DECIMAL
3030
"""
31+
32+
Scenario: Create a new property
33+
Given I execute the "node:property:set /properties/new 1234" command
34+
Then the command should not fail
35+
And I execute the "node:list /properties" command
36+
Then I should see the following:
37+
"""
38+
new | STRING
39+
"""

features/phpcr_node_property_show.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ hello world
3636
2011-04-21T14:34:20+01:00
3737
"""
3838

39+
Scenario: Attempt to show a node
40+
Given I execute the "node:property:show /tests_general_base" command
41+
Then the command should fail
42+
And I should see the following:
43+
"""
44+
Item at "/tests_general_base" is not a property
45+
"""
46+
3947
Scenario: Try to show non-existing property
4048
Given I execute the "node:property:show /this/path/does/not/exist" command
4149
Then the command should fail

features/shell_alias.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Feature: Command aliases
2020
| mv cms smc |
2121
| ls |
2222
| ls cms |
23-
| sl cms foobar |
24-
| cat cms |
23+
| sl cms/articles cms/test/foobar |
24+
| cat cms/articles/article1/title |
2525

2626
Scenario: List aliases
2727
Given I execute the "shell:alias:list" command

spec/PHPCR/Shell/Console/Helper/ConfigHelperSpec.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@
44

55
use PhpSpec\ObjectBehavior;
66
use Prophecy\Argument;
7+
use Symfony\Component\Filesystem\Filesystem;
78

89
class ConfigHelperSpec extends ObjectBehavior
910
{
11+
function let(
12+
Filesystem $filesystem
13+
)
14+
{
15+
$this->beConstructedWith($filesystem);
16+
}
17+
1018
function it_is_initializable()
1119
{
1220
$this->shouldHaveType('PHPCR\Shell\Console\Helper\ConfigHelper');
@@ -17,4 +25,19 @@ function it_should_have_a_method_to_get_the_users_config_directory()
1725
putenv('PHPCRSH_HOME=/home/foobar');
1826
$this->getConfigDir()->shouldReturn('/home/foobar');
1927
}
28+
29+
function it_should_be_able_to_parse_a_config_file_and_return_the_config_as_an_array(
30+
Filesystem $filesystem
31+
)
32+
{
33+
$dir = __DIR__ . '/fixtures/config';
34+
putenv('PHPCRSH_HOME=' . $dir);
35+
$filesystem->exists(Argument::any())->willReturn(true);
36+
37+
$config = $this->getConfig('alias')->shouldReturn(array(
38+
'foobar' => 'barfoo',
39+
'barfoo' => 'foobar',
40+
));
41+
42+
}
2043
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
foobar: barfoo
2+
barfoo: foobar

src/PHPCR/Shell/Console/Command/Phpcr/NodePropertySetCommand.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PHPCR\NamespaceException;
1313
use Symfony\Component\Console\Input\InputOption;
1414
use PHPCR\PropertyType;
15+
use PHPCR\PathNotFoundException;
1516

1617
class NodePropertySetCommand extends Command
1718
{
@@ -79,8 +80,13 @@ public function execute(InputInterface $input, OutputInterface $output)
7980
if ($type) {
8081
$intType = PropertyType::valueFromName($type);
8182
} else {
82-
$property = $node->getProperty($propName);
83-
$intType = $property->getType();
83+
try {
84+
$property = $node->getProperty($propName);
85+
$intType = $property->getType();
86+
} catch (PathNotFoundException $e) {
87+
// property doesn't exist and no type specified, default to string
88+
$intType = PropertyType::STRING;
89+
}
8490
}
8591

8692
$node->setProperty($propName, $value);

src/PHPCR/Shell/Console/Command/Phpcr/NodePropertyShowCommand.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Symfony\Component\Console\Output\OutputInterface;
88
use Symfony\Component\Console\Input\InputArgument;
99
use PHPCR\PathNotFoundException;
10+
use PHPCR\PropertyInterface;
1011

1112
class NodePropertyShowCommand extends Command
1213
{
@@ -24,7 +25,7 @@ protected function configure()
2425
public function execute(InputInterface $input, OutputInterface $output)
2526
{
2627
$session = $this->getHelper('phpcr')->getSession();
27-
$absPath = $input->getArgument('absPath');
28+
$absPath = $session->getAbsPath($input->getArgument('absPath'));
2829
$resultFormatHelper = $this->getHelper('result_formatter');
2930

3031
try {
@@ -35,6 +36,14 @@ public function execute(InputInterface $input, OutputInterface $output)
3536
));
3637
}
3738

39+
if (!$property instanceof PropertyInterface) {
40+
throw new \Exception(sprintf(
41+
'Item at "%s" is not a property.',
42+
$absPath
43+
));
44+
45+
}
46+
3847
$output->writeln($resultFormatHelper->formatValue($property, true));
3948
}
4049
}

src/PHPCR/Shell/Console/Command/Shell/ConfigInitCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ public function execute(InputInterface $input, OutputInterface $output)
2525
{
2626
$this->output = $output;
2727
$configHelper = $this->getHelper('config');
28-
$configHelper->initConfig($output, $this->getHelper('dialog'));
28+
$configHelper->initConfig($output, $this->getHelper('dialog'), $input->getOption('no-interaction'));
2929
}
3030
}

src/PHPCR/Shell/Console/Helper/ConfigHelper.php

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ class ConfigHelper extends Helper
3232
*/
3333
protected $cachedConfig = null;
3434

35+
/**
36+
* Filesystem
37+
*
38+
* @var Filesystem
39+
*/
40+
protected $filesystem;
41+
42+
public function __construct(Filesystem $filesystem = null)
43+
{
44+
if (null === $filesystem) {
45+
$filesystem = new Filesystem();
46+
}
47+
48+
$this->filesystem = $filesystem;
49+
}
50+
3551
/**
3652
* {@inheritDoc}
3753
*/
@@ -89,7 +105,7 @@ public function loadConfig()
89105
$fullPath = $configDir . '/' . $configKey . '.yml';
90106
$config[$configKey] = array();
91107

92-
if (file_exists($fullPath)) {
108+
if ($this->filesystem->exists($fullPath)) {
93109
$config[$configKey] = Yaml::parse($fullPath);
94110
}
95111
}
@@ -111,31 +127,31 @@ public function getConfig($type)
111127
}
112128

113129
$this->loadConfig();
130+
114131
return $this->cachedConfig[$type];
115132
}
116133

117134
/**
118135
* Initialize a configuration files
119136
*/
120-
public function initConfig(OutputInterface $output = null, DialogHelper $dialogHelper = null)
137+
public function initConfig(OutputInterface $output = null, DialogHelper $dialogHelper = null, $noInteraction = false)
121138
{
122139
$log = function ($message) use ($output) {
123140
if ($output) {
124141
$output->writeln($message);
125142
}
126143
};
127144

128-
$fs = new Filesystem();
129145
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
130146
throw new \RuntimeException('This feature is currently only supported on Linux and OSX (maybe). Please submit a PR to support it on windows.');
131147
}
132148

133149
$configDir = $this->getConfigDir();
134150
$distDir = __DIR__ . '/../../Resources/config.dist';
135151

136-
if (!file_exists($configDir)) {
152+
if (!$this->filesystem->exists($configDir)) {
137153
$log('<info>[+] Creating directory:</info> ' . $configDir);
138-
$fs->mkdir($configDir);
154+
$this->filesystem->mkdir($configDir);
139155
}
140156

141157
$configFilenames = array(
@@ -146,21 +162,28 @@ public function initConfig(OutputInterface $output = null, DialogHelper $dialogH
146162
$srcFile = $distDir . '/' . $configFilename;
147163
$destFile = $configDir . '/' . $configFilename;
148164

149-
if (!file_exists($srcFile)) {
165+
if (!$this->filesystem->exists($srcFile)) {
150166
throw new \Exception('Dist (source) file "' . $srcFile . '" does not exist.');
151167
}
152168

153-
if (file_exists($destFile)) {
169+
if ($this->filesystem->exists($destFile)) {
154170
if (null !== $dialogHelper) {
155-
if (!$dialogHelper->askConfirmation($output, '"' . $configFilename . '" already exists, do you want to overwrite it?')) {
156-
return 0;
171+
if (false === $noInteraction) {
172+
$confirmed = $dialogHelper->askConfirmation(
173+
$output,
174+
'"' . $configFilename . '" already exists, do you want to overwrite it?'
175+
);
176+
177+
if (!$confirmed) {
178+
return;
179+
}
157180
}
158181
} else {
159182
$log(sprintf('<info>File</info> %s <info> already exists, not overwriting.', $destFile));
160183
}
161184
}
162185

163-
$fs->copy($srcFile, $destFile);
186+
$this->filesystem->copy($srcFile, $destFile);
164187
$log('<info>[+] Creating file:</info> ' . $destFile);
165188
}
166189
}

src/PHPCR/Shell/Resources/config.dist/alias.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ mv: node:move {arg1} {arg2}
1212
pwd: shell:path:show
1313
exit: shell:exit
1414

15+
# Node commands
1516
ls: node:list {arg1}
1617
sl: node:clone {arg1} {arg2} # symlink, as in ln -s
1718
cp: node:copy {arg1} {arg2}
1819
cat: node:property:show {arg1}
1920

21+
# Node type commands
22+
mixins: node-type:list "^mix:"
23+
2024
# Editor commands
2125
vim: node:property:edit {arg1} {arg2}
2226
nano: node:property:edit {arg1} {arg2}
@@ -30,3 +34,7 @@ checkout: version:checkout {arg1}
3034
checkpoint: version:checkpoint {arg1}
3135
checkpoint: version:checkpoint {arg1}
3236
lsversion: version:history {arg1}
37+
38+
# Session commands
39+
save: session:save
40+
reload: session:reload

0 commit comments

Comments
 (0)