/** * @test */ function it_can_create_a_new_file_at_the_given_path() { $path = $this->temp_path('new_env'); $env = File::create($path); $this->assertTrue(file_exists($path)); $this->assertTrue($env->exists()); $this->assertSame($path, $env->path()); }
/** * Initialize the environment file. * * [--file=<path-to-dotenv>] * : Path to the environment file. Default: '.env' * * [--with-salts] * : Additionally, generate and define keys for salts * * [--template=<template-name>] * : Path to a template to use to interactively set values * * [--interactive] * : Set new values from the template interactively with prompts for each key-value pair * * [--force] * : Overwrite existing destination file if it exists * * @when before_wp_load * * @param $_ * @param $assoc_args */ public function init($_, $assoc_args) { $this->init_args(func_get_args()); $path = $this->resolve_file_path(); if (file_exists($path) && !$this->get_flag('force')) { WP_CLI::error("Environment file already exists at: {$path}"); return; } $env = File::create($path); if (!$env->exists()) { WP_CLI::error('Failed to create environment file at: ' . $env->path()); return; } if ($this->args->template) { $this->init_from_template($env, $this->args->template); } if ($this->get_flag('with-salts')) { WP_CLI::run_command(['dotenv', 'salts', 'generate'], ['file' => $env->path()]); } WP_CLI::success("{$path} created."); }