public function testGetUpdateSchemaSqlShouldAffectOnlyKnownDBTableParts() { list($fromSchema, $toSchema) = $this->prepareSchemas(); $meta = [new \stdClass()]; $schemaManager = $this->getMockBuilder('Doctrine\\DBAL\\Schema\\AbstractSchemaManager')->setMethods(['createSchema'])->disableOriginalConstructor()->getMockForAbstractClass(); $schemaManager->expects($this->once())->method('createSchema')->willReturn($fromSchema); $this->connection->expects($this->once())->method('getSchemaManager')->willReturn($schemaManager); $this->schemaTool->expects($this->once())->method('getSchemaFromMetadata')->with($meta)->willReturn($toSchema); $this->assertEquals(['DROP INDEX oro_idx_index_name ON oro_entity_extend_test_relation'], $this->schemaTool->getUpdateSchemaSql($meta, true)); }
public function setUp() { parent::setUp(); $this->postDecorator = new PostDecorator(); $this->conn = $this->getMock('Doctrine\\DBAL\\Connection', array(), array(), '', false); $expressionBuilder = new ExpressionBuilder($this->conn); $this->conn->expects($this->any())->method('getExpressionBuilder')->will($this->returnValue($expressionBuilder)); $this->queryBuilder = new QueryBuilder($this->conn); $this->queryBuilder->select('o.*')->from('posts', 'o'); }
public function testCommand() { $this->executeCommand('jackalope:init:dbal', array(), 2); $this->executeCommand('jackalope:init:dbal', array('--dump-sql' => true), 0); $this->executeCommand('jackalope:init:dbal', array('--dump-sql' => true, '--drop' => true), 0); $this->executeCommand('jackalope:init:dbal', array('--force' => true), 0); $this->executeCommand('jackalope:init:dbal', array('--force' => true, '--drop' => true), 0); // Unfortunately PDO doesn't follow internals and uses a non integer error code, which cannot be manually created $this->connection->expects($this->any())->method('exec')->will($this->throwException(new MockPDOException('', '42S01'))); $this->executeCommand('jackalope:init:dbal', array('--force' => true, '--drop' => true), 1); }
/** * @expectedException \Doctrine\DBAL\DBALException */ public function testExecuteCallsLoggerStopQueryOnException() { $logger = $this->getMock('\\Doctrine\\DBAL\\Logging\\SQLLogger'); $this->configuration->expects($this->once())->method('getSQLLogger')->will($this->returnValue($logger)); // Needed to satisfy construction of DBALException $this->conn->expects($this->any())->method('resolveParams')->will($this->returnValue(array())); $logger->expects($this->once())->method('startQuery'); $logger->expects($this->once())->method('stopQuery'); $this->pdoStatement->expects($this->once())->method('execute')->will($this->throwException(new \Exception("Mock test exception"))); $statement = new Statement("", $this->conn); $statement->execute(); }
/** * @covers \EzSystems\EzSupportToolsBundle\SystemInfo\Collector\DoctrineDatabaseSystemInfoCollector::collect() */ public function testCollect() { $expected = new DatabaseSystemInfo(['type' => 'mysql', 'name' => 'ezp_platform', 'host' => 'localhost', 'username' => 'ezp_user']); $this->dbalConnectionMock->expects($this->once())->method('getDatabasePlatform')->will($this->returnValue($this->dbalPlatformMock)); $this->dbalPlatformMock->expects($this->once())->method('getName')->will($this->returnValue($expected->type)); $this->dbalConnectionMock->expects($this->once())->method('getDatabase')->will($this->returnValue($expected->name)); $this->dbalConnectionMock->expects($this->once())->method('getHost')->will($this->returnValue($expected->host)); $this->dbalConnectionMock->expects($this->once())->method('getUsername')->will($this->returnValue($expected->username)); $value = $this->databaseCollector->collect(); self::assertInstanceOf('EzSystems\\EzSupportToolsBundle\\SystemInfo\\Value\\DatabaseSystemInfo', $value); self::assertEquals($expected, $value); }
public function setUp() { $statement = $this->createMock(Statement::class); $statement->expects($this->any())->method('fetchAll')->willReturn(array_values($this->articles)); $queryBuilder = $this->createMock(QueryBuilder::class); $queryBuilder->expects($this->any())->method('select')->willReturnSelf(); $queryBuilder->expects($this->any())->method('setMaxResults')->willReturnSelf(); $queryBuilder->expects($this->any())->method('execute')->willReturn($statement); $this->connection = $this->createMock(Connection::class); $this->connection->expects($this->any())->method('createQueryBuilder')->willReturn($queryBuilder); parent::setUp(); $this->dataMapper = new DoctrineDataMapper($this->connection, Article::class, 'articles', $this->entityRegistry); }
public function setUp() { $pdoStatement = $this->getMock('\\PDOStatment', array('execute', 'bindParam', 'bindValue')); $platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform(); $driverConnection = $this->getMock('\\Doctrine\\DBAL\\Driver\\Connection'); $driverConnection->expects($this->any())->method('prepare')->will($this->returnValue($pdoStatement)); $driver = $this->getMock('\\Doctrine\\DBAL\\Driver'); $constructorArgs = array(array('platform' => $platform), $driver); $this->conn = $this->getMock('\\Doctrine\\DBAL\\Connection', array(), $constructorArgs); $this->conn->expects($this->atLeastOnce())->method('getWrappedConnection')->will($this->returnValue($driverConnection)); $this->configuration = $this->getMock('\\Doctrine\\DBAL\\Configuration'); $this->conn->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration)); }
public function testCollect() { // getPosts returns an array of size 10 => 20 loops => 20 getUrl $this->curlUtils->expects($this->exactly(20))->method('getResource')->will($this->returnValue('whatever')); $this->postParserUtils->expects($this->exactly(20))->method('getPosts')->will($this->returnValue(array(0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9))); $this->postParserUtils->expects($this->exactly(200))->method('parse')->will($this->returnValue(array("content" => "this is a content", "author" => "FOO", "created" => "2014-01-01 00:00:00"))); // insert in Db should be called 200 times $this->conn->expects($this->exactly(200))->method('insert'); $response = $this->postController->collect(); $this->assertInstanceOf("Symfony\\Component\\HttpFoundation\\JsonResponse", $response); $this->assertEquals(200, $response->getStatusCode()); $this->assertContains("200 posts have been added", $response->getContent()); }
public function testDeletedirectory() { $statement = $this->createDbalStatementMock(); $statement->expects($this->once())->method('bindValue')->with(1, 'folder/subfolder/%'); $this->dbalMock->expects($this->once())->method('prepare')->with($this->anything())->will($this->returnValue($statement)); $this->handler->deleteDirectory('folder/subfolder/'); }
/** * @test * @expectedException \TYPO3\Flow\Error\Exception */ public function persistAllReconnectsConnectionOnFailure() { $this->mockEntityManager->expects($this->exactly(2))->method('flush')->will($this->throwException(new \TYPO3\Flow\Error\Exception('Dummy connection error'))); $this->mockConnection->expects($this->at(0))->method('close'); $this->mockConnection->expects($this->at(1))->method('connect'); $this->persistenceManager->persistAll(); }
public function testExistsNot() { $statement = $this->createDbalStatementMock(); $statement->expects($this->once())->method('rowCount')->will($this->returnValue(0)); $this->dbalMock->expects($this->once())->method('prepare')->with($this->anything())->will($this->returnValue($statement)); self::assertFalse($this->handler->exists('prefix/my/file.png')); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp() { $this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $this->conn = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->disableOriginalConstructor()->getMock(); $this->conn->expects($this->any())->method('getDatabase')->will($this->returnValue('myDatabase')); /* @var $platform AbstractPlatform */ $platform = $this->getMockForAbstractClass('Doctrine\\DBAL\\Platforms\\AbstractPlatform'); $this->conn->expects($this->any())->method('getDatabasePlatform')->will($this->returnValue($platform)); $this->em->expects($this->any())->method('getConnection')->will($this->returnValue($this->conn)); /* @var $meta ClassMetadata */ $meta = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock(); $this->em->expects($this->any())->method('getClassMetadata')->will($this->returnValue($meta)); $this->sc = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\SecurityContextInterface')->getMock(); $this->token = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface')->getMock(); $this->sc->expects($this->any())->method('getToken')->will($this->returnValue($this->token)); $this->rh = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Role\\RoleHierarchyInterface')->getMock(); $this->object = new AclNativeHelper($this->em, $this->sc, $this->rh); }
/** * @test */ public function insertAnOrder() { $orderData = ['status' => 'placed']; $this->db->expects(self::once())->method('insert')->with('order', $orderData); $this->db->expects(self::once())->method('lastInsertId')->willReturn(1); $order = new Order(); $order->setStatus('placed'); $this->repository->save($order); self::assertEquals(1, $order->getId()); }
public function testDuplicateFailed() { $product = (new StubProduct())->setSku(self::PRODUCT_SKU); $this->skuIncrementor->expects($this->once())->method('increment')->with(self::PRODUCT_SKU)->will($this->returnValue(self::PRODUCT_COPY_SKU)); $this->attachmentProvider->expects($this->once())->method('getEntityAttachments')->with($product)->will($this->returnValue([])); $this->connection->expects($this->once())->method('beginTransaction'); $this->connection->expects($this->once())->method('commit')->will($this->throwException(new \Exception())); $this->connection->expects($this->once())->method('rollback'); $this->setExpectedException('Exception'); $this->duplicator->duplicate($product); }
/** * @group DBAL-474 */ public function testFiltersSequences() { $configuration = new Configuration(); $configuration->setFilterSchemaAssetsExpression('/^schema/'); $sequences = array(array('relname' => 'foo', 'schemaname' => 'schema'), array('relname' => 'bar', 'schemaname' => 'schema'), array('relname' => 'baz', 'schemaname' => ''), array('relname' => 'bloo', 'schemaname' => 'bloo_schema')); $this->connection->expects($this->any())->method('getConfiguration')->will($this->returnValue($configuration)); $this->connection->expects($this->at(0))->method('fetchAll')->will($this->returnValue($sequences)); $this->connection->expects($this->at(1))->method('fetchAll')->will($this->returnValue(array(array('min_value' => 1, 'increment_by' => 1)))); $this->connection->expects($this->at(2))->method('fetchAll')->will($this->returnValue(array(array('min_value' => 2, 'increment_by' => 2)))); $this->connection->expects($this->exactly(3))->method('fetchAll'); $this->assertEquals(array(new Sequence('schema.foo', 2, 2), new Sequence('schema.bar', 1, 1)), $this->schemaManager->listSequences('database')); }
/** * delete() delegates call to connection */ public function testDelete() { $this->connection->expects($this->once())->method('delete')->willReturn(1); $this->dataMapper->delete(new Article()); }
/** * Adds an expected method call to the database connection mock object. * * @param array $imageSizes The image sizes to be returned */ private function expectImageSizes(array $imageSizes) { $this->connection->expects($this->atLeastOnce())->method('fetchAll')->willReturn($imageSizes); }
/** * @covers Imbo\Database\Doctrine::getStatus */ public function testGetStatusWhenDatabaseIsNotConnectedAndConnectThrowsAnException() { $this->connection->expects($this->once())->method('isConnected')->will($this->returnValue(false)); $this->connection->expects($this->once())->method('connect')->will($this->throwException(new PDOException())); $this->assertFalse($this->driver->getStatus()); }
/** * Test record removal while connection is malfunctioning. */ public function testRemoveRecordWhileConnectionIsMalfunctioning() { $testRecordId = 123; $this->connection->expects($this->once())->method('delete')->with(self::TABLE_NAME . '_0', ['id' => $testRecordId])->will($this->throwException(new \Exception('Connection is not working'))); $this->service->removeRecord($testRecordId); }