1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OpenOrchestra\FuntionalTests\BackOfficeBundle\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
6
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
7
|
|
|
use OpenOrchestra\BaseBundle\Tests\AbstractTest\AbstractWebTestCase; |
8
|
|
|
use OpenOrchestra\BackofficeBundle\Command\OrchestraPublishNodeCommand; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class OrchestraPublishNodeCommandTest |
12
|
|
|
*/ |
13
|
|
View Code Duplication |
class OrchestraPublishNodeCommandTest extends AbstractWebTestCase |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
protected $application; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Set Up |
19
|
|
|
*/ |
20
|
|
|
public function setUp() |
21
|
|
|
{ |
22
|
|
|
$client = self::createClient(); |
23
|
|
|
$this->application = new Application($client->getKernel()); |
24
|
|
|
$this->application->setAutoExit(false); |
25
|
|
|
$this->application->add(new OrchestraPublishNodeCommand()); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Test the command |
30
|
|
|
* |
31
|
|
|
* @param string $siteId |
32
|
|
|
* |
33
|
|
|
* @dataProvider provideSiteId |
34
|
|
|
*/ |
35
|
|
|
public function testExecute($siteId) |
36
|
|
|
{ |
37
|
|
|
$command = $this->application->find('orchestra:publish:node'); |
38
|
|
|
$commandTester = new CommandTester($command); |
39
|
|
|
|
40
|
|
|
$site = static::$kernel->getContainer()->get('open_orchestra_model.repository.site')->findOneBySiteId($siteId); |
41
|
|
|
$fromStatus = static::$kernel->getContainer()->get('open_orchestra_model.repository.status') |
42
|
|
|
->findByAutoPublishFrom(); |
43
|
|
|
$nodes = static::$kernel->getContainer()->get('open_orchestra_model.repository.node') |
44
|
|
|
->findNodeToAutoPublish($site->getSiteId(), $fromStatus); |
45
|
|
|
|
46
|
|
|
$commandTester->execute(array('command' => $command->getName())); |
47
|
|
|
$this->assertRegExp( |
48
|
|
|
'/Publishing nodes for siteId ' . $siteId . '/', |
49
|
|
|
$commandTester->getDisplay() |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
foreach ($nodes as $node) { |
53
|
|
|
$this->assertRegExp( |
54
|
|
|
'/-> ' . $node->getName() . ' \(v' . $node->getVersion() . ' ' . $node->getLanguage() . '\) published/', |
55
|
|
|
$commandTester->getDisplay() |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$this->assertRegExp('/Done./', $commandTester->getDisplay()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Provide site id |
64
|
|
|
*/ |
65
|
|
|
public function provideSiteId() |
66
|
|
|
{ |
67
|
|
|
return array( |
68
|
|
|
array('2'), |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.