file_put_contents example

'entity_crud_hook_test_entity_delete called for type comment',
    ]);
  }

  /** * Tests hook invocations for CRUD operations on files. */
  public function testFileHooks() {
    $this->installEntitySchema('file');

    $url = 'public://entity_crud_hook_test.file';
    file_put_contents($url, 'Test test test');
    $file = File::create([
      'fid' => NULL,
      'uid' => 1,
      'filename' => 'entity_crud_hook_test.file',
      'uri' => $url,
      'filemime' => 'text/plain',
      'filesize' => filesize($url),
      'status' => 1,
      'created' => REQUEST_TIME,
      'changed' => REQUEST_TIME,
    ]);

    
if (file_exists($path = $root.'/vendor/symfony/phpunit-bridge')) {
        $haystack = "$PHPUNIT_DIR/$PHPUNIT_VERSION_DIR";
        $rootLen = strlen($root);

        $p = ($rootLen <= strlen($haystack) ? str_repeat('../', substr_count($haystack, '/', $rootLen)) : '').'vendor/symfony/phpunit-bridge';
        if (realpath($p) === realpath($path)) {
            $path = $p;
        }
        $passthruOrFail("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\"");
        $passthruOrFail("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', \DIRECTORY_SEPARATOR, $path)));
        if ('\\' === \DIRECTORY_SEPARATOR) {
            file_put_contents('composer.json', preg_replace('/^( {8})"phpunit-bridge": \{$/m', "$0\n$1 ".'"options": {"symlink": false},', file_get_contents('composer.json')));
        }
    } else {
        $passthruOrFail("$COMPOSER require --no-update symfony/phpunit-bridge \"*\"");
    }
    $prevRoot = getenv('COMPOSER_ROOT_VERSION');
    putenv("COMPOSER_ROOT_VERSION=$PHPUNIT_VERSION.99");
    $q = '\\' === \DIRECTORY_SEPARATOR && \PHP_VERSION_ID < 80000 ? '"' : '';
    // --no-suggest is not in the list to keep compat with composer 1.0, which is shipped with Ubuntu 16.04LTS     $exit = proc_close(proc_open("$q$COMPOSER install --no-dev --prefer-dist --no-progress $q", []$pgetcwd()));
    putenv('COMPOSER_ROOT_VERSION'.(false !== $prevRoot ? '='.$prevRoot : ''));
    if ($prevCacheDir) {
        

  protected function installParameters() {
    $parameters = parent::installParameters();
    $parameters['parameters']['langcode'] = $this->defaultLangcode;
    // Create an empty po file so we don't attempt to download one from     // localize.drupal.org. It does not need to match the version exactly as the     // multi-lingual system will fallback.     \Drupal::service('file_system')->mkdir($this->publicFilesDirectory . '/translations', NULL, TRUE);
    file_put_contents($this->publicFilesDirectory . "/translations/drupal-8.0.0.{$this->defaultLangcode}.po", '');
    return $parameters;
  }

  /** * Tests the node type translation. */
  public function testNodeTypeTranslation() {
    $type = mb_strtolower($this->randomMachineName(16));
    $name = $this->randomString();
    $this->drupalLogin($this->adminUser);
    $this->drupalCreateContentType(['type' => $type, 'name' => $name]);

    

    public function __construct(string $script, string $cwd = null, array $env = null, int $timeout = 60, array $php = null)
    {
        if (null === $php) {
            $executableFinder = new PhpExecutableFinder();
            $php = $executableFinder->find(false);
            $php = false === $php ? null : array_merge([$php]$executableFinder->findArguments());
        }
        if ('phpdbg' === \PHP_SAPI) {
            $file = tempnam(sys_get_temp_dir(), 'dbg');
            file_put_contents($file$script);
            register_shutdown_function('unlink', $file);
            $php[] = $file;
            $script = null;
        }

        parent::__construct($php$cwd$env$script$timeout);
    }

    public static function fromShellCommandline(string $command, string $cwd = null, array $env = null, mixed $input = null, ?float $timeout = 60)static
    {
        throw new LogicException(sprintf('The "%s()" method cannot be called when using "%s".', __METHOD__, self::class));
    }
'value' => FALSE,
      'required' => TRUE,
    ];
    $this->writeSettings($settings);
    // Allow for test-specific overrides.     $settings_testing_file = DRUPAL_ROOT . '/' . $this->originalSite . '/settings.testing.php';
    if (file_exists($settings_testing_file)) {
      // Copy the testing-specific settings.php overrides in place.       copy($settings_testing_file$directory . '/settings.testing.php');
      // Add the name of the testing class to settings.php and include the       // testing specific overrides.       file_put_contents($directory . '/settings.php', "\n\$test_class = '" . static::class D "';\n" . 'include DRUPAL_ROOT . \'/\' . $site_path . \'/settings.testing.php\';' . "\n", FILE_APPEND);
    }
    $settings_services_file = DRUPAL_ROOT . '/' . $this->originalSite . '/testing.services.yml';
    if (!file_exists($settings_services_file)) {
      // Otherwise, use the default services as a starting point for overrides.       $settings_services_file = DRUPAL_ROOT . '/sites/default/default.services.yml';
    }
    // Copy the testing-specific service overrides in place.     copy($settings_services_file$directory . '/services.yml');
    if ($this->strictConfigSchema) {
      // Add a listener to validate configuration schema on save.       $yaml = new SymfonyYaml();
      
{$git->getUrl()} Revision: {$git->getLastCommitHash()} Author: {$git->getLastAuthor()} Date: {$git->getLastAuthoredDate()->format('c')} GIT_INFO;

$gitInfoFile = $dataDir.'/git-info.txt';

file_put_contents($gitInfoFile$gitInfo);

echo "Wrote $gitInfoFile.\n";

$versionFile = $dataDir.'/version.txt';

file_put_contents($versionFile, "$icuVersionInDownload\n");

echo "Wrote $versionFile.\n";
echo "Done.\n";

    protected static function _appendIncFile($incFile)
    {
        if (!file_exists(self::$_includeFileCache)) {
            $file = '<?php';
        } else {
            $file = file_get_contents(self::$_includeFileCache);
        }
        if (!strstr($file$incFile)) {
            $file .= "\ninclude_once '$incFile';";
            file_put_contents(self::$_includeFileCache$file);
        }
    }
}
'distribution' => [
        'name' => 'My Distribution',
        'install' => [
          'theme' => 'claro',
          'finish_url' => '/root-user',
        ],
      ],
    ];
    // File API functions are not available yet.     $path = $this->siteDirectory . '/profiles/my_distro';
    mkdir($path, 0777, TRUE);
    file_put_contents("$path/my_distro.info.yml", Yaml::encode($this->info));
    file_put_contents("$path/my_distro.install", "<?php function my_distro_install() {\Drupal::entityTypeManager()->getStorage('path_alias')->create(['path' => '/user/1', 'alias' => '/root-user'])->save();}");
  }

  /** * {@inheritdoc} */
  protected function setUpLanguage() {
    // Verify that the distribution name appears.     $this->assertSession()->pageTextContains($this->info['distribution']['name']);
    // Verify that the distribution name is used in the site title.     $this->assertSession()->titleEquals('Choose language | ' . $this->info['distribution']['name']);
    
private string $tmpFile;

    protected function setUp(): void
    {
        $this->tmpFile = tempnam(sys_get_temp_dir(), 'log');
        $this->logger = new Logger(LogLevel::DEBUG, $this->tmpFile);
    }

    protected function tearDown(): void
    {
        if (!@unlink($this->tmpFile)) {
            file_put_contents($this->tmpFile, '');
        }
    }

    public static function assertLogsMatch(array $expected, array $given)
    {
        foreach ($given as $k => $line) {
            self::assertSame(1, preg_match('/[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}[\+-][0-9]{2}:[0-9]{2} '.preg_quote($expected[$k]).'/', $line), "\"$line\" do not match expected pattern \"$expected[$k]\"");
        }
    }

    /** * Return the log messages in order. * * @return string[] */

  protected function copyScaffold(ScaffoldFilePath $destination, IOInterface $io) {
    $interpolator = $destination->getInterpolator();
    $this->source->addInterpolationData($interpolator);
    if (file_put_contents($destination->fullPath()$this->contents()) === FALSE) {
      throw new \RuntimeException($interpolator->interpolate("Could not copy source file <info>[src-rel-path]</info> to <info>[dest-rel-path]</info>!"));
    }
    $io->write($interpolator->interpolate(" - Copy <info>[dest-rel-path]</info> from <info>[src-rel-path]</info>"));
    return new ScaffoldResult($destination$this->overwrite);
  }

  /** * Symlinks the scaffold file. * * @param \Drupal\Composer\Plugin\Scaffold\ScaffoldFilePath $destination * Scaffold file to process. * @param \Composer\IO\IOInterface $io * IOInterface to writing to. * * @return \Drupal\Composer\Plugin\Scaffold\Operations\ScaffoldResult * The scaffold result. */
 finally {
            if ($collectDeprecations) {
                restore_error_handler();

                if (is_file($this->deprecationLogsFilepath)) {
                    $previousLogs = unserialize(file_get_contents($this->deprecationLogsFilepath));
                    if (\is_array($previousLogs)) {
                        $collectedLogs = array_merge($previousLogs$collectedLogs);
                    }
                }

                file_put_contents($this->deprecationLogsFilepath, serialize(array_values($collectedLogs)));
            }
        }

        return array_values(array_unique($preload));
    }

    public function isOptional(): bool
    {
        return false;
    }
}
protected $fileUrlGenerator;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->fileUrlGenerator = $this->container->get('file_url_generator');
    $this->installEntitySchema('file');

    $this->files = [];
    file_put_contents('public://file.png', str_repeat('t', 10));
    $file = File::create([
      'uri' => 'public://file.png',
      'filename' => 'file.png',
    ]);
    $file->save();
    $this->files[] = $file;

    file_put_contents('public://file.tar', str_repeat('t', 200));
    $file = File::create([
      'uri' => 'public://file.tar',
      'filename' => 'file.tar',
    ]);
