ContainerInteropDoctrineTest\ConnectionFactoryTest::testDefaultsThroughException PHP Метод

testDefaultsThroughException() публичный Метод

    public function testDefaultsThroughException()
    {
        if (defined('HHVM_VERSION')) {
            $this->markTestSkipped('HHVM is somewhat funky here');
        }
        $factory = new ConnectionFactory();
        $container = $this->prophesize(ContainerInterface::class);
        $container->has('config')->willReturn(false);
        $container->has('doctrine.configuration.orm_default')->willReturn(true);
        $container->get('doctrine.configuration.orm_default')->willReturn($this->configuration);
        $container->has('doctrine.event_manager.orm_default')->willReturn(true);
        $container->get('doctrine.event_manager.orm_default')->willReturn($this->eventManger);
        // This is actually quite tricky. We cannot really test the pure defaults, as that would require a MySQL
        // connection without a username and password. Since that can't work, we just verify that we get an exception
        // with the right backtrace, and test the other defaults with a pure memory-database later.
        try {
            $factory($container->reveal());
        } catch (ConnectionException $e) {
            $this->assertContains("Access denied for user ''@'localhost' (using password: NO)", $e->getMessage());
            foreach ($e->getTrace() as $entry) {
                if ('Doctrine\\DBAL\\Driver\\PDOMySql\\Driver' === $entry['class']) {
                    return;
                }
            }
            $this->fail('Exception was not raised by PDOMySql');
            return;
        }
        $this->fail('An expected exception was not raised');
    }