createForFileCouldNotBeFound() public static method

public static createForFileCouldNotBeFound ( string $file, integer $code, Throwable $previous = null ) : InvalidArgumentException
$file string
$code integer
$previous Throwable
return InvalidArgumentException
Esempio n. 1
0
 /**
  * {@inheritDoc}
  *
  * @param string $file Local PHP file
  */
 public function parse(string $file) : array
 {
     if (false === file_exists($file)) {
         throw InvalidArgumentExceptionFactory::createForFileCouldNotBeFound($file);
     }
     $data = (include $file);
     if (false === is_array($data)) {
         throw TypeErrorFactory::createForInvalidFixtureFileReturnedData($file);
     }
     return $data;
 }
Esempio n. 2
0
 /**
  * {@inheritDoc}
  *
  * @param string $file Local YAML file
  *
  * @throws ParseException
  */
 public function parse(string $file) : array
 {
     if (false === file_exists($file)) {
         throw InvalidArgumentExceptionFactory::createForFileCouldNotBeFound($file);
     }
     try {
         $data = $this->yamlParser->parse(file_get_contents($file));
         // $data is null only if the YAML file was empty; otherwise an exception is thrown
         return null === $data ? [] : $data;
     } catch (\Exception $exception) {
         if ($exception instanceof SymfonyParseException) {
             throw ParseExceptionFactory::createForInvalidYaml($file, 0, $exception);
         }
         throw ParseExceptionFactory::createForUnparsableFile($file, 0, $exception);
     }
 }
Esempio n. 3
0
 /**
  * @inheritdoc
  */
 public function parse(string $file) : array
 {
     try {
         $realPath = $this->fileLocator->locate($file);
     } catch (FileNotFoundException $exception) {
         throw InvalidArgumentExceptionFactory::createForFileCouldNotBeFound($file, 0, $exception);
     }
     if (array_key_exists($realPath, $this->cache)) {
         return $this->cache[$realPath];
     }
     $data = $this->parser->parse($realPath);
     if (array_key_exists('include', $data)) {
         $data = $this->includeProcessor->process($this, $file, $data);
     }
     $this->cache[$realPath] = $data;
     return $data;
 }
 public function testTestCreateForFileCouldNotBeFound()
 {
     $exception = InvalidArgumentExceptionFactory::createForFileCouldNotBeFound('foo');
     $this->assertEquals('The file "foo" could not be found.', $exception->getMessage());
     $this->assertEquals(0, $exception->getCode());
     $this->assertNull($exception->getPrevious());
     $code = 500;
     $previous = new \Error();
     $exception = InvalidArgumentExceptionFactory::createForFileCouldNotBeFound('foo', $code, $previous);
     $this->assertEquals('The file "foo" could not be found.', $exception->getMessage());
     $this->assertEquals($code, $exception->getCode());
     $this->assertSame($previous, $exception->getPrevious());
 }