public function testHasPackage()
 {
     $locker = new LockFileParser(__DIR__ . '/../res/composer.lock');
     $this->assertTrue($locker->hasInstalledPackage('danielstjules/stringy'));
     $this->assertTrue($locker->hasInstalledPackage('klein/klein'));
     $this->assertFalse($locker->hasInstalledPackage('not-a-package'));
 }
Example #2
0
 /**
  * @param ExerciseInterface $exercise
  * @param string $fileName
  * @return ResultInterface
  */
 public function check(ExerciseInterface $exercise, $fileName)
 {
     if (!$exercise instanceof ComposerExerciseCheck) {
         throw new \InvalidArgumentException();
     }
     if (!file_exists(sprintf('%s/composer.json', dirname($fileName)))) {
         return new Failure($this->getName(), 'No composer.json file found');
     }
     if (!file_exists(sprintf('%s/composer.lock', dirname($fileName)))) {
         return new Failure($this->getName(), 'No composer.lock file found');
     }
     $lockFile = new LockFileParser(sprintf('%s/composer.lock', dirname($fileName)));
     $missingPackages = array_filter($exercise->getRequiredPackages(), function ($package) use($lockFile) {
         return !$lockFile->hasInstalledPackage($package);
     });
     if (count($missingPackages) > 0) {
         return new Failure($this->getName(), sprintf('Lockfile doesn\'t include the following packages at any version: "%s"', implode('", "', $missingPackages)));
     }
     return new Success($this->getName());
 }