1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the ONGR package. |
5
|
|
|
* |
6
|
|
|
* (c) NFQ Technologies UAB <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace ONGR\SettingsBundle\Tests\Functional\Command; |
13
|
|
|
|
14
|
|
|
use ONGR\ElasticsearchBundle\Test\AbstractElasticsearchTestCase; |
15
|
|
|
use ONGR\SettingsBundle\Command\CacheClearCommand; |
16
|
|
|
use Symfony\Component\Console\Application; |
17
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
18
|
|
|
|
19
|
|
|
class CacheClearCommandTest extends AbstractElasticsearchTestCase |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Tests the normal functioning of the command |
23
|
|
|
*/ |
24
|
|
|
public function testCacheClear() |
25
|
|
|
{ |
26
|
|
|
$cache = $this->getContainer()->get('ong_settings.cache_provider'); |
27
|
|
|
$commandTester = $this->getCommandTester(); |
28
|
|
|
|
29
|
|
|
$cache->save('foo', 'bar'); |
30
|
|
|
|
31
|
|
|
$this->assertTrue($cache->contains('foo')); |
32
|
|
|
$this->assertEquals('bar', $cache->fetch('foo')); |
33
|
|
|
|
34
|
|
|
$commandTester->execute( |
35
|
|
|
[ |
36
|
|
|
'command' => 'ongr:settings:cache:clear', |
37
|
|
|
'setting_name' => 'foo', |
38
|
|
|
] |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
$this->assertContains( |
42
|
|
|
'`foo` has been successfully cleared from cache', |
43
|
|
|
$commandTester->getDisplay() |
44
|
|
|
); |
45
|
|
|
$this->assertFalse($cache->contains('foo')); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Tests the command when a non-existing setting is provided |
50
|
|
|
*/ |
51
|
|
|
public function testEmptySettingClear() |
52
|
|
|
{ |
53
|
|
|
$commandTester = $this->getCommandTester(); |
54
|
|
|
|
55
|
|
|
$commandTester->execute( |
56
|
|
|
[ |
57
|
|
|
'command' => 'ongr:settings:cache:clear', |
58
|
|
|
'setting_name' => 'foo', |
59
|
|
|
] |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
$this->assertContains( |
63
|
|
|
'Cache does not contain a setting named `foo`', |
64
|
|
|
$commandTester->getDisplay() |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Returns cache clear command with assigned container. |
70
|
|
|
* |
71
|
|
|
* @return CommandTester |
72
|
|
|
*/ |
73
|
|
|
private function getCommandTester() |
74
|
|
|
{ |
75
|
|
|
$app = new Application(); |
76
|
|
|
$command = new CacheClearCommand(); |
77
|
|
|
$command->setContainer($this->getContainer()); |
78
|
|
|
|
79
|
|
|
$app->add($command); |
80
|
|
|
|
81
|
|
|
$command = $app->find('ongr:settings:cache:clear'); |
82
|
|
|
$commandTester = new CommandTester($command); |
83
|
|
|
|
84
|
|
|
return $commandTester; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|