Skip to content

Commit 1ec3e1e

Browse files
committed
Merge pull request #30 from phpcr/profiles
Profiles
2 parents 36e9ace + 0fb0d28 commit 1ec3e1e

32 files changed

+979
-212
lines changed

README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ $ sudo cp phpcrsh.phar /usr/bin/local/phpcrsh
3030

3131
To connect to a doctrine-dbal PHPCR repository:
3232

33-
$ phpcr --db-name=foobar --db-username=user --db-password=foobar
33+
$ phpcr --transport=doctrine-dbal --db-name=foobar --db-username=user --db-password=foobar
3434

3535
Full definition:
3636

3737
````bash
3838
Usage:
39-
phpcr_shell [-h|--help] [-v|--verbose] [-V|--version] [--ansi] [--no-ansi] [-t|--transport="..."] [-pu|--phpcr-username="..."] [-pp|--phpcr-password[="..."]] [-pw|--phpcr-workspace[="..."]] [-du|--db-username="..."] [-dn|--db-name="..."] [-dp|--db-password[="..."]] [-dh|--db-host="..."] [-dd|--db-driver="..."] [-dP|--db-path="..."] [--no-interaction] [--unsupported] [-url|--repo-url="..."] [--command="..."]
39+
phpcrsh [-h|--help] [-v|--verbose] [-V|--version] [--ansi] [--no-ansi] [-t|--transport="..."] [-pu|--phpcr-username="..."] [-pp|--phpcr-password[="..."]] [-pw|--phpcr-workspace[="..."]] [-du|--db-username="..."] [-dn|--db-name="..."] [-dp|--db-password[="..."]] [-dh|--db-host="..."] [-dd|--db-driver="..."] [-dP|--db-path="..."] [--no-interaction] [--unsupported] [-url|--repo-url="..."] [--command="..."]
4040

4141
Options:
4242
--help (-h) Display this help message.
@@ -60,7 +60,32 @@ Options:
6060
--command Run the given command
6161
````
6262

63-
Todo:
63+
## Using profiles
64+
65+
Profiles enable you to save and reuse connection settings. Profiles can be
66+
created or used by using the `--profile` option.
67+
68+
To create or update a profile, use it in conjunction with `--transport`, i.e.:
69+
70+
````bash
71+
$ phpcrsh --profile=mydb --transport=doctrine-dbal --db-user=foobar --db-name=mydb
72+
Create new profile "mydb"?
73+
````
74+
75+
To use the profile:
76+
77+
````bash
78+
$ phpcrsh --profile=mydb
79+
````
80+
81+
Or use the short syntax:
82+
83+
````bash
84+
$ phpcrsh --pmydb
85+
````
86+
87+
88+
## Todo
6489

