isSuccessful example

return (bool) preg_match($pattern$control);
    }

    public function handle(HttpCache $cache, string $uri, string $alt, bool $ignoreErrors): string
    {
        $subRequest = Request::create($uri, Request::METHOD_GET, []$cache->getRequest()->cookies->all()[]$cache->getRequest()->server->all());

        try {
            $response = $cache->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true);

            if (!$response->isSuccessful() && Response::HTTP_NOT_MODIFIED !== $response->getStatusCode()) {
                throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %d).', $subRequest->getUri()$response->getStatusCode()));
            }

            return $response->getContent();
        } catch (\Exception $e) {
            if ($alt) {
                return $this->handle($cache$alt, '', $ignoreErrors);
            }

            if (!$ignoreErrors) {
                throw $e;
            }
return (bool) preg_match($pattern$control);
    }

    public function handle(HttpCache $cache, string $uri, string $alt, bool $ignoreErrors): string
    {
        $subRequest = Request::create($uri, Request::METHOD_GET, []$cache->getRequest()->cookies->all()[]$cache->getRequest()->server->all());

        try {
            $response = $cache->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true);

            if (!$response->isSuccessful() && Response::HTTP_NOT_MODIFIED !== $response->getStatusCode()) {
                throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %d).', $subRequest->getUri()$response->getStatusCode()));
            }

            return $response->getContent();
        } catch (\Exception $e) {
            if ($alt) {
                return $this->handle($cache$alt, '', $ignoreErrors);
            }

            if (!$ignoreErrors) {
                throw $e;
            }

  protected function renderResponseBody(Request $request, ResourceResponse $response, SerializerInterface $serializer$format) {
    $data = $response->getResponseData();

    // If there is data to send, serialize and set it as the response body.     if ($data !== NULL) {
      // First normalize the data. Note that error responses do not need a       // normalization context, since there are no entities to normalize.       // @see \Drupal\jsonapi\EventSubscriber\DefaultExceptionSubscriber::isJsonApiExceptionEvent()       $context = !$response->isSuccessful() ? [] : static::generateContext($request);
      $jsonapi_doc_object = $serializer->normalize($data$format$context);
      // Having just normalized the data, we can associate its cacheability with       // the response object.       if ($response instanceof CacheableResponseInterface) {
        assert($jsonapi_doc_object instanceof CacheableNormalization);
        $response->addCacheableDependency($jsonapi_doc_object);
      }
      // Finally, encode the normalized data (JSON:API's encoder rasterizes it       // automatically).       $response->setContent($serializer->encode($jsonapi_doc_object->getNormalization()$format));
      $response->headers->set('Content-Type', $request->getMimeType($format));
    }

      else {
        // If the current version is developing towards an x.y.0 release, there         // might be tagged pre-releases. "git describe" identifies the latest         // one.         $root = $this->getDrupalRoot();
        $process = $this->executeCommand("git -C \"$root\" describe --abbrev=0 --match=\"$version_towards-*\"");

        // If there aren't any tagged pre-releases for this version yet, return         // 'dev'. Ensure that any other error from "git describe" causes a test         // failure.         if (!$process->isSuccessful()) {
          $this->assertErrorOutputContains('No names found, cannot describe anything.');
          return 'dev';
        }

        // We expect a pre-release, because:         // - A tag should not be of "dev" stability.         // - After a "stable" release is made, \Drupal::VERSION is incremented,         // so there should not be a stable release on that new version.         $stability = VersionParser::parseStability(trim($process->getOutput()));
        $this->assertContains($stability['alpha', 'beta', 'RC']);
      }
    }
if ($verbosity <= $output->getVerbosity()) {
            $output->write($formatter->start(spl_object_hash($process)$this->escapeString($process->getCommandLine())));
        }

        if ($output->isDebug()) {
            $callback = $this->wrapCallback($output$process$callback);
        }

        $process->run($callback$cmd);

        if ($verbosity <= $output->getVerbosity()) {
            $message = $process->isSuccessful() ? 'Command ran successfully' : sprintf('%s Command did not run successfully', $process->getExitCode());
            $output->write($formatter->stop(spl_object_hash($process)$message$process->isSuccessful()));
        }

        if (!$process->isSuccessful() && null !== $error) {
            $output->writeln(sprintf('<error>%s</error>', $this->escapeString($error)));
        }

        return $process;
    }

    /** * Runs the process. * * This is identical to run() except that an exception is thrown if the process * exits with a non-zero exit code. * * @param array|Process $cmd An instance of Process or a command to run * @param callable|null $callback A PHP callback to run whenever there is some * output available on STDOUT or STDERR * * @throws ProcessFailedException * * @see run() */
