Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7494 from shadowhand/fix/cli-apcu-warning
Do not allow cache clearing with APCu
- Loading branch information
Showing
7 changed files
with
217 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheMetadataCommandTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Tools\Console\Command; | ||
|
||
use Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand; | ||
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
use LogicException; | ||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\Helper\HelperSet; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
use function sprintf; | ||
|
||
class ClearCacheMetadataCommandTest extends OrmFunctionalTestCase | ||
{ | ||
/** @var Application */ | ||
private $application; | ||
|
||
/** @var MetadataCommand */ | ||
private $command; | ||
|
||
protected function setUp() : void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->command = new MetadataCommand(); | ||
|
||
$this->application = new Application(); | ||
$this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->em)])); | ||
$this->application->add($this->command); | ||
} | ||
|
||
public function dataInvalidCacheDrivers() : array | ||
{ | ||
return [ | ||
'apc' => ['Doctrine\Common\Cache\ApcCache', 'APC Cache'], | ||
'apcu' => ['Doctrine\Common\Cache\ApcuCache', 'APCu Cache'], | ||
'xcache' => ['Doctrine\Common\Cache\XcacheCache', 'XCache Cache'], | ||
]; | ||
} | ||
|
||
/** @dataProvider dataInvalidCacheDrivers */ | ||
public function testCannotClearCacheWithInvalidDriver($driver, $name) : void | ||
{ | ||
$this->em->getConfiguration()->setMetadataCacheImpl(new $driver()); | ||
|
||
$command = $this->application->find('orm:clear-cache:metadata'); | ||
|
||
$tester = new CommandTester($command); | ||
|
||
$this->expectException(LogicException::class); | ||
$this->expectExceptionMessage(sprintf('Cannot clear %s from Console', $name)); | ||
|
||
$tester->execute( | ||
[ | ||
'command' => $command->getName(), | ||
], | ||
['decorated' => false] | ||
); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheQueryCommandTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Tools\Console\Command; | ||
|
||
use Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand; | ||
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
use LogicException; | ||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\Helper\HelperSet; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
use function sprintf; | ||
|
||
class ClearCacheQueryCommandTest extends OrmFunctionalTestCase | ||
{ | ||
/** @var Application */ | ||
private $application; | ||
|
||
/** @var QueryCommand */ | ||
private $command; | ||
|
||
protected function setUp() : void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->command = new QueryCommand(); | ||
|
||
$this->application = new Application(); | ||
$this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->em)])); | ||
$this->application->add($this->command); | ||
} | ||
|
||
public function dataInvalidCacheDrivers() : array | ||
{ | ||
return [ | ||
'apc' => ['Doctrine\Common\Cache\ApcCache', 'APC Cache'], | ||
'apcu' => ['Doctrine\Common\Cache\ApcuCache', 'APCu Cache'], | ||
'xcache' => ['Doctrine\Common\Cache\XcacheCache', 'XCache Cache'], | ||
]; | ||
} | ||
|
||
/** @dataProvider dataInvalidCacheDrivers */ | ||
public function testCannotClearCacheWithInvalidDriver($driver, $name) : void | ||
{ | ||
$this->em->getConfiguration()->setQueryCacheImpl(new $driver()); | ||
|
||
$command = $this->application->find('orm:clear-cache:query'); | ||
|
||
$tester = new CommandTester($command); | ||
|
||
$this->expectException(LogicException::class); | ||
$this->expectExceptionMessage(sprintf('Cannot clear %s from Console', $name)); | ||
|
||
$tester->execute( | ||
[ | ||
'command' => $command->getName(), | ||
], | ||
['decorated' => false] | ||
); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
tests/Doctrine/Tests/ORM/Tools/Console/Command/ClearCacheResultCommandTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Tools\Console\Command; | ||
|
||
use Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand; | ||
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
use LogicException; | ||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\Helper\HelperSet; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
use function sprintf; | ||
|
||
class ClearCacheResultCommandTest extends OrmFunctionalTestCase | ||
{ | ||
/** @var Application */ | ||
private $application; | ||
|
||
/** @var ResultCommand */ | ||
private $command; | ||
|
||
protected function setUp() : void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->command = new ResultCommand(); | ||
|
||
$this->application = new Application(); | ||
$this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->em)])); | ||
$this->application->add($this->command); | ||
} | ||
|
||
public function dataInvalidCacheDrivers() : array | ||
{ | ||
return [ | ||
'apc' => ['Doctrine\Common\Cache\ApcCache', 'APC Cache'], | ||
'apcu' => ['Doctrine\Common\Cache\ApcuCache', 'APCu Cache'], | ||
'xcache' => ['Doctrine\Common\Cache\XcacheCache', 'XCache Cache'], | ||
]; | ||
} | ||
|
||
/** @dataProvider dataInvalidCacheDrivers */ | ||
public function testCannotClearCacheWithInvalidDriver($driver, $name) : void | ||
{ | ||
$this->em->getConfiguration()->setResultCacheImpl(new $driver()); | ||
|
||
$command = $this->application->find('orm:clear-cache:result'); | ||
|
||
$tester = new CommandTester($command); | ||
|
||
$this->expectException(LogicException::class); | ||
$this->expectExceptionMessage(sprintf('Cannot clear %s from Console', $name)); | ||
|
||
$tester->execute( | ||
[ | ||
'command' => $command->getName(), | ||
], | ||
['decorated' => false] | ||
); | ||
} | ||
} |