| Conditions | 9 |
| Paths | 128 |
| Total Lines | 109 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 165 | public function testBookPublish($bookName, $editionName) |
||
| 166 | { |
||
| 167 | $slug = $bookName; |
||
| 168 | |||
| 169 | static::$lastBook = static::$currentBook ?: $bookName; |
||
| 170 | static::$currentBook = $bookName; |
||
| 171 | if (static::$currentBook != static::$lastBook) { |
||
| 172 | static::$someEditionOfSameBookHasErrors = false; |
||
| 173 | } |
||
| 174 | |||
| 175 | $this->tmpDir = $this->tmpDirBase . '/' . $slug; |
||
| 176 | |||
| 177 | if ($this->isDebug) { |
||
| 178 | echo sprintf("\n" . '- Processing test "%s"' . "\n", $slug); |
||
| 179 | } |
||
| 180 | |||
| 181 | $thisBookDir = $this->fixturesDir . $slug; |
||
| 182 | |||
| 183 | // mirror test book contents in temp dir |
||
| 184 | $this->filesystem->mirror( |
||
| 185 | $thisBookDir . '/input', |
||
| 186 | $this->tmpDir |
||
| 187 | ); |
||
| 188 | |||
| 189 | // look for and publish the book edition |
||
| 190 | $bookConfigFile = $this->tmpDir . '/config.yml'; |
||
| 191 | |||
| 192 | // publish the book edition |
||
| 193 | $input = new ArrayInput(array( |
||
| 194 | 'command' => 'publish', |
||
| 195 | 'slug' => $slug, |
||
| 196 | 'edition' => $editionName, |
||
| 197 | '--dir' => $this->tmpDirBase, |
||
| 198 | '--themes_dir' => $this->fixturesDir . 'Themes' |
||
| 199 | )); |
||
| 200 | |||
| 201 | $output = new NullOutput(); |
||
| 202 | if ($this->isDebug) { |
||
| 203 | // we want the full output in debug mode |
||
| 204 | $output = new ConsoleOutput(OutputInterface::VERBOSITY_NORMAL, true); |
||
| 205 | } |
||
| 206 | |||
| 207 | $this->console->find('publish')->run($input, $output); |
||
| 208 | |||
| 209 | // look for config.yml modification |
||
| 210 | $expectedBookConfigFile = $thisBookDir . '/expected/config.yml'; |
||
| 211 | if (file_exists($expectedBookConfigFile)) { |
||
| 212 | $this->assertFileEquals( |
||
| 213 | $expectedBookConfigFile, |
||
| 214 | $bookConfigFile, |
||
| 215 | 'Book config.yml not modified correctly' |
||
| 216 | ); |
||
| 217 | } |
||
| 218 | |||
| 219 | // assert that generated files are exactly the same as expected |
||
| 220 | $generatedFiles = Finder::create() |
||
| 221 | ->files() |
||
| 222 | ->notName('.gitignore') |
||
| 223 | ->in($this->tmpDir . '/Output/' . $editionName); |
||
| 224 | |||
| 225 | foreach ($generatedFiles as $file) { |
||
| 226 | /* @var $file SplFileInfo */ |
||
| 227 | |||
| 228 | if ('epub' == $file->getExtension()) { |
||
| 229 | // unzip both files to compare its contents |
||
| 230 | $workDir = $this->tmpDir . '/unzip/' . $editionName; |
||
| 231 | $generated = $workDir . '/generated'; |
||
| 232 | $expected = $workDir . '/expected'; |
||
| 233 | |||
| 234 | Toolkit::unzip($file->getRealPath(), $generated); |
||
| 235 | Toolkit::unzip( |
||
| 236 | $thisBookDir . '/expected/' . |
||
| 237 | $editionName . '/' . $file->getRelativePathname(), |
||
| 238 | $expected |
||
| 239 | ); |
||
| 240 | |||
| 241 | // assert that generated files insize EPUB are exactly the same as expected |
||
| 242 | $this->checkGeneratedFiles($expected, $generated, $file->getPathName()); |
||
| 243 | |||
| 244 | // assert that all required files inside EPUB are generated |
||
| 245 | $this->checkForMissingFiles($expected, $generated); |
||
| 246 | |||
| 247 | } elseif ('mobi' == $file->getExtension()) { |
||
| 248 | // mobi files cannot be compared to expected results |
||
| 249 | // because kindlegen does funny things with the contents |
||
| 250 | // so do nothing |
||
| 251 | |||
| 252 | } else { |
||
| 253 | $this->assertFileEquals( |
||
| 254 | $thisBookDir . '/expected/' . $editionName . '/' . $file->getRelativePathname(), |
||
| 255 | $file->getPathname(), |
||
| 256 | sprintf("'%s' file not properly generated", $file->getPathname()) |
||
| 257 | ); |
||
| 258 | } |
||
| 259 | |||
| 260 | // assert that all required files for this edition are generated |
||
| 261 | $this->checkForMissingFiles( |
||
| 262 | $thisBookDir . '/expected/' . $editionName, |
||
| 263 | $this->tmpDir . '/Output/' . $editionName |
||
| 264 | ); |
||
| 265 | |||
| 266 | // assert that book publication took less than 5 seconds |
||
| 267 | $this->assertLessThan( |
||
| 268 | 10, |
||
| 269 | $this->app['app.timer.finish'] - $this->app['app.timer.start'], |
||
| 270 | sprintf("Publication of '%s' edition for '%s' book took more than 10 seconds", $editionName, $slug) |
||
| 271 | ); |
||
| 272 | } |
||
| 273 | } |
||
| 274 | |||
| 326 |