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) {

src/PHPCR/Shell/Test/CliContext.php

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the PHPCR Shell package
5+
*
6+
* (c) Daniel Leech <daniel@dantleech.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace PHPCR\Shell\Test;
13+
14+
use Jackalope\RepositoryFactoryJackrabbit;
15+
use PHPCR\SimpleCredentials;
16+
use PHPCR\Util\NodeHelper;
17+
use Symfony\Component\Filesystem\Filesystem;
18+
use PHPCR\PathNotFoundException;
19+
use PHPCR\Util\PathHelper;
20+
use PHPCR\PropertyInterface;
21+
use PHPCR\PropertyType;
22+
use Behat\Behat\Context\SnippetAcceptingContext;
23+
use Behat\Behat\Context\Context;
24+
use PHPCR\NodeInterface;
25+
use Behat\Gherkin\Node\PyStringNode;
26+
use Behat\Gherkin\Node\TableNode;
27+
28+
/**
29+
* Features context.
30+
*/
31+
class CliContext implements Context, SnippetAcceptingContext
32+
{
33+
private $output = array();
34+
private $rootPath;
35+
private $lastExitCode;
36+
private $fixturesDir;
37+
38+
/**
39+
* Initializes context.
40+
* Every scenario gets it's own context object.
41+
*
42+
* @BeforeScenario
43+
*/
44+
public function beforeScenario()
45+
{
46+
$this->output = array();
47+
48+
$this->rootPath = realpath(__DIR__ . '/../../../..');
49+
$dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'phpcr-shell' . DIRECTORY_SEPARATOR .
50+
md5(microtime() * rand(0, 10000));
51+
$this->fixturesDir = realpath(__DIR__.'/../../../../features/fixtures/');
52+
53+
$this->workingDir = $dir;
54+
putenv('PHPCRSH_HOME=' . $dir);
55+
56+
mkdir($this->workingDir, 0777, true);
57+
mkdir($this->workingDir . '/profiles');
58+
chdir($this->workingDir);
59+
$this->filesystem = new Filesystem();
60+
}
61+
62+
/**
63+
* Cleans test folders in the temporary directory.
64+
*
65+
* @AfterSuite
66+
*/
67+
public static function cleanTestFolders()
68+
{
69+
$fs = new Filesystem();
70+
$fs->remove(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'phpcr-shell');
71+
}
72+
73+
private function exec($command)
74+
{
75+
exec($command, $output, $return);
76+
$this->output += $output;
77+
$this->lastExitCode = $return;
78+
}
79+
80+
/**
81+
* @Given I run PHPCR shell with ":argsAndOptions"
82+
*/
83+
public function execShell($argsAndOptions)
84+
{
85+
$this->exec(sprintf('%s/bin/phpcrsh %s', $this->rootPath, $argsAndOptions));
86+
}
87+
88+
/**
89+
* @Given print output
90+
*/
91+
public function printOutput()
92+
{
93+
foreach ($this->output as $line) {
94+
echo $line . PHP_EOL;
95+
}
96+
}
97+
98+
/**
99+
* @Given the following profile ":profileName" exists:
100+
*/
101+
public function iHaveTheFollowingProfile($profileName, PyStringNode $text)
102+
{
103+
file_put_contents($this->workingDir . '/profiles/' . $profileName . '.yml', $text->getRaw());
104+
}
105+
106+
/**
107+
* @Given I initialize doctrine dbal
108+
*/
109+
public function initializeDoctrineDbal()
110+
{
111+
$this->filesystem->copy(
112+
$this->fixturesDir . '/jackalope-doctrine-dbal-cli-config.php',
113+
$this->workingDir . '/cli-config.php'
114+
);
115+
$this->exec($this->rootPath . '/vendor/jackalope/jackalope-doctrine-dbal/bin/jackalope jackalope:init:dbal --force');
116+
}
117+
118+
/**
119+
* @Then the command should not fail
120+
*/
121+
public function theCommandShouldNotFail()
122+
{
123+
\PHPUnit_Framework_Assert::assertEquals(0, $this->lastExitCode);
124+
}
125+
}

src/PHPCR/Shell/Transport/Transport/DoctrineDbal.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\DBAL\DriverManager;
1515
use Jackalope\RepositoryFactoryDoctrineDBAL;
1616
use PHPCR\Shell\Transport\TransportInterface;
17+
use PHPCR\Shell\Config\Config;
1718

1819
class DoctrineDbal implements TransportInterface
1920
{
@@ -22,7 +23,7 @@ public function getName()
2223
return 'doctrine-dbal';
2324
}
2425

25-
public function getRepository(array $config)
26+
public function getRepository(Config $config)
2627
{
2728
$connection = DriverManager::getConnection($ops = array(
2829
'user' => $config['db_username'],

src/PHPCR/Shell/Transport/Transport/JackalopeFs.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPCR\Shell\Transport\TransportInterface;
1515
use Jackalope\RepositoryFactoryFilesystem;
16+
use PHPCR\Shell\Config\Config;
1617

1718
class JackalopeFs implements TransportInterface
1819
{
@@ -21,7 +22,7 @@ public function getName()
2122
return 'jackalope-fs';
2223
}
2324

24-
public function getRepository(array $config)
25+
public function getRepository(Config $config)
2526
{
2627
$params = array(
2728
'path' => $config['repo_path'],

src/PHPCR/Shell/Transport/Transport/Jackrabbit.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Jackalope\RepositoryFactoryJackrabbit;
1515
use PHPCR\Shell\Transport\TransportInterface;
16+
use PHPCR\Shell\Config\Config;
1617

1718
class Jackrabbit implements TransportInterface
1819
{
@@ -21,7 +22,7 @@ public function getName()
2122
return 'jackrabbit';
2223
}
2324

24-
public function getRepository(array $config)
25+
public function getRepository(Config $config)
2526
{
2627
$params = array(
2728
'jackalope.jackrabbit_uri' => $config['repo_url'],

src/PHPCR/Shell/Transport/TransportInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace PHPCR\Shell\Transport;
1313

14+
use PHPCR\Shell\Config\Config;
15+
1416
/**
1517
* All phpcr-shell transports must implement this interface
1618
*
@@ -20,5 +22,5 @@ interface TransportInterface
2022
{
2123
public function getName();
2224

23-
public function getRepository(array $config);
25+
public function getRepository(Config $config);
2426
}

0 commit comments

Comments
 (0)