1 | <?php |
||
17 | class TestCommand extends Command |
||
18 | { |
||
19 | const COMMAND_NAME = 'test'; |
||
20 | |||
21 | /** |
||
22 | * Configure command. |
||
23 | */ |
||
24 | 5 | protected function configure() |
|
31 | |||
32 | /** |
||
33 | * @param InputInterface $input |
||
34 | * @param OutputInterface $output |
||
35 | * |
||
36 | * @throws \RuntimeException |
||
37 | * |
||
38 | * @return int|null|void |
||
39 | */ |
||
40 | 1 | protected function execute(InputInterface $input, OutputInterface $output) |
|
41 | { |
||
42 | 1 | $this->input = $input; |
|
43 | 1 | $this->output = $output; |
|
44 | |||
45 | 1 | $fast = $this->input->getOption('fast'); |
|
46 | 1 | $testDir = sys_get_temp_dir() . '/' . uniqid('SyncFS_tests'); |
|
47 | 1 | $configPath = $testDir . '/config.yml'; |
|
48 | 1 | $srcDir = $testDir . '/sync-from-here'; |
|
49 | 1 | $dstDir = $testDir . '/sync-to-here'; |
|
50 | 1 | $fsHelper = new FileSystemHelper($srcDir); |
|
51 | |||
52 | 1 | $output->writeln(sprintf('<info>Creating temporary files in dir `%s`.</info>', $testDir)); |
|
53 | 1 | $fsHelper->create($srcDir, ! $fast); |
|
54 | |||
55 | 1 | $this->createConfig( |
|
56 | 1 | $configPath, |
|
57 | array( |
||
58 | 'sync-fs' => array( |
||
59 | 'maps' => array( |
||
60 | 'random-folders-sync' => array( |
||
61 | 1 | 'src' => $srcDir, |
|
62 | 1 | 'dst' => $dstDir, |
|
63 | 1 | ), |
|
64 | 1 | ), |
|
65 | 1 | 'timeout' => 30, |
|
66 | 'default_client' => 'rsync' |
||
67 | 1 | ) |
|
68 | 1 | ) |
|
69 | 1 | ); |
|
70 | |||
71 | 1 | $this->runCommand( |
|
72 | 1 | ShowCommand::COMMAND_NAME, |
|
73 | array( |
||
74 | 1 | self::ARG_CONFIG_PATH => $configPath, |
|
75 | ) |
||
76 | 1 | ); |
|
77 | |||
78 | 1 | $this->runCommand( |
|
79 | 1 | SyncCommand::COMMAND_NAME, |
|
80 | array( |
||
81 | 1 | self::ARG_CONFIG_PATH => $configPath, |
|
82 | ) |
||
83 | 1 | ); |
|
84 | |||
85 | 1 | $output->writeln(sprintf('<info>Cleaning up...</info>')); |
|
86 | 1 | $fsHelper->cleanUp($testDir); |
|
87 | 1 | } |
|
88 | |||
89 | /** |
||
90 | * @param string $configPath |
||
91 | * @param array $data |
||
92 | * |
||
93 | * @return int |
||
94 | */ |
||
95 | 1 | private function createConfig($configPath, array $data) |
|
101 | |||
102 | |||
103 | /** |
||
104 | * @param string $name |
||
105 | * @param array $args |
||
106 | * |
||
107 | * @return int |
||
108 | * @throws \LogicException |
||
109 | */ |
||
110 | 1 | protected function runCommand($name, array $args) |
|
118 | |||
119 | /** |
||
120 | * @param string $title |
||
121 | */ |
||
122 | 1 | private function writeSeparator($title) |
|
128 | } |
||
129 |