6590
- Better querying support
6691
- Better autocompletion

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"jackalope/jackalope-jackrabbit": "dev-master",
88
"jackalope/jackalope": "dev-master",
99
"phpcr/phpcr": "dev-master",
10-
"phpcr/phpcr-utils": "dev-master"
10+
"phpcr/phpcr-utils": "dev-master",
11+
"symfony/finder": "~2.0"
1112
},
1213
"require-dev": {
1314
"mockery/mockery": "0.9",
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
namespace spec\PHPCR\Shell\Config;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Prophecy\Argument;
7+
use PHPCR\Shell\Console\Helper\ConfigHelper;
8+
use PHPCR\Shell\Config\Profile;
9+
use Symfony\Component\Filesystem\Filesystem;
10+
11+
class ProfileLoaderSpec extends ObjectBehavior
12+
{
13+
function let(
14+
ConfigHelper $configHelper,
15+
Filesystem $filesystem
16+
)
17+
{
18+
$configHelper->getConfigDir()->willReturn(__DIR__);
19+
$this->beConstructedWith($configHelper, $filesystem);
20+
}
21+
22+
function it_is_initializable()
23+
{
24+
$this->shouldHaveType('PHPCR\Shell\Config\ProfileLoader');
25+
}
26+
27+
function it_should_list_profile_names()
28+
{
29+
$this->getProfileNames()->shouldReturn(array(
30+
'one', 'two'
31+
));
32+
}
33+
34+
function it_should_load_data_into_a_given_profile(
35+
Profile $profile,
36+
Filesystem $filesystem
37+
)
38+
{
39+
$profile->getName()->willReturn('one');
40+
$profile->set('transport', array(
41+
'name' => 'foobar',
42+
'bar_foo' => 'barfoo',
43+
'foo_bar' => 'foobar',
44+
))->shouldBeCalled();
45+
$profile->set('phpcr', array(
46+
'username' => 'username',
47+
'password' => 'password',
48+
'workspace' => 'default',
49+
))->shouldBeCalled();
50+
51+
$this->loadProfile($profile);
52+
}
53+
54+
function it_should_save_a_given_profile(
55+
Profile $profile,
56+
Filesystem $filesystem
57+
)
58+
{
59+
$profile->getName()->willReturn('newprofile');
60+
$profile->toArray()->willReturn(array(
61+
'transport' => array(
62+
'name' => 'test_transport',
63+
'option1' => 'value1',
64+
),
65+
'phpcr' => array(
66+
'username' => 'daniel',
67+
'password' => 'leech',
68+
),
69+
));
70+
$filesystem->dumpFile(Argument::type('string'), <<<EOT
71+
transport:
72+
name: test_transport
73+
option1: value1
74+
phpcr:
75+
username: daniel
76+
password: leech
77+
78+
EOT
79+
, 0600)->shouldBeCalled();
80+
$this->saveProfile($profile);
81+
}
82+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace spec\PHPCR\Shell\Config;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Prophecy\Argument;
7+
use PHPCR\Shell\Transport\TransportConfig;
8+
9+
class ProfileSpec extends ObjectBehavior
10+
{
11+
function let()
12+
{
13+
$this->beConstructedWith(
14+
'foobar'
15+
);
16+
}
17+
18+
function it_is_initializable()
19+
{
20+
$this->shouldHaveType('PHPCR\Shell\Config\Profile');
21+
}
22+
23+
function it_has_a_method_to_set_config(
24+
)
25+
{
26+
$this->set('transport', array());
27+
}
28+
29+
function it_has_a_method_to_get_config()
30+
{
31+
$this->set('transport', array(
32+
'foo' => 'bar'
33+
));
34+
35+
$this->get('transport')->shouldReturn(array(
36+
'foo' => 'bar'
37+
));
38+
39+
$this->get('transport', 'foo')->shouldReturn('bar');
40+
}
41+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
transport:
2+
name: foobar
3+
bar_foo: barfoo
4+
foo_bar: foobar
5+
phpcr:
6+
username: username
7+
password: password
8+
workspace: default
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
transport: daadoo
2+
dar_boo: darboo
3+
boo_dar: boodar

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44

55
use PhpSpec\ObjectBehavior;
66
use Prophecy\Argument;
7-
use Symfony\Component\Console\Input\InputInterface;
7+
use PHPCR\Shell\Config\Profile;
8+
use PHPCR\Shell\Transport\TransportRegistryInterface;
89

910
class PhpcrHelperSpec extends ObjectBehavior
1011
{
1112
function let(
12-
InputInterface $input
13+
Profile $profile,
14+
TransportRegistryInterface $transportRegistry
1315
) {
14-
$this->beConstructedWith($input);
16+
$this->beConstructedWith($transportRegistry, $profile);
1517
}
1618

1719
function it_is_initializable()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace spec\PHPCR\Shell\Event;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Prophecy\Argument;
7+
use PHPCR\Shell\Config\Profile;
8+
use Symfony\Component\Console\Input\InputInterface;
9+
use Symfony\Component\Console\Output\OutputInterface;
10+
11+
class ProfileInitEventSpec extends ObjectBehavior
12+
{
13+
function it_is_initializable()
14+
{
15+
$this->shouldHaveType('PHPCR\Shell\Event\ProfileInitEvent');
16+
}
17+
18+
function let(
19+
Profile $profile,
20+
InputInterface $input,
21+
OutputInterface $output
22+
)
23+
{
24+
$this->beConstructedWith(
25+
$profile, $input, $output
26+
);
27+
}
28+
29+
function it_should_have_getters(
30+
Profile $profile,
31+
InputInterface $input,
32+
OutputInterface $output
33+
)
34+
{
35+
$this->getProfile()->shouldReturn($profile);
36+
$this->getInput()->shouldReturn($input);
37+
$this->getOutput()->shouldReturn($output);
38+
}
39+
}

spec/PHPCR/Shell/Subscriber/AliasSubscriberSpec.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHPCR\Shell\Console\Helper\ConfigHelper;
88
use PHPCR\Shell\Console\Input\StringInput;
99
use PHPCR\Shell\Event\CommandPreRunEvent;
10+
use Symfony\Component\Console\Helper\HelperSet;
1011

1112
class AliasSubscriberSpec extends ObjectBehavior
1213
{
@@ -16,10 +17,13 @@ function it_is_initializable()
1617
}
1718

1819
function let(
20+
HelperSet $helperSet,
1921
ConfigHelper $config
2022
) {
23+
$helperSet->get('config')->willReturn($config);
24+
2125
$this->beConstructedWith(
22-
$config
26+
$helperSet
2327
);
2428

2529
$config->getConfig('alias')->willReturn(array(
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace spec\PHPCR\Shell\Transport\Transport;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Prophecy\Argument;
7+
8+
class DoctrineDbalSpec extends ObjectBehavior
9+
{
10+
function it_is_initializable()
11+
{
12+
$this->shouldHaveType('PHPCR\Shell\Transport\Transport\DoctrineDbal');
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace spec\PHPCR\Shell\Transport\Transport;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Prophecy\Argument;
7+
8+
class JackrabbitSpec extends ObjectBehavior
9+
{
10+
function it_is_initializable()
11+
{
12+
$this->shouldHaveType('PHPCR\Shell\Transport\Transport\Jackrabbit');
13+
}
14+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace spec\PHPCR\Shell\Transport;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Prophecy\Argument;
7+
use PHPCR\Shell\Transport\TransportInterface;
8+
9+
class TransportRegistrySpec extends ObjectBehavior
10+
{
11+
function it_is_initializable()
12+
{
13+
$this->shouldHaveType('PHPCR\Shell\Transport\TransportRegistry');
14+
}
15+
16+
function it_can_register_transports(
17+
TransportInterface $transport
18+
)
19+
{
20+
$transport->getName()->willReturn('foobar');
21+
$this->register($transport);
22+
}
23+
24+
function it_can_return_the_names_of_the_transports(
25+
TransportInterface $transport1,
26+
TransportInterface $transport2
27+
)
28+
{
29+
$transport1->getName()->willReturn('transport1');
30+
$transport2->getName()->willReturn('transport2');
31+
$this->register($transport1);
32+
$this->register($transport2);
33+
34+
$this->getTransportNames()->shouldReturn(array(
35+
'transport1', 'transport2'
36+
));
37+
}
38+
39+
function it_can_return_a_named_transport_object(
40+
TransportInterface $transport
41+
)
42+
{
43+
$transport->getName()->willReturn('test');
44+
$this->register($transport);
45+
46+
$this->getTransport('test')->shouldReturn($transport);
47+
}
48+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Config\Exception;
4+
5+
class FileExistsException extends \Exception
6+
{
7+
}

0 commit comments

Comments
 (0)