You are here

public function PdoSessionHandlerTest::testReadLockedConvertsStreamToString in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/http-foundation/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php \Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\PdoSessionHandlerTest::testReadLockedConvertsStreamToString()

File

vendor/symfony/http-foundation/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php, line 155

Class

PdoSessionHandlerTest

Namespace

Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler

Code

public function testReadLockedConvertsStreamToString() {
  $pdo = new MockPdo('pgsql');
  $selectStmt = $this
    ->getMock('PDOStatement');
  $insertStmt = $this
    ->getMock('PDOStatement');
  $pdo->prepareResult = function ($statement) use ($selectStmt, $insertStmt) {
    return 0 === strpos($statement, 'INSERT') ? $insertStmt : $selectStmt;
  };
  $content = 'foobar';
  $stream = $this
    ->createStream($content);
  $exception = null;
  $selectStmt
    ->expects($this
    ->atLeast(2))
    ->method('fetchAll')
    ->will($this
    ->returnCallback(function () use (&$exception, $stream) {
    return $exception ? array(
      array(
        $stream,
        42,
        time(),
      ),
    ) : array();
  }));
  $insertStmt
    ->expects($this
    ->once())
    ->method('execute')
    ->will($this
    ->returnCallback(function () use (&$exception) {
    throw $exception = new \PDOException('', '23');
  }));
  $storage = new PdoSessionHandler($pdo);
  $result = $storage
    ->read('foo');
  $this
    ->assertSame($content, $result);
}