Skip to content

Commit abb898d

Browse files
committed
Working on profiles
1 parent bbb6531 commit abb898d

17 files changed

+550
-2
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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_the_transport_config(
24+
TransportConfig $transportConfig
25+
)
26+
{
27+
$this->setTransportConfig($transportConfig);
28+
}
29+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace spec\PHPCR\Shell\Console\Helper;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Prophecy\Argument;
7+
use PHPCR\Shell\Config\Profile;
8+
9+
class ProfileHelperSpec extends ObjectBehavior
10+
{
11+
function it_is_initializable()
12+
{
13+
$this->shouldHaveType('PHPCR\Shell\Console\Helper\ProfileHelper');
14+
}
15+
16+
function it_should_return_a_list_of_available_profiles()
17+
{
18+
$this->getProfileNames()->shouldReturn(array(
19+
'profile1',
20+
'profile2',
21+
));
22+
}
23+
24+
function it_should_a_profile_object_for_a_valid_profile_name()
25+
{
26+
$this->getProfile('profile1');
27+
}
28+
29+
function it_should_provide_a_method_to_create_a_new_named_profile()
30+
{
31+
$this->createNewProfile('foobar');
32+
}
33+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace spec\PHPCR\Shell\Console\Wizard;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Prophecy\Argument;
7+
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Output\OutputInterface;
9+
use Symfony\Component\Console\Helper\DialogHelper;
10+
use PHPCR\Shell\Transport\TransportFactoryInterface;
11+
use PHPCR\Shell\Transport\Transport\TransportInterface;
12+
13+
class ConnectionWizardSpec extends ObjectBehavior
14+
{
15+
function it_is_initializable()
16+
{
17+
$this->shouldHaveType('PHPCR\Shell\Console\Wizard\ConnectionWizard');
18+
}
19+
20+
function let(
21+
DialogHelper $dialogHelper,
22+
TransportFactoryInterface $transportFactory
23+
)
24+
{
25+
$this->beConstructedWith(
26+
$dialogHelper,
27+
$transportFactory
28+
);
29+
}
30+
31+
function it_should_produce_a_transport_config(
32+
InputInterface $input,
33+
OutputInterface $output,
34+
DialogHelper $dialogHelper,
35+
TransportFactoryInterface $transportFactory,
36+
TransportInterface $transport
37+
)
38+
{
39+
$transportFactory->getTransportNames()->willReturn(array(
40+
'test transport 1',
41+
'test transport 2',
42+
));
43+
44+
$output->writeln('(0) test transport 1');
45+
$output->writeln('(1) test transport 2');
46+
47+
$dialogHelper->ask($output, 'Choose a transport')->willReturn('0');
48+
49+
$transportFactory->getTransport('test transport 1')->willReturn($transport);
50+
51+
$transport->getTemplateConnectionParameters()->willReturn(array(
52+
'testhost' => 'http://example.com',
53+
'foobar' => '',
54+
));
55+
56+
$dialogHelper->ask($output, 'testhost', 'http://example.com')->willReturn('http://barfoo.com');
57+
$dialogHelper->ask($output, 'foobar', '')->willReturn('bar');
58+
59+
$this->run($input, $output)->shouldReturn(array(
60+
'testhost' => 'http://barfoo.com',
61+
'foobar' => 'bar',
62+
));
63+
}
64+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
namespace spec\PHPCR\Shell\Console\Wizard;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Prophecy\Argument;
7+
use Symfony\Component\Console\Helper\DialogHelper;
8+
use PHPCR\Shell\Console\Wizard\WizardInterface;
9+
use PHPCR\Shell\Console\Helper\ProfileHelper;
10+
use Symfony\Component\Console\Input\InputInterface;
11+
use Symfony\Component\Console\Output\OutputInterface;
12+
use PHPCR\Shell\Transport\SessionConfig;
13+
use PHPCR\Shell\Config\Profile;
14+
use PHPCR\Shell\Transport\TransportConfig;
15+
16+
class ProfileWizardSpec extends ObjectBehavior
17+
{
18+
function it_is_initializable()
19+
{
20+
$this->shouldHaveType('PHPCR\Shell\Console\Wizard\ProfileWizard');
21+
}
22+
23+
function let(
24+
DialogHelper $dialogHelper,
25+
ProfileHelper $profileHelper,
26+
WizardInterface $connectionWizard
27+
)
28+
{
29+
$this->beConstructedWith(
30+
$dialogHelper,
31+
$profileHelper,
32+
$connectionWizard
33+
);
34+
}
35+
36+
37+
function it_should_return_a_config_object_for_a_named_profile(
38+
InputInterface $input,
39+
OutputInterface $output,
40+
Profile $profile,
41+
ProfileHelper $profileHelper,
42+
DialogHelper $dialogHelper
43+
)
44+
{
45+
$profileHelper->getProfileNames()->willReturn(array(
46+
'profile1', 'profile2'
47+
));
48+
49+
$output->writeln('(0) Use: profile1')->shouldBeCalled();
50+
$output->writeln('(1) Use: profile2')->shouldBeCalled();
51+
$output->writeln('(c) Create a new profile')->shouldBeCalled();
52+
53+
$dialogHelper->ask($output, 'Enter a choice: ')->willReturn('0');
54+
55+
$profileHelper->getProfile('profile1')->willReturn($profile);
56+
$profileHelper->getProfileNames()->willReturn(array(
57+
'profile1', 'profile2'
58+
));
59+
60+
$this->run($input, $output)->shouldReturn($profile);
61+
}
62+
63+
function it_should_create_a_new_profile(
64+
InputInterface $input,
65+
OutputInterface $output,
66+
Profile $profile,
67+
ProfileHelper $profileHelper,
68+
DialogHelper $dialogHelper,
69+
TransportConfig $transportConfig,
70+
WizardInterface $connectionWizard
71+
)
72+
{
73+
$profileHelper->getProfileNames()->willReturn(array());
74+
75+
$output->writeln('(c) Create a new profile')->shouldBeCalled();
76+
$dialogHelper->ask($output, 'Enter a choice: ')->willReturn('c');
77+
$dialogHelper->ask($output, 'Enter name for new profile: ')->willReturn('test');
78+
$connectionWizard->run($input, $output)->willReturn(array());
79+
$profileHelper->createNewProfile('test')->willReturn($profile);
80+
81+
$this->run($input, $output)->shouldReturn($profile);
82+
}
83+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace spec\PHPCR\Shell\Transport;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Prophecy\Argument;
7+
8+
class TransportConfigSpec extends ObjectBehavior
9+
{
10+
function it_is_initializable()
11+
{
12+
$this->shouldHaveType('PHPCR\Shell\Transport\TransportConfig');
13+
}
14+
15+
function it_should_provide_array_access()
16+
{
17+
$this['foo'] = 'bar';
18+
$this->offsetGet('foo')->shouldReturn('bar');
19+
}
20+
21+
function it_should_provide_get_and_set()
22+
{
23+
$this['foo'] = 'bar';
24+
$this->get('foo')->shouldReturn('bar');
25+
}
26+
}
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\Transport\TransportInterface;
8+
9+
class TransportFactorySpec extends ObjectBehavior
10+
{
11+
function it_is_initializable()
12+
{
13+
$this->shouldHaveType('PHPCR\Shell\Transport\TransportFactory');
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+
}

src/PHPCR/Shell/Config/Profile.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Config;
4+
5+
use PHPCR\Shell\Transport\TransportConfig;
6+
7+
/**
8+
* Configuration profile object
9+
*/
10+
class Profile
11+
{
12+
protected $profile = array();
13+
protected $name;
14+
15+
public function __construct($name)
16+
{
17+
$this->name = $name;
18+
}
19+
20+
public function setTransportConfig($transportConfig)
21+
{
22+
$this->profile['transport'] = $transportConfig;
23+
}
24+
25+
public function getName()
26+
{
27+
return $this->name;
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Console\Helper;
4+
5+
use PHPCR\Shell\Transport\SessionConfig;
6+
use PHPCR\Shell\Config\Profile;
7+
8+
class ProfileHelper
9+
{
10+
public function getProfileNames()
11+
{
12+
return array(
13+
'profile1',
14+
'profile2',
15+
);
16+
}
17+
18+
public function getProfile()
19+
{
20+
return new Profile('test');
21+
}
22+
23+
public function createNewProfile($name)
24+
{
25+
$profile = new Profile($name);
26+
27+
return $profile;
28+
}
29+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Console\Wizard;
4+
5+
use Symfony\Component\Console\Input\InputInterface;
6+
use Symfony\Component\Console\Output\OutputInterface;
7+
use Symfony\Component\Console\Helper\DialogHelper;
8+
use PHPCR\Shell\Transport\TransportFactoryInterface;
9+
10+
class ConnectionWizard implements WizardInterface
11+
{
12+
protected $dialog;
13+
protected $transportFactory;
14+
15+
public function __construct(
16+
DialogHelper $dialog,
17+
TransportFactoryInterface $transportFactory
18+
) {
19+
$this->dialog = $dialog;
20+
$this->transportFactory = $transportFactory;
21+
}
22+
23+
/**
24+
* Run the wizard
25+
*
26+
* @return ShellSessionConfig
27+
*/
28+
public function run(InputInterface $input, OutputInterface $output)
29+
{
30+
$config = array();
31+
32+
$transportNames = $this->transportFactory->getTransportNames();
33+
34+
foreach ($transportNames as $i => $transportName) {
35+
$output->writeln(sprintf('(%d) %s', $i, $transportName));
36+
}
37+
$choice = $this->dialog->ask($output, 'Choose a transport');
38+
$transportName = $transportNames[$choice];
39+
$transport = $this->transportFactory->getTransport($transportName);
40+
$templateParameters = $transport->getTemplateConnectionParameters();
41+
42+
foreach ($templateParameters as $key => $defaultValue) {
43+
$answer = $this->dialog->ask($output, $key, $defaultValue);
44+
$config[$key] = $answer;
45+
}
46+
47+
return $config;
48+
}
49+
}

0 commit comments

Comments
 (0)