Skip to content

Commit 90f5329

Browse files
committed
Merge pull request #137 from phpcr/profile_overwritten
Load the profile after setting the config from the Input
2 parents fa90a41 + 29ca2d6 commit 90f5329

File tree

15 files changed

+231
-17
lines changed

15 files changed

+231
-17
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ php:
99
- 5.4
1010

1111
before_script:
12+
- composer self-update
1213
- composer require "symfony/symfony" "2.6.*" --no-update
1314
- composer install
1415
- bash tests/bin/travis_jackrabbit.sh

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dev-master
88
### Bug fixes
99

1010
- [embedded] No exit code returned
11+
- [profile] Profile configuration overwritten by session parameters
1112

1213
beta1
1314
-----

behat.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ default:
1414
- PHPCR\Shell\Test\EmbeddedContext
1515
paths:
1616
- features/all
17+
cli:
18+
contexts:
19+
- PHPCR\Shell\Test\CliContext
20+
paths:
21+
- features/cli

features/all/phpcr_node_edit.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Feature: Edit a node
77
Given that I am logged in as "testuser"
88
And the "cms.xml" fixtures are loaded
99

10-
Scenario: Make a nutral edit
10+
Scenario: Make a neutral edit
1111
Given I have an editor which produces the following:
1212
""""
1313
weight:
@@ -91,7 +91,7 @@ Feature: Edit a node
9191
And I save the session
9292
Then the command should not fail
9393
And the property "/cms/products/product1/weight" should have type "Long" and value "10"
94-
And the property "/cms/products/product1/cost" should have type "Long" and value "100"
94+
And the property "/cms/products/product1/cost" should have type "Double" and value "100"
9595
And the property "/cms/products/product1/size" should have type "String" and value "XXL"
9696
And the property "/cms/products/product1/name" should have type "String" and value "Product One"
9797
And the property "/cms/products/product1/jcr:primaryType" should have type "Name" and value "nt:unstructured"

features/cli/doctrine-dbal.feature

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Feature: Connect to a doctrine dbal repository
2+
In order to use the jackalope doctrine-dbal repository
3+
As a user
4+
I need to be able to connect to it
5+
6+
Background:
7+
Given I initialize doctrine dbal
8+
9+
Scenario: Connect to doctrine-dbal session
10+
Given I run PHPCR shell with "--transport=doctrine-dbal --db-driver=pdo_sqlite --db-path=./app.sqlite --command='ls'"
11+
Then the command should not fail
12+
13+
Scenario: Connect to doctrine-dbal session create a new profile
14+
Given I run PHPCR shell with "--transport=doctrine-dbal --db-driver=pdo_sqlite --db-path=./app.sqlite --profile=new --no-interaction --command='ls'"
15+
Then the command should not fail
16+
17+
Scenario: Connect to an existing profile
18+
Given the following profile "phpcrtest" exists:
19+
"""
20+
transport:
21+
name: doctrine-dbal
22+
db_name: phpcrtest
23+
db_path: app.sqlite
24+
db_driver: pdo_sqlite
25+
phpcr:
26+
workspace: default
27+
username: admin
28+
password: admin
29+
"""
30+
And I run PHPCR shell with "--profile=phpcrtest --no-interaction --command='ls'"
31+
Then the command should not fail
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
$dbConn = \Doctrine\DBAL\DriverManager::getConnection(array(
3+
'driver' => 'pdo_sqlite',
4+
'dbname' => 'test',
5+
'path' => __DIR__.'/app.sqlite',
6+
));
7+
8+
/*
9+
* configuration
10+
*/
11+
$workspace = 'default'; // phpcr workspace to use
12+
$user = 'admin';
13+
$pass = 'admin';
14+
15+
$factory = new \Jackalope\RepositoryFactoryDoctrineDBAL();
16+
$repository = $factory->getRepository(array('jackalope.doctrine_dbal_connection' => $dbConn));
17+
18+
$credentials = new \PHPCR\SimpleCredentials($user, $pass);
19+
20+
/* only create a session if this is not about the server control command */
21+
if (isset($argv[1])
22+
&& $argv[1] != 'jackalope:init:dbal'
23+
&& $argv[1] != 'list'
24+
&& $argv[1] != 'help'
25+
) {
26+
$session = $repository->login($credentials, $workspace);
27+
28+
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
29+
'dialog' => new \Symfony\Component\Console\Helper\DialogHelper(),
30+
'phpcr' => new \PHPCR\Util\Console\Helper\PhpcrHelper($session),
31+
'phpcr_console_dumper' => new \PHPCR\Util\Console\Helper\PhpcrConsoleDumperHelper(),
32+
));
33+
} else if (isset($argv[1]) && $argv[1] == 'jackalope:init:dbal') {
34+
// special case: the init command needs the db connection, but a session is impossible if the db is not yet initialized
35+
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
36+
'connection' => new \Jackalope\Tools\Console\Helper\DoctrineDbalHelper($dbConn)
37+
));
38+
}
39+

spec/PHPCR/Shell/Config/ProfileSpec.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace spec\PHPCR\Shell\Config;
1313

1414
use PhpSpec\ObjectBehavior;
15+
use PHPCR\Shell\Config\Config;
1516

1617
class ProfileSpec extends ObjectBehavior
1718
{
@@ -39,9 +40,7 @@ public function it_has_a_method_to_get_config()
3940
'foo' => 'bar'
4041
));
4142

42-
$this->get('transport')->shouldReturn(array(
43-
'foo' => 'bar'
44-
));
43+
$this->get('transport')->shouldHaveType('PHPCR\Shell\Config\Config');
4544

4645
$this->get('transport', 'foo')->shouldReturn('bar');
4746
}

src/PHPCR/Shell/Config/Profile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function get($domain, $key = null)
8080
$this->validateDomain($domain);
8181

8282
if (null === $key) {
83-
return $this->profile[$domain];
83+
return new Config($this->profile[$domain]);
8484
}
8585

8686
if (!isset($this->profile[$domain][$key])) {

src/PHPCR/Shell/DependencyInjection/Container.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ public function registerPhpcr()
104104
public function registerEvent()
105105
{
106106
if ($this->mode === PhpcrShell::MODE_STANDALONE) {
107+
$this->register(
108+
'event.subscriber.profile_from_session_input',
109+
'PHPCR\Shell\Subscriber\ProfileFromSessionInputSubscriber'
110+
)->addTag('event.subscriber');
111+
107112
$this->register(
108113
'event.subscriber.profile_loader',
109114
'PHPCR\Shell\Subscriber\ProfileLoaderSubscriber'
@@ -112,11 +117,6 @@ public function registerEvent()
112117
->addArgument(new Reference('helper.question'))
113118
->addTag('event.subscriber');
114119

115-
$this->register(
116-
'event.subscriber.profile_from_session_input',
117-
'PHPCR\Shell\Subscriber\ProfileFromSessionInputSubscriber'
118-
)->addTag('event.subscriber');
119-
120120
$this->register(
121121
'event.subscriber.profile_writer',
122122
'PHPCR\Shell\Subscriber\ProfileWriterSubscriber'

src/PHPCR/Shell/Subscriber/ProfileWriterSubscriber.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function handleProfileInit(ProfileInitEvent $e)
4040
$profile = $e->getProfile();
4141
$input = $e->getInput();
4242
$output = $e->getOutput();
43+
$noInteraction = $input->getOption('no-interaction');
4344
$transport = $input->getOption('transport');
4445
$profileName = $input->getOption('profile');
4546

@@ -50,10 +51,17 @@ public function handleProfileInit(ProfileInitEvent $e)
5051
$overwrite = false;
5152

5253
if (file_exists($this->profileLoader->getProfilePath($profileName))) {
53-
$res = $this->questionHelper->askConfirmation($output, sprintf('Update existing profile "%s"?', $profileName));
54+
$res = true;
55+
if (false === $noInteraction) {
56+
$res = $this->questionHelper->askConfirmation($output, sprintf('Update existing profile "%s"?', $profileName));
57+
}
5458
$overwrite = true;
5559
} else {
56-
$res = $this->questionHelper->askConfirmation($output, sprintf('Create new profile "%s"?', $profileName));
60+
$res = true;
61+
62+
if (false === $noInteraction) {
63+
$res = $this->questionHelper->askConfirmation($output, sprintf('Create new profile "%s"?', $profileName));
64+
}
5765
}
5866

5967
if ($res) {

0 commit comments

Comments
 (0)