Skip to content

Commit

Permalink
Merge branch '2.7' into 2.8
Browse files Browse the repository at this point in the history
* 2.7:
  [Bridge\Doctrine] Fix change breaking doctrine-bundle test suite
  [HttpFoundation][bugfix]  should always be initialized
  MockArraySessionStorage: updated phpdoc for $bags so that IDE autocompletion would work
  normalize paths before making them relative
  • Loading branch information
fabpot committed Mar 26, 2017
2 parents f971f4f + 359a063 commit d175340
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,12 @@ private function addTaggedListeners(ContainerBuilder $container)
throw new RuntimeException(sprintf('The Doctrine connection "%s" referenced in service "%s" does not exist. Available connections names: %s', $con, $id, implode(', ', array_keys($this->connections))));
}

if ($lazy = isset($tag['lazy']) && $tag['lazy']) {
if ($lazy = !empty($tag['lazy'])) {
$taggedListenerDef->setPublic(true);
}

// we add one call per event per service so we have the correct order
$this->getEventManagerDef($container, $con)->addMethodCall('addEventListener', array(
$tag['event'],
$lazy ? $id : new Reference($id),
));
$this->getEventManagerDef($container, $con)->addMethodCall('addEventListener', array(array($tag['event']), $lazy ? $id : new Reference($id)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ public function testProcessEventListenersWithPriorities()

$this->assertEquals(
array(
array('addEventListener', array('foo_bar', new Reference('c'))),
array('addEventListener', array('foo_bar', new Reference('a'))),
array('addEventListener', array('bar', new Reference('a'))),
array('addEventListener', array('foo', new Reference('b'))),
array('addEventListener', array('foo', new Reference('a'))),
array('addEventListener', array(array('foo_bar'), new Reference('c'))),
array('addEventListener', array(array('foo_bar'), new Reference('a'))),
array('addEventListener', array(array('bar'), new Reference('a'))),
array('addEventListener', array(array('foo'), new Reference('b'))),
array('addEventListener', array(array('foo'), new Reference('a'))),
),
$methodCalls
);
Expand Down Expand Up @@ -138,16 +138,16 @@ public function testProcessEventListenersWithMultipleConnections()

$this->assertEquals(
array(
array('addEventListener', array('onFlush', new Reference('a'))),
array('addEventListener', array('onFlush', new Reference('b'))),
array('addEventListener', array(array('onFlush'), new Reference('a'))),
array('addEventListener', array(array('onFlush'), new Reference('b'))),
),
$container->getDefinition('doctrine.dbal.default_connection.event_manager')->getMethodCalls()
);

$this->assertEquals(
array(
array('addEventListener', array('onFlush', new Reference('a'))),
array('addEventListener', array('onFlush', new Reference('c'))),
array('addEventListener', array(array('onFlush'), new Reference('a'))),
array('addEventListener', array(array('onFlush'), new Reference('c'))),
),
$container->getDefinition('doctrine.dbal.second_connection.event_manager')->getMethodCalls()
);
Expand Down
25 changes: 25 additions & 0 deletions src/Symfony/Component/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,31 @@ public function makePathRelative($endPath, $startPath)
$startPathArr = explode('/', trim($startPath, '/'));
$endPathArr = explode('/', trim($endPath, '/'));

if ('/' !== $startPath[0]) {
array_shift($startPathArr);
}

if ('/' !== $endPath[0]) {
array_shift($endPathArr);
}

$normalizePathArray = function ($pathSegments) {
$result = array();

foreach ($pathSegments as $segment) {
if ('..' === $segment) {
array_pop($result);
} else {
$result[] = $segment;
}
}

return $result;
};

$startPathArr = $normalizePathArray($startPathArr);
$endPathArr = $normalizePathArray($endPathArr);

// Find for which directory the common path stops
$index = 0;
while (isset($startPathArr[$index]) && isset($endPathArr[$index]) && $startPathArr[$index] === $endPathArr[$index]) {
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,16 @@ public function providePathsForMakePathRelative()
array('/a/aab/bb/', '/b/aab', '../../a/aab/bb/'),
array('/aab/bb', '/aa', '../aab/bb/'),
array('/aab', '/aa', '../aab/'),
array('/aa/bb/cc', '/aa/dd/..', 'bb/cc/'),
array('/aa/../bb/cc', '/aa/dd/..', '../bb/cc/'),
array('/aa/bb/../../cc', '/aa/../dd/..', 'cc/'),
array('/../aa/bb/cc', '/aa/dd/..', 'bb/cc/'),
array('/../../aa/../bb/cc', '/aa/dd/..', '../bb/cc/'),
array('C:/aa/bb/cc', 'C:/aa/dd/..', 'bb/cc/'),
array('c:/aa/../bb/cc', 'c:/aa/dd/..', '../bb/cc/'),
array('C:/aa/bb/../../cc', 'C:/aa/../dd/..', 'cc/'),
array('C:/../aa/bb/cc', 'C:/aa/dd/..', 'bb/cc/'),
array('C:/../../aa/../bb/cc', 'C:/aa/dd/..', '../bb/cc/'),
);

if ('\\' === DIRECTORY_SEPARATOR) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class MockArraySessionStorage implements SessionStorageInterface
protected $metadataBag;

/**
* @var array
* @var array|SessionBagInterface[]
*/
protected $bags;
protected $bags = array();

/**
* Constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,30 @@ public function testGetId()
$this->assertNotEquals('', $this->storage->getId());
}

public function testClearClearsBags()
{
$this->storage->clear();

$this->assertSame(array(), $this->storage->getBag('attributes')->all());
$this->assertSame(array(), $this->storage->getBag('flashes')->peekAll());
}

public function testClearStartsSession()
{
$this->storage->clear();

$this->assertTrue($this->storage->isStarted());
}

public function testClearWithNoBagsStartsSession()
{
$storage = new MockArraySessionStorage();

$storage->clear();

$this->assertTrue($storage->isStarted());
}

/**
* @expectedException \RuntimeException
*/
Expand Down

0 comments on commit d175340

Please sign in to comment.