Skip to content

Commit 38610d2

Browse files
committed
Embedded context tests work
1 parent b85eec4 commit 38610d2

File tree

8 files changed

+98
-37
lines changed

8 files changed

+98
-37
lines changed

.travis.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
language: php
22

3+
env:
4+
- BEHAT_SUITE=standalone
5+
- BEHAT_SUITE=embedded
6+
7+
38
php:
49
- 5.4
510

611
before_script:
7-
- composer require "symfony/symfony" "2.6" --no-update
8-
- composer install
12+
- composer install --dev
913
- bash tests/bin/travis_jackrabbit.sh
1014

1115
script:
1216
- phpunit
1317
- php vendor/bin/phpspec run
14-
- php vendor/behat/behat/bin/behat --suite=standalone
18+
- php vendor/behat/behat/bin/behat --suite=$BEHAT_SUITE

src/PHPCR/Shell/Console/Application/EmbeddedApplication.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPCR\Shell\Subscriber;
66
use Symfony\Component\DependencyInjection\ContainerInterface;
77
use PHPCR\Shell\DependencyInjection\Container;
8+
use PHPCR\Shell\Console\Helper\PhpcrHelper;
89

910
/**
1011
* Subclass of the full ShellApplication for running as an EmbeddedApplication
@@ -40,6 +41,7 @@ public function __construct($mode)
4041
$container = new Container($this->mode);
4142
parent::__construct($container, SessionApplication::APP_NAME, SessionApplication::APP_VERSION);
4243
$this->setAutoExit(false);
44+
$this->getHelperSet()->set(new PhpcrHelper($container->get('phpcr.session_manager')));
4345
}
4446

4547
/**
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Console\Helper;
4+
5+
use PHPCR\Util\PathHelper as StaticPathHelper;
6+
use Symfony\Component\Console\Helper\Helper;
7+
use PHPCR\Shell\Phpcr\SessionManager;
8+
use PHPCR\SessionInterface;
9+
10+
/**
11+
* @deprecated
12+
*
13+
* This helper is deprecated and only exists to provide a backwards compatible
14+
* API fo rsetting the PHPCR session as used in the DoctrinePHPCRBundle.
15+
*
16+
* It has since been replaced by the SessionManager service.
17+
*
18+
* @author Daniel Leech <daniel@dantleech.com>
19+
*/
20+
class PhpcrHelper extends Helper
21+
{
22+
private $sessionManager;
23+
24+
public function __construct(SessionManager $sessionManager)
25+
{
26+
$this->sessionManager = $sessionManager;
27+
}
28+
29+
public function setSession(SessionInterface $session)
30+
{
31+
$this->sessionManager->setSession($session);
32+
}
33+
34+
public function getName()
35+
{
36+
return 'phpcr';
37+
}
38+
}
39+

src/PHPCR/Shell/DependencyInjection/Container.php

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -95,41 +95,48 @@ public function registerPhpcr()
9595

9696
public function registerEvent()
9797
{
98-
$this->register(
99-
'event.subscriber.profile_from_session_input',
100-
'PHPCR\Shell\Subscriber\ProfileFromSessionInputSubscriber'
101-
)->addTag('event.subscriber');
98+
if ($this->mode === self::MODE_STANDALONE) {
99+
$this->register(
100+
'event.subscriber.profile_from_session_input',
101+
'PHPCR\Shell\Subscriber\ProfileFromSessionInputSubscriber'
102+
)->addTag('event.subscriber');
103+
104+
$this->register(
105+
'event.subscriber.profile_writer',
106+
'PHPCR\Shell\Subscriber\ProfileWriterSubscriber'
107+
)
108+
->addArgument(new Reference('config.profile_loader'))
109+
->addArgument(new Reference('helper.question'))
110+
->addTag('event.subscriber');
111+
112+
$this->register(
113+
'event.subscriber.profile_loader',
114+
'PHPCR\Shell\Subscriber\ProfileLoaderSubscriber'
115+
)
116+
->addArgument(new Reference('config.profile_loader'))
117+
->addArgument(new Reference('helper.question'))
118+
->addTag('event.subscriber');
119+
120+
$this->register(
121+
'event.subscriber.config_init',
122+
'PHPCR\Shell\Subscriber\ConfigInitSubscriber'
123+
)
124+
->addArgument(new Reference('config.manager'))
125+
->addTag('event.subscriber');
126+
127+
}
102128

103-
$this->register(
104-
'event.subscriber.exception',
105-
'PHPCR\Shell\Subscriber\ExceptionSubscriber'
106-
)->addTag('event.subscriber');
107129
$this->register(
108130
'event.subscriber.alias',
109131
'PHPCR\Shell\Subscriber\AliasSubscriber'
110132
)
111133
->addArgument(new Reference('config.manager'))
112134
->addTag('event.subscriber');
135+
113136
$this->register(
114-
'event.subscriber.profile_writer',
115-
'PHPCR\Shell\Subscriber\ProfileWriterSubscriber'
116-
)
117-
->addArgument(new Reference('config.profile_loader'))
118-
->addArgument(new Reference('helper.question'))
119-
->addTag('event.subscriber');
120-
$this->register(
121-
'event.subscriber.profile_loader',
122-
'PHPCR\Shell\Subscriber\ProfileLoaderSubscriber'
123-
)
124-
->addArgument(new Reference('config.profile_loader'))
125-
->addArgument(new Reference('helper.question'))
126-
->addTag('event.subscriber');
127-
$this->register(
128-
'event.subscriber.config_init',
129-
'PHPCR\Shell\Subscriber\ConfigInitSubscriber'
130-
)
131-
->addArgument(new Reference('config.manager'))
132-
->addTag('event.subscriber');
137+
'event.subscriber.exception',
138+
'PHPCR\Shell\Subscriber\ExceptionSubscriber'
139+
)->addTag('event.subscriber');
133140

