Search

Codeception\InitTemplate

  • Uses Codeception\Command\Shared\FileSystemTrait, Codeception\Command\Shared\StyleTrait

Codeception templates allow creating a customized setup and configuration for your project. An abstract class for installation template. Each init template should extend it and implement a setup method. Use it to build a custom setup class which can be started with codecept init command.

<?php
namespace Codeception\Template; // it is important to use this namespace so codecept init could locate this template
class CustomInstall extends \Codeception\InitTemplate
{
     public function setup()
     {
        // implement this
     }
}

This class provides various helper methods for building customized setup

__construct()

public __construct($input, $output)

  • param \Symfony\Component\Console\Input\InputInterface $input
  • param \Symfony\Component\Console\Output\OutputInterface $output

See source

addModulesToComposer()

protected addModulesToComposer(array $modules)

  • param array $modules
  • return ?int

See source

addStyles()

public addStyles($output)

  • param \Symfony\Component\Console\Output\OutputInterface $output
  • return void

See source

ask()

protected ask($question, $answer = null)

  • param string $question
  • param array|string|bool|null $answer
  • return mixed|string
<?php
// propose firefox as default browser
$this->ask('select the browser of your choice', 'firefox');

// propose firefox or chrome possible options
$this->ask('select the browser of your choice', ['firefox', 'chrome']);

// ask true/false question
$this->ask('do you want to proceed (y/n)', true);

See source

breakParts()

protected breakParts($class)

  • param string $class
  • return string[]

See source

checkInstalled()

protected checkInstalled($dir = β€˜.’)

  • param string $dir
  • return void

See source

completeSuffix()

protected completeSuffix($filename, $suffix)

  • param string $filename
  • param string $suffix
  • return string

See source

createActor()

protected createActor($name, $directory, array $suiteConfig)

  • param string $name
  • param string $directory
  • param array $suiteConfig
  • return void

Create an Actor class and generate actions for it.

Requires a suite config as array in 3rd parameter.

See source

createDirectoryFor()

protected createDirectoryFor($basePath, $className = β€˜β€™)

  • param string $basePath
  • param string $className
  • return string

See source

createEmptyDirectory()

protected createEmptyDirectory($dir)

  • param string $dir
  • return void

Create an empty directory and add a placeholder file into it

See source

createFile()

protected createFile($filename, $contents, $force = false, $flags = 0)

  • param string $filename
  • param string $contents
  • param bool $force
  • param int $flags
  • return bool

See source

createHelper()

protected createHelper($name, $directory, array $settings = array ( ))

  • param string $name
  • param string $directory
  • param array $settings
  • return void

Create a helper class inside a directory

See source

getNamespaceHeader()

protected getNamespaceHeader($class)

  • param string $class
  • return string

See source

getNamespaceString()

protected getNamespaceString($class)

  • param string $class
  • return string

See source

getNamespaces()

protected getNamespaces($class)

  • param string $class
  • return array

See source

getShortClassName()

protected getShortClassName($class)

  • param string $class
  • return string

See source

gitIgnore()

protected gitIgnore($path)

  • param string $path
  • return void

See source

initDir()

public initDir($workDir)

  • param string $workDir
  • return void

Change the directory where Codeception should be installed.

See source

removeSuffix()

protected removeSuffix($classname, $suffix)

  • param string $classname
  • param string $suffix
  • return string

See source

say()

protected say($message = β€˜β€™)

  • param string $message
  • return void

Print a message to console.

<?php
$this->say('Welcome to Setup');

See source

sayError()

protected sayError($message)

  • param string $message
  • return void

Print error message

See source

sayInfo()

protected sayInfo($message)

  • param string $message
  • return void

Print info message

See source

saySuccess()

protected saySuccess($message)

  • param string $message
  • return void

Print a successful message

See source

sayWarning()

protected sayWarning($message)

  • param string $message
  • return void

Print warning message

See source

setup()

abstract public setup()

  • return mixed

Override this class to create customized setup.

See source

updateComposerClassMap()

private updateComposerClassMap($vendorDir = β€˜vendor’)

  • param string $vendorDir
  • return void

See source

 

Reference is taken from the source code. Help us to improve documentation. Edit module reference
Don't know how to write tests on your own? We will build or improve them for you. Request a quote for official enterprise support or trainings