2013-10-23 15:46:45 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Tools\Console\Command;
|
|
|
|
|
|
|
|
use Doctrine\ORM\Tools\Console\Command\ClearCache\CollectionRegionCommand;
|
|
|
|
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
|
2016-12-08 18:01:04 +01:00
|
|
|
use Doctrine\Tests\Models\Cache\State;
|
2013-10-23 15:46:45 -04:00
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase;
|
2016-12-08 18:01:04 +01:00
|
|
|
use Symfony\Component\Console\Application;
|
|
|
|
use Symfony\Component\Console\Helper\HelperSet;
|
|
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
2013-10-23 15:46:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-2183
|
|
|
|
*/
|
|
|
|
class ClearCacheCollectionRegionCommandTest extends OrmFunctionalTestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Symfony\Component\Console\Application
|
|
|
|
*/
|
|
|
|
private $application;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Doctrine\ORM\Tools\Console\Command\ClearCache\CollectionRegionCommand
|
|
|
|
*/
|
|
|
|
private $command;
|
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
$this->enableSecondLevelCache();
|
|
|
|
parent::setUp();
|
|
|
|
|
2017-11-24 01:13:52 +01:00
|
|
|
$this->command = new CollectionRegionCommand();
|
2013-10-23 15:46:45 -04:00
|
|
|
|
2017-11-24 01:13:52 +01:00
|
|
|
$this->application = new Application();
|
|
|
|
$this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)]));
|
2013-10-23 15:46:45 -04:00
|
|
|
$this->application->add($this->command);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testClearAllRegion()
|
|
|
|
{
|
2017-11-24 01:13:52 +01:00
|
|
|
$command = $this->application->find('orm:clear-cache:region:collection');
|
|
|
|
$tester = new CommandTester($command);
|
|
|
|
|
2016-12-07 23:33:41 +01:00
|
|
|
$tester->execute(
|
|
|
|
[
|
2017-11-24 01:13:52 +01:00
|
|
|
'command' => $command->getName(),
|
|
|
|
'--all' => true,
|
|
|
|
],
|
|
|
|
['decorated' => false]
|
2016-12-07 23:33:41 +01:00
|
|
|
);
|
2013-10-23 15:46:45 -04:00
|
|
|
|
2017-11-23 11:18:21 +01:00
|
|
|
self::assertContains(' // Clearing all second-level cache collection regions', $tester->getDisplay());
|
2013-10-23 15:46:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testClearByOwnerEntityClassName()
|
|
|
|
{
|
2017-11-24 01:13:52 +01:00
|
|
|
$command = $this->application->find('orm:clear-cache:region:collection');
|
|
|
|
$tester = new CommandTester($command);
|
|
|
|
|
2016-12-07 23:33:41 +01:00
|
|
|
$tester->execute(
|
|
|
|
[
|
2017-11-24 01:13:52 +01:00
|
|
|
'command' => $command->getName(),
|
|
|
|
'owner-class' => State::class,
|
|
|
|
'association' => 'cities',
|
|
|
|
],
|
|
|
|
['decorated' => false]
|
2016-12-07 23:33:41 +01:00
|
|
|
);
|
2013-10-23 15:46:45 -04:00
|
|
|
|
2017-11-23 11:18:21 +01:00
|
|
|
self::assertContains(
|
|
|
|
' // Clearing second-level cache for collection "Doctrine\Tests\Models\Cache\State#cities"',
|
|
|
|
$tester->getDisplay()
|
|
|
|
);
|
2013-10-23 15:46:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testClearCacheEntryName()
|
|
|
|
{
|
2017-11-24 01:13:52 +01:00
|
|
|
$command = $this->application->find('orm:clear-cache:region:collection');
|
|
|
|
$tester = new CommandTester($command);
|
|
|
|
|
2016-12-07 23:33:41 +01:00
|
|
|
$tester->execute(
|
|
|
|
[
|
2017-11-24 01:13:52 +01:00
|
|
|
'command' => $command->getName(),
|
|
|
|
'owner-class' => State::class,
|
|
|
|
'association' => 'cities',
|
|
|
|
'owner-id' => 1,
|
|
|
|
],
|
|
|
|
['decorated' => false]
|
2016-12-07 23:33:41 +01:00
|
|
|
);
|
2013-10-23 15:46:45 -04:00
|
|
|
|
2017-11-23 11:18:21 +01:00
|
|
|
self::assertContains(
|
|
|
|
' // Clearing second-level cache entry for collection "Doctrine\Tests\Models\Cache\State#cities" owner',
|
|
|
|
$tester->getDisplay()
|
|
|
|
);
|
|
|
|
|
|
|
|
self::assertContains(' // entity identified by "1"', $tester->getDisplay());
|
2013-10-23 15:46:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFlushRegionName()
|
|
|
|
{
|
2017-11-24 01:13:52 +01:00
|
|
|
$command = $this->application->find('orm:clear-cache:region:collection');
|
|
|
|
$tester = new CommandTester($command);
|
|
|
|
|
2016-12-07 23:33:41 +01:00
|
|
|
$tester->execute(
|
|
|
|
[
|
2017-11-24 01:13:52 +01:00
|
|
|
'command' => $command->getName(),
|
|
|
|
'owner-class' => State::class,
|
|
|
|
'association' => 'cities',
|
|
|
|
'--flush' => true,
|
|
|
|
],
|
|
|
|
['decorated' => false]
|
2016-12-07 23:33:41 +01:00
|
|
|
);
|
2013-10-23 15:46:45 -04:00
|
|
|
|
2017-11-23 11:18:21 +01:00
|
|
|
self::assertContains(
|
|
|
|
' // Flushing cache provider configured for "Doctrine\Tests\Models\Cache\State#cities"',
|
|
|
|
$tester->getDisplay()
|
|
|
|
);
|
2013-10-23 15:46:45 -04:00
|
|
|
}
|
|
|
|
}
|