134141
$dispatcher = $this->register('event.dispatcher', 'Symfony\Component\EventDispatcher\EventDispatcher');
135142

src/PHPCR/Shell/Subscriber/ExceptionSubscriber.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public function handleException(CommandExceptionEvent $event)
4242
$output->writeln('<error>Not implemented: ' . $exception->getMessage() . '</error>');
4343
}
4444

45+
$output->writeln($exception->getTraceAsString());
46+
4547
$output->writeln('<error>[' . get_class($exception) .'] ' . $exception->getMessage() . '</error>');
4648
}
4749
}

src/PHPCR/Shell/Test/ApplicationTester.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function runShellCommand($command)
134134
if ($this->shellApplication) {
135135
$ret = $this->shellApplication->run(new StringInput($command), $this->output);
136136
} else {
137-
$ret = $this->application->run(new StringInput($command, $this->output));
137+
$ret = $this->application->run(new StringInput($command), $this->output);
138138
}
139139

140140

src/PHPCR/Shell/Test/ContextBase.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
*/
2727
abstract class ContextBase implements Context, SnippetAcceptingContext
2828
{
29-
protected $application;
3029
protected $applicationTester;
3130
protected $filesystem;
3231
protected $workingDir;
@@ -53,8 +52,8 @@ public function beforeScenario()
5352
mkdir($this->workingDir, 0777, true);
5453
chdir($this->workingDir);
5554
$this->filesystem = new Filesystem();
56-
5755
$this->applicationTester = $this->createTester();
56+
$this->getSession()->refresh(true);
5857
}
5958

6059
/**
@@ -68,7 +67,7 @@ public static function cleanTestFolders()
6867
$fs->remove(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'phpcr-shell');
6968
}
7069

71-
private function getSession($workspaceName = null, $force = false)
70+
protected function getSession($workspaceName = null, $force = false)
7271
{
7372
if ($workspaceName === null) {
7473
$workspaceName = $this->currentWorkspaceName;
@@ -352,7 +351,7 @@ public function iShouldNotBeLoggedIntoTheSession()
352351
/**
353352
* @Given /^there exists a namespace prefix "([^"]*)" with URI "([^"]*)"$/
354353
*/
355-
public function thereExistsANamespacePrefixWithUri($arg1, $arg2)
354+
public function thereExistsANamespacePrefixWithUri($arg, $arg2)
356355
{
357356
$session = $this->getSession();
358357
$session->setNamespacePrefix($arg1, $arg2);

src/PHPCR/Shell/Test/EmbeddedContext.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,24 @@
44

55
use PHPCR\Shell\Console\Application\EmbeddedApplication;
66
use PHPCR\Shell\Test\ApplicationTester;
7+
use PHPCR\Shell\Phpcr\PhpcrSession;
78

89
/**
910
* Features context.
1011
*/
1112
class EmbeddedContext extends ContextBase
1213
{
14+
private $application;
15+
1316
protected function createTester()
1417
{
15-
$application = new EmbeddedApplication(EmbeddedApplication::MODE_COMMAND);
16-
$tester = new ApplicationTester($application);
18+
// embbed a new session
19+
$session = $this->getSession(null, true);
20+
21+
$this->application = new EmbeddedApplication(EmbeddedApplication::MODE_SHELL);
22+
$this->application->getHelperSet()->get('phpcr')->setSession(new PhpcrSession($session));
23+
24+
$tester = new ApplicationTester($this->application);
1725

1826
return $tester;
1927
}

0 commit comments

Comments
 (0)