$this->assertEquals(304, $modified->getStatusCode());

        ob_start();
        $modified->sendContent();
        $string = ob_get_clean();
        $this->assertEmpty($string);
    }

    public function testIsSuccessful()
    {
        $response = new Response();
        $this->assertTrue($response->isSuccessful());
    }

    public function testIsNotModified()
    {
        $response = new Response();
        $modified = $response->isNotModified(new Request());
        $this->assertFalse($modified);
    }

    public function testIsNotModifiedNotSafe()
    {
        
$process->stop();
                $this->fail();
            } elseif ("READY\n" === $buffer) {
                $dumper->dump($data);
            } else {
                $dumped .= $buffer;
            }
        });

        $process->wait();

        $this->assertTrue($process->isSuccessful());
        $this->assertStringMatchesFormat(<<<'DUMP' (3) "foo" [ "timestamp" => %d.%d "foo_provider" => [ (3) "foo" ] ] %d DUMP
            , $dumped);
    }
$twig = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock();
        $twig->expects($this->once())->method('render')->with('foo', ['bar' => $formView])->willReturn('bar');

        $container = new Container();
        $container->set('twig', $twig);

        $controller = $this->createController();
        $controller->setContainer($container);

        $response = $controller->renderForm('foo', ['bar' => $form]);

        $this->assertTrue($response->isSuccessful());
        $this->assertSame('bar', $response->getContent());
    }

    /** * @group legacy */
    public function testRenderFormSubmittedAndInvalid()
    {
        $formView = new FormView();

        $form = $this->getMockBuilder(FormInterface::class)->getMock();
        

        $fs->mkdir($folder . '/custom/plugins');
        $fs->mkdir($folder . '/custom/static-plugins');

        ProjectComposerJsonUpdater::update(
            $folder . '/composer.json',
            $shopwareVersion
        );

        $finish = function DProcess $process) use ($request): void {
            echo json_encode([
                'success' => $process->isSuccessful(),
                'newLocation' => $request->getBasePath() . '/public/',
            ]);
        };

        return $this->streamedCommandResponseGenerator->run([
            $this->recoveryManager->getPhpBinary($request),
            '-dmemory_limit=1G',
            $this->recoveryManager->getBinary(),
            'install',
            '-d',
            $folder,
            
/** * Exception for failed processes. * * @author Johannes M. Schmitt <schmittjoh@gmail.com> */
class ProcessFailedException extends RuntimeException
{
    private Process $process;

    public function __construct(Process $process)
    {
        if ($process->isSuccessful()) {
            throw new InvalidArgumentException('Expected a failed process, but the given process was successful.');
        }

        $error = sprintf('The command "%s" failed.'."\n\nExit Code: %s(%s)\n\nWorking directory: %s",
            $process->getCommandLine(),
            $process->getExitCode(),
            $process->getExitCodeText(),
            $process->getWorkingDirectory()
        );

        if (!$process->isOutputDisabled()) {
            
$process->stop();
                $this->fail();
            } elseif ("READY\n" === $buffer) {
                $connection->write($data);
            } else {
                $dumped .= $buffer;
            }
        });

        $process->wait();

        $this->assertTrue($process->isSuccessful());
        $this->assertStringMatchesFormat(<<<'DUMP' (3) "foo" [ "timestamp" => %d.%d "foo_provider" => [ (3) "foo" ] ] %d DUMP
            ,
$expected_resource_response = $this->getExpectedGetRelationshipResponse($relationship_field_name);
      $expected_document = $expected_resource_response->getResponseData();
      $expected_cacheability = $expected_resource_response->getCacheableMetadata();
      $actual_response = $related_responses[$relationship_field_name];
      $this->assertResourceResponse(
        $expected_resource_response->getStatusCode(),
        $expected_document,
        $actual_response,
        $expected_cacheability->getCacheTags(),
        $expected_cacheability->getCacheContexts(),
        FALSE,
        $expected_resource_response->isSuccessful() ? 'MISS' : FALSE
      );
    }
  }

  /** * Performs one round of relationship POST, PATCH and DELETE route testing. * * @param array $request_options * Request options to apply. * * @see \GuzzleHttp\ClientInterface::request() * @see ::testRelationships */
if (null === $lastModified = $this->getLastModified()) {
            return false;
        }

        return $lastModified->format('D, d M Y H:i:s').' GMT' === $header;
    }

    public function sendContent()static
    {
        try {
            if (!$this->isSuccessful()) {
                return $this;
            }

            if (0 === $this->maxlen) {
                return $this;
            }

            $out = fopen('php://output', 'w');
            $file = fopen($this->file->getPathname(), 'r');

            ignore_user_abort(true);

            

class StreamedCommandResponseGeneratorTest extends TestCase
{
    public function testRun(): void
    {
        $generator = new StreamedCommandResponseGenerator();

        $response = $generator->run(['echo', 'foo']function DProcess $process): void {
            static::assertTrue($process->isSuccessful());
        });

        ob_start();
        $response->sendContent();

        $content = ob_get_clean();

        static::assertSame('foo', trim((string) $content));
    }

    public function testRunJSON(): void
    {
private function isPHPRunning(string $path): bool
    {
        $process = new Process([$path, '-v']);

        try {
            $process->run();
        } catch (ProcessSignaledException) {
            return false;
        }

        return $process->isSuccessful();
    }
}
Home | Imprint | This part of the site doesn't use cookies.