public function __construct(Mutation $mutation, FileGenerator $generator, CoverageData $coverage, $baseDirectory) { $this->mutation = $mutation; try { $this->tests = $coverage->getTestClasses($mutation->getFile(), $mutation->getLine()); $this->testMethods = $coverage->getTestMethods($mutation->getFile(), $mutation->getLine()); } catch (NoCoveringTestsException $e) { $this->tests = []; $this->testMethods = []; } $this->file = $generator->generateFile($mutation); $this->baseDirectory = $baseDirectory; $this->diff = Diff::getInstance(); }
/** * @param Collector $collector * @param CoverageData $coverage * @param array $batch */ private function runBatch(Collector $collector, CoverageData $coverage, array $batch, IncrementalCache $cache = null) { $processes = []; foreach ($batch as $batchItem) { list($index, $mutation) = $batchItem; try { $coverage->loadCoverageFor($mutation->getFile()); /** * Unleash the Mutant! */ $mutant = new Mutant($mutation, $this->mutantGenerator, $coverage, $this->baseDirectory); if (!$mutant->hasTests()) { throw new NoCoveringTestsException('Current mutant has no covering tests'); } if (!is_null($cache)) { $hit = $this->runCache($cache, $coverage, $collector, $mutation->getFile(), $index); if ($hit === true) { continue; } } $processes[] = $this->processBuilder->build($mutant, $index); } catch (NoCoveringTestsException $e) { $shadow = new Mutant($mutation, $this->mutantGenerator, $coverage, $this->baseDirectory); $collector->collectShadow($shadow); $this->onShadowMutant($index); } } /** * Check if the whole batch has been eliminated as uncovered * by any tests */ if (count($processes) == 0) { return; } $group = new ParallelGroup($processes); $group->run(); foreach ($processes as $process) { /** * Handle the defined result for each process */ $result = $process->getResult(); $this->onMutantDone($result, $process->getMutableIndex()); $collector->collect($result); } }
/** * @param CoverageData $coverage * @param string $file * @return bool */ public function hasModifiedTestFiles(CoverageData $coverage, $file) { $tests = $coverage->getAllTestClasses($file); $testFiles = []; foreach ($tests as $test) { $tfile = $this->container->getAdapter()->getClassFile($test, $this->container); $this->testCollector->collect($tfile); $testFiles[] = $tfile; } foreach ($testFiles as $testFile) { if (!$this->cachedTestCollection->hasFile($testFile)) { return true; } $currentHash = $this->testCollector->getCollection()->getFileHash($testFile); $previousHash = $this->cachedTestCollection->getFileHash($testFile); if ($currentHash !== $previousHash) { return true; } } return false; }