Skip to content

Profiles #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ $ sudo cp phpcrsh.phar /usr/bin/local/phpcrsh

To connect to a doctrine-dbal PHPCR repository:

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

Full definition:

````bash
Usage:
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="..."]
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="..."]

Options:
--help (-h) Display this help message.
Expand All @@ -60,7 +60,32 @@ Options:
--command Run the given command
````

Todo:
## Using profiles

Profiles enable you to save and reuse connection settings. Profiles can be
created or used by using the `--profile` option.

To create or update a profile, use it in conjunction with `--transport`, i.e.:

````bash
$ phpcrsh --profile=mydb --transport=doctrine-dbal --db-user=foobar --db-name=mydb
Create new profile "mydb"?
````

To use the profile:

````bash
$ phpcrsh --profile=mydb
````

Or use the short syntax:

````bash
$ phpcrsh --pmydb
````


## Todo

- Better querying support
- Better autocompletion
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"jackalope/jackalope-jackrabbit": "dev-master",
"jackalope/jackalope": "dev-master",
"phpcr/phpcr": "dev-master",
"phpcr/phpcr-utils": "dev-master"
"phpcr/phpcr-utils": "dev-master",
"symfony/finder": "~2.0"
},
"require-dev": {
"mockery/mockery": "0.9",
Expand Down
82 changes: 82 additions & 0 deletions spec/PHPCR/Shell/Config/ProfileLoaderSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace spec\PHPCR\Shell\Config;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use PHPCR\Shell\Console\Helper\ConfigHelper;
use PHPCR\Shell\Config\Profile;
use Symfony\Component\Filesystem\Filesystem;

class ProfileLoaderSpec extends ObjectBehavior
{
function let(
ConfigHelper $configHelper,
Filesystem $filesystem
)
{
$configHelper->getConfigDir()->willReturn(__DIR__);
$this->beConstructedWith($configHelper, $filesystem);
}

function it_is_initializable()
{
$this->shouldHaveType('PHPCR\Shell\Config\ProfileLoader');
}

function it_should_list_profile_names()
{
$this->getProfileNames()->shouldReturn(array(
'one', 'two'
));
}

function it_should_load_data_into_a_given_profile(
Profile $profile,
Filesystem $filesystem
)
{
$profile->getName()->willReturn('one');
$profile->set('transport', array(
'name' => 'foobar',
'bar_foo' => 'barfoo',
'foo_bar' => 'foobar',
))->shouldBeCalled();
$profile->set('phpcr', array(
'username' => 'username',
'password' => 'password',
'workspace' => 'default',
))->shouldBeCalled();

$this->loadProfile($profile);
}

function it_should_save_a_given_profile(
Profile $profile,
Filesystem $filesystem
)
{
$profile->getName()->willReturn('newprofile');
$profile->toArray()->willReturn(array(
'transport' => array(
'name' => 'test_transport',
'option1' => 'value1',
),
'phpcr' => array(
'username' => 'daniel',
'password' => 'leech',
),
));
$filesystem->dumpFile(Argument::type('string'), <<<EOT
transport:
name: test_transport
option1: value1
phpcr:
username: daniel
password: leech

EOT
, 0600)->shouldBeCalled();
$this->saveProfile($profile);
}
}
41 changes: 41 additions & 0 deletions spec/PHPCR/Shell/Config/ProfileSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace spec\PHPCR\Shell\Config;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use PHPCR\Shell\Transport\TransportConfig;

class ProfileSpec extends ObjectBehavior
{
function let()
{
$this->beConstructedWith(
'foobar'
);
}

function it_is_initializable()
{
$this->shouldHaveType('PHPCR\Shell\Config\Profile');
}

function it_has_a_method_to_set_config(
)
{
$this->set('transport', array());
}

function it_has_a_method_to_get_config()
{
$this->set('transport', array(
'foo' => 'bar'
));

$this->get('transport')->shouldReturn(array(
'foo' => 'bar'
));

$this->get('transport', 'foo')->shouldReturn('bar');
}
}
8 changes: 8 additions & 0 deletions spec/PHPCR/Shell/Config/profiles/one.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
transport:
name: foobar
bar_foo: barfoo
foo_bar: foobar
phpcr:
username: username
password: password
workspace: default
3 changes: 3 additions & 0 deletions spec/PHPCR/Shell/Config/profiles/two.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
transport: daadoo
dar_boo: darboo
boo_dar: boodar
8 changes: 5 additions & 3 deletions spec/PHPCR/Shell/Console/Helper/PhpcrHelperSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\Console\Input\InputInterface;
use PHPCR\Shell\Config\Profile;
use PHPCR\Shell\Transport\TransportRegistryInterface;

class PhpcrHelperSpec extends ObjectBehavior
{
function let(
InputInterface $input
Profile $profile,
TransportRegistryInterface $transportRegistry
) {
$this->beConstructedWith($input);
$this->beConstructedWith($transportRegistry, $profile);
}

function it_is_initializable()
Expand Down
39 changes: 39 additions & 0 deletions spec/PHPCR/Shell/Event/ProfileInitEventSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace spec\PHPCR\Shell\Event;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use PHPCR\Shell\Config\Profile;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class ProfileInitEventSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('PHPCR\Shell\Event\ProfileInitEvent');
}

function let(
Profile $profile,
InputInterface $input,
OutputInterface $output
)
{
$this->beConstructedWith(
$profile, $input, $output
);
}

function it_should_have_getters(
Profile $profile,
InputInterface $input,
OutputInterface $output
)
{
$this->getProfile()->shouldReturn($profile);
$this->getInput()->shouldReturn($input);
$this->getOutput()->shouldReturn($output);
}
}
6 changes: 5 additions & 1 deletion spec/PHPCR/Shell/Subscriber/AliasSubscriberSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PHPCR\Shell\Console\Helper\ConfigHelper;
use PHPCR\Shell\Console\Input\StringInput;
use PHPCR\Shell\Event\CommandPreRunEvent;
use Symfony\Component\Console\Helper\HelperSet;

