17 use Prophecy\Argument;
18 use Prophecy\Prophecy\ObjectProphecy;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
42 protected function setUp()
44 $this->subject = $this->getMockBuilder(CleanerTask::class)
45 ->setMethods([
'dummy'])
46 ->disableOriginalConstructor()
56 $this->subject->setPeriod($period);
58 $this->assertEquals($period, $this->subject->getPeriod());
66 $tables = [
'pages',
'tt_content'];
67 $this->subject->setTcaTables($tables);
69 $this->assertEquals($tables, $this->subject->getTcaTables());
77 $GLOBALS[
'TCA'][
'pages'][
'ctrl'][
'delete'] =
'deleted';
78 $GLOBALS[
'TCA'][
'pages'][
'ctrl'][
'tstamp'] =
'tstamp';
81 $subject = $this->getMockBuilder(CleanerTask::class)
82 ->setMethods([
'getPeriodAsTimestamp'])
83 ->disableOriginalConstructor()
86 $subject->expects($this->once())->method(
'getPeriodAsTimestamp')->willReturn(400);
89 $connection = $this->prophesize(Connection::class);
90 $connection->getDatabasePlatform()->willReturn(
new MockPlatform());
91 $connection->getExpressionBuilder()->willReturn(
new ExpressionBuilder($connection->reveal()));
92 $connection->quoteIdentifier(Argument::cetera())->willReturnArgument(0);
97 $statementProphet = $this->prophesize(\Doctrine\DBAL\Driver\Statement::class);
99 $restrictionProphet = $this->prophesize(DefaultRestrictionContainer::class);
100 $restrictionProphet->removeAll()->willReturn($restrictionProphet->reveal());
102 $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
103 $queryBuilderProphet->expr()->willReturn(
104 GeneralUtility::makeInstance(ExpressionBuilder::class, $connection->reveal())
106 $queryBuilderProphet->getRestrictions()->willReturn($restrictionProphet->reveal());
107 $queryBuilderProphet->createNamedParameter(Argument::cetera())->willReturnArgument(0);
108 $queryBuilderProphet->delete(Argument::cetera())->willReturn($queryBuilderProphet->reveal());
109 $queryBuilderProphet->where(Argument::cetera())->willReturn($queryBuilderProphet->reveal());
110 $queryBuilderProphet->execute()->willReturn($statementProphet->reveal());
112 $connectionPool = $this->prophesize(ConnectionPool::class);
113 $connectionPool->getQueryBuilderForTable(
'pages')->willReturn($queryBuilderProphet->reveal());
114 GeneralUtility::addInstance(ConnectionPool::class, $connectionPool->reveal());
124 $GLOBALS[
'TCA'][
'pages'][
'ctrl'][
'delete'] =
'deleted';
125 $GLOBALS[
'TCA'][
'pages'][
'ctrl'][
'tstamp'] =
'tstamp';
127 $this->subject->setTcaTables([
'pages']);
130 $connection = $this->prophesize(Connection::class);
131 $connection->getDatabasePlatform()->willReturn(
new MockPlatform());
132 $connection->getExpressionBuilder()->willReturn(
new ExpressionBuilder($connection->reveal()));
133 $connection->quoteIdentifier(Argument::cetera())->willReturnArgument(0);
138 $connection->reveal(),
140 new \Doctrine\DBAL\Query\
QueryBuilder($connection->reveal())
143 $connectionPool = $this->prophesize(ConnectionPool::class);
144 $connectionPool->getQueryBuilderForTable(
'pages')->willReturn($queryBuilder);
145 GeneralUtility::addInstance(ConnectionPool::class, $connectionPool->reveal());
147 $connection->executeUpdate(Argument::cetera())
149 ->willThrow(
new \Doctrine\DBAL\DBALException(
'testing', 1476122315));
151 $this->assertFalse($this->subject->execute());