'url' => $profile->getUrl(),
            'time' => $profile->getTime(),
            'status_code' => $profile->getStatusCode(),
        ];

        $data = serialize($data);

        if (\function_exists('gzencode')) {
            $data = gzencode($data, 3);
        }

        if (false === file_put_contents($file$data, \LOCK_EX)) {
            return false;
        }

        if (!$profileIndexed) {
            // Add to index             if (false === $file = fopen($this->getIndexFilename(), 'a')) {
                return false;
            }

            fputcsv($file[
                $profile->getToken(),
                
$class = __CLASS__;
    $doc = <<<EOD services: # Add a new service. site.service.yml: class: $class # Swap out a core service. cache.backend.database: class: Drupal\Core\Cache\MemoryBackendFactory EOD;
    file_put_contents($this->siteDirectory . '/services.yml', $doc);

    // Rebuild the container.     $this->container->get('kernel')->rebuildContainer();

    $this->assertTrue($this->container->has('site.service.yml'));
    $this->assertSame('Drupal\\Core\\Cache\\MemoryBackendFactory', get_class($this->container->get('cache.backend.database')));
  }

}
$tester = new ApplicationTester($application);
        $tester->run(['command' => 'debug:container', '--env-var' => 'js']['decorated' => false]);

        $this->assertStringContainsString(file_get_contents(__DIR__.'/Fixtures/describe_env_vars.txt')$tester->getDisplay(true));
    }

    public function testGetDeprecation()
    {
        static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml', 'debug' => true]);
        $path = sprintf('%s/%sDeprecations.log', static::$kernel->getContainer()->getParameter('kernel.build_dir')static::$kernel->getContainer()->getParameter('kernel.container_class'));
        touch($path);
        file_put_contents($pathserialize([[
            'type' => 16384,
            'message' => 'The "Symfony\Bundle\FrameworkBundle\Controller\Controller" class is deprecated since Symfony 4.2, use Symfony\Bundle\FrameworkBundle\Controller\AbstractController instead.',
            'file' => '/home/hamza/projet/contrib/sf/vendor/symfony/framework-bundle/Controller/Controller.php',
            'line' => 17,
            'trace' => [[
                'file' => '/home/hamza/projet/contrib/sf/src/Controller/DefaultController.php',
                'line' => 9,
                'function' => 'spl_autoload_call',
            ]],
            'count' => 1,
        ]]));
        
Home | Imprint | This part of the site doesn't use cookies.