class AliasSubscriberSpec extends ObjectBehavior
{
Expand All @@ -16,10 +17,13 @@ function it_is_initializable()
}

function let(
HelperSet $helperSet,
ConfigHelper $config
) {
$helperSet->get('config')->willReturn($config);

$this->beConstructedWith(
$config
$helperSet
);

$config->getConfig('alias')->willReturn(array(
Expand Down
14 changes: 14 additions & 0 deletions spec/PHPCR/Shell/Transport/Transport/DoctrineDbalSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace spec\PHPCR\Shell\Transport\Transport;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class DoctrineDbalSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('PHPCR\Shell\Transport\Transport\DoctrineDbal');
}
}
14 changes: 14 additions & 0 deletions spec/PHPCR/Shell/Transport/Transport/JackrabbitSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace spec\PHPCR\Shell\Transport\Transport;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class JackrabbitSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('PHPCR\Shell\Transport\Transport\Jackrabbit');
}
}
48 changes: 48 additions & 0 deletions spec/PHPCR/Shell/Transport/TransportRegistrySpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace spec\PHPCR\Shell\Transport;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use PHPCR\Shell\Transport\TransportInterface;

class TransportRegistrySpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('PHPCR\Shell\Transport\TransportRegistry');
}

function it_can_register_transports(
TransportInterface $transport
)
{
$transport->getName()->willReturn('foobar');
$this->register($transport);
}

function it_can_return_the_names_of_the_transports(
TransportInterface $transport1,
TransportInterface $transport2
)
{
$transport1->getName()->willReturn('transport1');
$transport2->getName()->willReturn('transport2');
$this->register($transport1);
$this->register($transport2);

$this->getTransportNames()->shouldReturn(array(
'transport1', 'transport2'
));
}

function it_can_return_a_named_transport_object(
TransportInterface $transport
)
{
$transport->getName()->willReturn('test');
$this->register($transport);

$this->getTransport('test')->shouldReturn($transport);
}
}
7 changes: 7 additions & 0 deletions src/PHPCR/Shell/Config/Exception/FileExistsException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace PHPCR\Shell\Config\Exception;

class FileExistsException extends \Exception
{
}
Loading