Skip to content

Commit

Permalink
hotfix: container has in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicodmf committed May 14, 2016
1 parent 5b881a5 commit a433996
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ language: php
sudo: false

php:
- 5.3
- 5.4
- 5.5
- 5.6
Expand All @@ -17,10 +16,6 @@ matrix:
include:
- php: 5.6
env: SYMFONY_VERSION=2.3.*
- php: 5.6
env: SYMFONY_VERSION=2.4.*
- php: 5.6
env: SYMFONY_VERSION=2.5.*
- php: 5.6
env: SYMFONY_VERSION=2.7.*
- php: 5.6
Expand All @@ -31,7 +26,6 @@ matrix:
env: SYMFONY_VERSION=dev-master
fast_finish: true
allow_failures:
- env: SYMFONY_VERSION=2.7.*
- env: SYMFONY_VERSION=dev-master

before_script:
Expand Down
50 changes: 26 additions & 24 deletions Tests/Kernel/Symfony14KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTestCase;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -16,7 +14,7 @@
use Theodo\Evolution\Bundle\LegacyWrapperBundle\Kernel\Symfony14Kernel;

/**
* Symfony14KernelTest
* Symfony14KernelTest.
*
* @author Benjamin Grandfond <benjaming@theodo.fr>
*/
Expand All @@ -27,7 +25,7 @@ public function testShouldBootAndHandleRequest()
$kernelOptions = array(
'application' => 'frontend',
'environment' => 'prod',
'debug' => true
'debug' => true,
);

$classLoader = $this->prophesize('Theodo\Evolution\Bundle\LegacyWrapperBundle\Autoload\LegacyClassLoaderInterface');
Expand All @@ -39,16 +37,9 @@ public function testShouldBootAndHandleRequest()
$eventDispatcher = $this->prophesize('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$eventDispatcher->dispatch('legacy_kernel.boot', new LegacyKernelBootEvent($request, $kernelOptions))->shouldBeCalled();

$container = $this->prophesize('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->createProphesizedContainer($request);
$container->get('session')->willReturn($session);
$container->get('event_dispatcher')->willReturn($eventDispatcher);
if (Kernel::MAJOR_VERSION == 2) {
$container->get('request')->willReturn($request);
} else {
$request_stack = new RequestStack();
$request_stack->push($request);
$container->get('request_stack')->willReturn($request_stack);
}

$classLoader->setKernel(Argument::type('Theodo\Evolution\Bundle\LegacyWrapperBundle\Kernel\Symfony14Kernel'))->shouldBeCalled();
$classLoader->isAutoloaded()->willReturn(false);
Expand All @@ -73,7 +64,7 @@ public function testShouldBootAndHandleRequestIfClassLoaderIsNotProvided()
$kernelOptions = array(
'application' => 'frontend',
'environment' => 'prod',
'debug' => true
'debug' => true,
);

$session = new Session(new MockArraySessionStorage());
Expand All @@ -83,17 +74,9 @@ public function testShouldBootAndHandleRequestIfClassLoaderIsNotProvided()
$eventDispatcher = $this->prophesize('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$eventDispatcher->dispatch('legacy_kernel.boot', new LegacyKernelBootEvent($request, $kernelOptions))->shouldBeCalled();

$container = $this->prophesize('Symfony\Component\DependencyInjection\ContainerInterface');
$container = $this->createProphesizedContainer($request);
$container->get('event_dispatcher')->willReturn($eventDispatcher);

if (Kernel::MAJOR_VERSION == 2) {
$container->get('request')->willReturn($request);
} else {
$request_stack = new RequestStack();
$request_stack->push($request);
$container->get('request_stack')->willReturn($request_stack);
}

$kernel = new Symfony14Kernel();
$kernel->setRootDir($_ENV['THEODO_EVOLUTION_FAKE_PROJECTS'].'/symfony14');
$kernel->setOptions($kernelOptions);
Expand All @@ -118,7 +101,7 @@ public function testShouldCopyLegacyResponseData()
$legacyResponse->getHttpHeaders()->willReturn($headers = array(
'Content-Type' => 'text/html',
'Location' => 'http://localhost',
'X-Custom-Header' => 'value'
'X-Custom-Header' => 'value',
));
$legacyResponse->getContent()->willReturn($content = 'content');
$legacyResponse->getCharset()->willReturn($charset = 'charset');
Expand All @@ -134,5 +117,24 @@ public function testShouldCopyLegacyResponseData()
$this->assertEquals($headers['Location'], $response->headers->get('Location'));
$this->assertEquals($headers['X-Custom-Header'], $response->headers->get('X-Custom-Header'));
}
}

protected function createProphesizedContainer($request)
{
$container = $this->prophesize('Symfony\Component\DependencyInjection\ContainerInterface');

if (Kernel::MAJOR_VERSION === 2) {
$container->has('request_stack')->willReturn(false);
$container->get('request')->willReturn($request);
} elseif (Kernel::MAJOR_VERSION === 3) {
$request_stack = new RequestStack();
$request_stack->push($request);
$container->has('request_stack')->willReturn(true);
$container->get('request_stack')->willReturn($request_stack);
} else {
$container->has('request_stack')->willReturn(false);
$container->get('request')->willReturn($request);
}

return $container;
}
}

0 comments on commit a433996

Please sign in to comment.