From 55e91e14567c7476bc29e778eda976d336c24f58 Mon Sep 17 00:00:00 2001 From: Michael Bodnarchuk Date: Fri, 16 Aug 2019 13:47:07 +0300 Subject: [PATCH] Unified bootstrap loading (#5645) * * Unified bootstrap loading * Deprecated configuring bootstrap for all suites implicitly * Added `--bootstrap` option to `run` See http://phptest.club/t/bootstrap-deprecations-in-3-0/2196 * fixed tests * fixed suites bootstrap files * Added tests, and docs, for new bootstrap process * minor fixes * removed generated snapshot * Deleted generated actions file * replaced include with require --- .gitignore | 2 + autoload.php | 8 +- codeception.yml | 1 - docs/08-Customization.md | 94 +- docs/reference/Configuration.md | 7 +- src/Codeception/Command/Run.php | 6 + src/Codeception/Configuration.php | 28 +- src/Codeception/Subscriber/Bootstrap.php | 12 +- src/Codeception/Util/PathResolver.php | 9 + tests/cli.suite.yml | 3 +- tests/cli/RunCest.php | 37 + tests/data/claypit/codeception.bootstrap.yml | 7 + tests/data/claypit/tests/_init.php | 4 + .../claypit/tests/dummy.bootstrap.suite.yml | 7 + .../tests/_data/Snapshot.UserSnapshot.json | 1 - .../_support/_generated/DataTesterActions.php | 1081 ----------------- tests/unit.suite.yml | 1 + tests/web.suite.yml | 1 + 18 files changed, 173 insertions(+), 1136 deletions(-) create mode 100755 tests/data/claypit/codeception.bootstrap.yml create mode 100644 tests/data/claypit/tests/_init.php create mode 100755 tests/data/claypit/tests/dummy.bootstrap.suite.yml delete mode 100644 tests/data/snapshots/tests/_data/Snapshot.UserSnapshot.json delete mode 100644 tests/data/snapshots/tests/_support/_generated/DataTesterActions.php diff --git a/.gitignore b/.gitignore index 96c422ef3f..ea324caf8d 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,8 @@ tests/data/exception_in_before/tests/_support/_generated/UnitTesterActions.php tests/data/exception_in_before/tests/_output/ tests/data/bundled_suites/_support/_generated/UnitTesterActions.php tests/data/bundled_suites/_output/ +tests/data/snapshots/tests/_support/_generated +tests/data/snapshots/tests/_data/Snapshot.UserSnapshot.json .DS_Store robo.phar .env diff --git a/autoload.php b/autoload.php index a0f24393e8..cf59628eb2 100644 --- a/autoload.php +++ b/autoload.php @@ -1,7 +1,7 @@ -Wildcards (*) can be used to specify multiple directories at once. - - ### Namespaces To avoid naming conflicts between Actor classes and Helper classes, they should be separated into namespaces. @@ -61,6 +35,46 @@ Where `unit` is the name of suite and the `-c` option specifies the path to the In this example we will assume that there is `frontend/codeception.yml` configuration file and that we will execute the unit tests for only that app. +## Bootstrap + +To prepare environment for testing you can execute custom PHP script before all tests or just before a specific suite. +This way you can initialize autoloader, check availability of a website, etc. + +### Global Bootstrap + +To run bootstrap script before all suites place it in `tests` directory (absolute paths supported as well). +Then set a `bootstrap` config key in `codeception.yml`: + +```yml +# file will be loaded from tests/bootstrap.php +bootstrap: bootstrap.php +``` + +### Suite Bootstrap + +To run a script for a specific suite, place it into the suite directory and add to suite config: + +```yml +# inside .suite.yml +# file will be loaded from tests//bootstrap.php +bootstrap: bootstrap.php +``` + +### On Fly Bootstrap + +Bootstrap script can be executed with `--bootstrap` option for `codecept run` command: + +``` +php vendor/bin/codecept run --bootstrap bootstrap.php +``` + +In this case, bootstrap script will be executed before the Codeception is initialized. +Bootstrap script should be located in current working directory or by an absolute path. + +> Bootstrap is a classical way to run custom PHP code before your tests. +However, we recommend you to use Extensions instead of bootstrap scripts for better flexibility. +If you need configuration, conditional enabling or disabling bootstrap script, extensions should work for you better. + ## Extension Codeception has limited capabilities to extend its core features. @@ -396,6 +410,34 @@ Learn from the examples above to build a custom Installation Template. Here are * Use `createHelper`, `createActor` methods to create helpers and actors. * Use [Codeception generators](https://github.com/Codeception/Codeception/tree/2.4/src/Codeception/Lib/Generator) to create other support classes. + +## One Runner for Multiple Applications + +If your project consists of several applications (frontend, admin, api) or you are using the Symfony framework +with its bundles, you may be interested in having all tests for all applications (bundles) executed in one runner. +In this case you will get one report that covers the whole project. + +Place the `codeception.yml` file into the root folder of your project +and specify the paths to the other `codeception.yml` configurations that you want to include: + +```yaml +include: + - frontend/src/*Bundle + - admin + - api/rest +paths: + output: _output +settings: + colors: false +``` + +You should also specify the path to the `log` directory, where the reports and logs will be saved. + +
+Wildcards (*) can be used to specify multiple directories at once. +
+ + ## Conclusion Each feature mentioned above may help dramatically when using Codeception to automate the testing of large projects, diff --git a/docs/reference/Configuration.md b/docs/reference/Configuration.md index d072eff9e4..3ea65c6382 100644 --- a/docs/reference/Configuration.md +++ b/docs/reference/Configuration.md @@ -34,11 +34,6 @@ paths: ```yaml settings: - # name of bootstrap that will be used - # each bootstrap file should be - # inside a suite directory. - bootstrap: _bootstrap.php - # enable/disable syntax of test files before loading # for php < 7 exec('php -l') is used # disable if you need to speed up tests execution @@ -99,6 +94,7 @@ modules: * `coverage`: [CodeCoverage](http://codeception.com/docs/11-Codecoverage#Configuration) settings. * `params`: allows to pass [external parameters](http://codeception.com/docs/06-ModulesAndHelpers#Dynamic-Configuration-With-Params) into module configuration. * `gherkin`: BDD-specific [Gherkin options](http://codeception.com/docs/07-BDD#Configuration). +* `bootstrap`: bootstrap script that will be executed before all suites. A script should be put into `tests` directory. ## Suite Configuration @@ -143,6 +139,7 @@ modules: * `coverage`: pre suite [CodeCoverage](http://codeception.com/docs/11-Codecoverage#Configuration) settings. * `gherkin`: per suite [BDD Gherkin](http://codeception.com/docs/07-BDD#Configuration) settings. * `error_level`: [error level](http://codeception.com/docs/04-FunctionalTests#Error-Reporting) for runner in current suite. Should be specified for unit, integration, functional tests. Passes value to `error_reporting` function. +* `bootstrap`: bootstrap script that will be executed before current suites. A script should be put into suite directory. ## Config Templates (dist) diff --git a/src/Codeception/Command/Run.php b/src/Codeception/Command/Run.php index 792c1f70b0..067e967554 100644 --- a/src/Codeception/Command/Run.php +++ b/src/Codeception/Command/Run.php @@ -69,6 +69,7 @@ * --silent Only outputs suite names and final results * --steps Show steps in output * --debug (-d) Show debug and scenario output + * --bootstrap Execute bootstrap script before the test * --coverage Run with code coverage (default: "coverage.serialized") * --coverage-html Generate CodeCoverage HTML report in path (default: "coverage") * --coverage-xml Generate CodeCoverage XML report in file (default: "coverage.xml") @@ -143,6 +144,7 @@ protected function configure() new InputOption('silent', '', InputOption::VALUE_NONE, 'Only outputs suite names and final results'), new InputOption('steps', '', InputOption::VALUE_NONE, 'Show steps in output'), new InputOption('debug', 'd', InputOption::VALUE_NONE, 'Show debug and scenario output'), + new InputOption('bootstrap', '', InputOption::VALUE_OPTIONAL, 'Execute custom PHP script before running tests. Path can be absolute or relative to current working directory', false), new InputOption('no-redirect', '', InputOption::VALUE_NONE, 'Do not redirect to Composer-installed version in vendor/codeception'), new InputOption( 'coverage', @@ -239,6 +241,10 @@ public function execute(InputInterface $input, OutputInterface $output) $this->options = $input->getOptions(); $this->output = $output; + if ($this->options['bootstrap']) { + Configuration::loadBootstrap($this->options['bootstrap'], getcwd()); + } + // load config $config = $this->getGlobalConfig(); diff --git a/src/Codeception/Configuration.php b/src/Codeception/Configuration.php index fa9f82dc4c..1add6997af 100644 --- a/src/Codeception/Configuration.php +++ b/src/Codeception/Configuration.php @@ -3,6 +3,7 @@ namespace Codeception; use Codeception\Exception\ConfigurationException; +use Codeception\Lib\Notification; use Codeception\Lib\ParamsLoader; use Codeception\Util\Autoload; use Codeception\Util\Template; @@ -86,6 +87,7 @@ class Configuration 'phpunit-xml' => 'Codeception\PHPUnit\Log\PhpUnit', ], 'groups' => [], + 'bootstrap' => false, 'settings' => [ 'colors' => true, 'bootstrap' => false, @@ -251,21 +253,37 @@ public static function config($configFile = null) } Autoload::addNamespace(self::$config['namespace'], self::supportDir()); - self::loadBootstrap($config['settings']['bootstrap']); + + if ($config['settings']['bootstrap']) { + $bootstrap = self::$config['settings']['bootstrap']; + Notification::deprecate("'settings: bootstrap: $bootstrap' option is deprecated! Replace it with: 'bootstrap: $bootstrap' (not under settings section). See https://bit.ly/2YrRzVc "); + try { + self::loadBootstrap($bootstrap, self::testsDir()); + } catch (ConfigurationException $exception) { + Notification::deprecate("Bootstrap file ($bootstrap) is defined in configuration but can't be loaded. Disable 'settings: bootstrap:' configuration to remove this message"); + } + } + self::loadBootstrap($config['bootstrap'], self::testsDir()); self::loadSuites(); return $config; } - protected static function loadBootstrap($bootstrap) + public static function loadBootstrap($bootstrap, $path) { if (!$bootstrap) { return; } - $bootstrap = self::$dir . DIRECTORY_SEPARATOR . self::$testsDir . DIRECTORY_SEPARATOR . $bootstrap; - if (file_exists($bootstrap)) { - include_once $bootstrap; + + $bootstrap = codecept_is_path_absolute($bootstrap) + ? $bootstrap + : rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $bootstrap; + + + if (!file_exists($bootstrap)) { + throw new ConfigurationException("Bootstrap file $bootstrap can't be loaded"); } + require_once $bootstrap; } protected static function loadSuites() diff --git a/src/Codeception/Subscriber/Bootstrap.php b/src/Codeception/Subscriber/Bootstrap.php index 31e611bdf3..483e0badb9 100644 --- a/src/Codeception/Subscriber/Bootstrap.php +++ b/src/Codeception/Subscriber/Bootstrap.php @@ -1,6 +1,7 @@ assertNotEquals($output, $newOutput, 'order of tests is the same'); + } + + public function runCustomBootstrap(\CliGuy $I) + { + $I->wantTo('execute one test'); + $I->executeCommand('run dummy --bootstrap tests/_init.php'); + $I->seeInShellOutput('--INIT--'); + $I->seeInShellOutput("'hello' => 'world'"); + $I->seeInShellOutput("OK ("); + } + + public function throwErrorIfBootstrapNotFound(\CliGuy $I) + { + $I->wantTo('execute one test'); + $I->executeCommand('run dummy --bootstrap tests/init.php --no-exit 2>&1', false); + $I->dontSeeInShellOutput('--INIT--'); + $I->seeInShellOutput("can't be loaded"); + $I->dontSeeInShellOutput("OK ("); + } + + + public function runBootstrapInGlobalConfig(\CliGuy $I) + { + $I->wantTo('execute one test'); + $I->executeCommand('run dummy -c codeception.bootstrap.yml'); + $I->seeInShellOutput('--INIT--'); + $I->seeInShellOutput("'hello' => 'world'"); + $I->seeInShellOutput("OK ("); + } + + public function runBootstrapInSuiteConfig(\CliGuy $I) + { + $I->wantTo('execute one test'); + $I->executeCommand('run dummy.bootstrap'); + $I->seeInShellOutput('--INIT--'); + $I->seeInShellOutput("'hello' => 'world'"); + $I->seeInShellOutput("OK ("); } } diff --git a/tests/data/claypit/codeception.bootstrap.yml b/tests/data/claypit/codeception.bootstrap.yml new file mode 100755 index 0000000000..26f8115bb7 --- /dev/null +++ b/tests/data/claypit/codeception.bootstrap.yml @@ -0,0 +1,7 @@ +paths: + tests: tests + log: tests/_output + data: tests/_data + helpers: tests/_support + envs: tests/_envs +bootstrap: _init.php diff --git a/tests/data/claypit/tests/_init.php b/tests/data/claypit/tests/_init.php new file mode 100644 index 0000000000..5cf7310677 --- /dev/null +++ b/tests/data/claypit/tests/_init.php @@ -0,0 +1,4 @@ + 'world']); +echo "--INIT--\n"; + diff --git a/tests/data/claypit/tests/dummy.bootstrap.suite.yml b/tests/data/claypit/tests/dummy.bootstrap.suite.yml new file mode 100755 index 0000000000..87be06950d --- /dev/null +++ b/tests/data/claypit/tests/dummy.bootstrap.suite.yml @@ -0,0 +1,7 @@ +class_name: DumbGuy +path: dummy +modules: + enabled: [Filesystem, DumbHelper] +env: + dev: [] +bootstrap: "../_init.php" \ No newline at end of file diff --git a/tests/data/snapshots/tests/_data/Snapshot.UserSnapshot.json b/tests/data/snapshots/tests/_data/Snapshot.UserSnapshot.json deleted file mode 100644 index 2b9da7b919..0000000000 --- a/tests/data/snapshots/tests/_data/Snapshot.UserSnapshot.json +++ /dev/null @@ -1 +0,0 @@ -["davert@mail.ua","nick@mail.ua","miles@davis.com","charlie@parker.com"] \ No newline at end of file diff --git a/tests/data/snapshots/tests/_support/_generated/DataTesterActions.php b/tests/data/snapshots/tests/_support/_generated/DataTesterActions.php deleted file mode 100644 index afbed9c1ac..0000000000 --- a/tests/data/snapshots/tests/_support/_generated/DataTesterActions.php +++ /dev/null @@ -1,1081 +0,0 @@ -expectException(MyException::class, function() { - * $this->doSomethingBad(); - * }); - * - * $I->expectException(new MyException(), function() { - * $this->doSomethingBad(); - * }); - * ``` - * If you want to check message or exception code, you can pass them with exception instance: - * ```php - * expectException(new MyException("Don't do bad things"), function() { - * $this->doSomethingBad(); - * }); - * ``` - * - * @param $exception string or \Exception - * @param $callback - * @see \Codeception\Module\Asserts::expectException() - */ - public function expectException($exception, $callback) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('expectException', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Handles and checks throwables (Exceptions/Errors) called inside the callback function. - * Either throwable class name or throwable instance should be provided. - * - * ```php - * expectThrowable(MyThrowable::class, function() { - * $this->doSomethingBad(); - * }); - * - * $I->expectThrowable(new MyException(), function() { - * $this->doSomethingBad(); - * }); - * ``` - * If you want to check message or throwable code, you can pass them with throwable instance: - * ```php - * expectThrowable(new MyError("Don't do bad things"), function() { - * $this->doSomethingBad(); - * }); - * ``` - * - * @param $throwable string or \Throwable - * @param $callback - * @see \Codeception\Module\Asserts::expectThrowable() - */ - public function expectThrowable($throwable, $callback) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('expectThrowable', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that two variables are equal. - * - * @param $expected - * @param $actual - * @param string $message - * @param float $delta - * @see \Codeception\Module\Asserts::assertEquals() - */ - public function assertEquals($expected, $actual, $message = null, $delta = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEquals', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that two variables are not equal - * - * @param $expected - * @param $actual - * @param string $message - * @param float $delta - * @see \Codeception\Module\Asserts::assertNotEquals() - */ - public function assertNotEquals($expected, $actual, $message = null, $delta = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEquals', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that two variables are same - * - * @param $expected - * @param $actual - * @param string $message - * @see \Codeception\Module\Asserts::assertSame() - */ - public function assertSame($expected, $actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertSame', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that two variables are not same - * - * @param $expected - * @param $actual - * @param string $message - * @see \Codeception\Module\Asserts::assertNotSame() - */ - public function assertNotSame($expected, $actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotSame', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that actual is greater than expected - * - * @param $expected - * @param $actual - * @param string $message - * @see \Codeception\Module\Asserts::assertGreaterThan() - */ - public function assertGreaterThan($expected, $actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThan', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that actual is greater or equal than expected - * - * @param $expected - * @param $actual - * @param string $message - * @see \Codeception\Module\Asserts::assertGreaterThanOrEqual() - */ - public function assertGreaterThanOrEqual($expected, $actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThanOrEqual', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that actual is less than expected - * - * @param $expected - * @param $actual - * @param string $message - * @see \Codeception\Module\Asserts::assertLessThan() - */ - public function assertLessThan($expected, $actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessThan', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that actual is less or equal than expected - * - * @param $expected - * @param $actual - * @param string $message - * @see \Codeception\Module\Asserts::assertLessThanOrEqual() - */ - public function assertLessThanOrEqual($expected, $actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessThanOrEqual', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that haystack contains needle - * - * @param $needle - * @param $haystack - * @param string $message - * @see \Codeception\Module\Asserts::assertContains() - */ - public function assertContains($needle, $haystack, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertContains', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that haystack doesn't contain needle. - * - * @param $needle - * @param $haystack - * @param string $message - * @see \Codeception\Module\Asserts::assertNotContains() - */ - public function assertNotContains($needle, $haystack, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotContains', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that string match with pattern - * - * @param string $pattern - * @param string $string - * @param string $message - * @see \Codeception\Module\Asserts::assertRegExp() - */ - public function assertRegExp($pattern, $string, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertRegExp', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that string not match with pattern - * - * @param string $pattern - * @param string $string - * @param string $message - * @see \Codeception\Module\Asserts::assertNotRegExp() - */ - public function assertNotRegExp($pattern, $string, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotRegExp', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that a string starts with the given prefix. - * - * @param string $prefix - * @param string $string - * @param string $message - * @see \Codeception\Module\Asserts::assertStringStartsWith() - */ - public function assertStringStartsWith($prefix, $string, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringStartsWith', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that a string doesn't start with the given prefix. - * - * @param string $prefix - * @param string $string - * @param string $message - * @see \Codeception\Module\Asserts::assertStringStartsNotWith() - */ - public function assertStringStartsNotWith($prefix, $string, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringStartsNotWith', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that variable is empty. - * - * @param $actual - * @param string $message - * @see \Codeception\Module\Asserts::assertEmpty() - */ - public function assertEmpty($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEmpty', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that variable is not empty. - * - * @param $actual - * @param string $message - * @see \Codeception\Module\Asserts::assertNotEmpty() - */ - public function assertNotEmpty($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEmpty', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that variable is NULL - * - * @param $actual - * @param string $message - * @see \Codeception\Module\Asserts::assertNull() - */ - public function assertNull($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNull', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that variable is not NULL - * - * @param $actual - * @param string $message - * @see \Codeception\Module\Asserts::assertNotNull() - */ - public function assertNotNull($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotNull', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that condition is positive. - * - * @param $condition - * @param string $message - * @see \Codeception\Module\Asserts::assertTrue() - */ - public function assertTrue($condition, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertTrue', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the condition is NOT true (everything but true) - * - * @param $condition - * @param string $message - * @see \Codeception\Module\Asserts::assertNotTrue() - */ - public function assertNotTrue($condition, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotTrue', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that condition is negative. - * - * @param $condition - * @param string $message - * @see \Codeception\Module\Asserts::assertFalse() - */ - public function assertFalse($condition, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFalse', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks that the condition is NOT false (everything but false) - * - * @param $condition - * @param string $message - * @see \Codeception\Module\Asserts::assertNotFalse() - */ - public function assertNotFalse($condition, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotFalse', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks if file exists - * - * @param string $filename - * @param string $message - * @see \Codeception\Module\Asserts::assertFileExists() - */ - public function assertFileExists($filename, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFileExists', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Checks if file doesn't exist - * - * @param string $filename - * @param string $message - * @see \Codeception\Module\Asserts::assertFileNotExists() - */ - public function assertFileNotExists($filename, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFileNotExists', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * @param $expected - * @param $actual - * @param $description - * @see \Codeception\Module\Asserts::assertGreaterOrEquals() - */ - public function assertGreaterOrEquals($expected, $actual, $description = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterOrEquals', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * @param $expected - * @param $actual - * @param $description - * @see \Codeception\Module\Asserts::assertLessOrEquals() - */ - public function assertLessOrEquals($expected, $actual, $description = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessOrEquals', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * @param $actual - * @param $description - * @see \Codeception\Module\Asserts::assertIsEmpty() - */ - public function assertIsEmpty($actual, $description = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsEmpty', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * @param $key - * @param $actual - * @param $description - * @see \Codeception\Module\Asserts::assertArrayHasKey() - */ - public function assertArrayHasKey($key, $actual, $description = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArrayHasKey', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * @param $key - * @param $actual - * @param $description - * @see \Codeception\Module\Asserts::assertArrayNotHasKey() - */ - public function assertArrayNotHasKey($key, $actual, $description = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArrayNotHasKey', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * @param $expectedCount - * @param $actual - * @param $description - * @see \Codeception\Module\Asserts::assertCount() - */ - public function assertCount($expectedCount, $actual, $description = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertCount', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * @param $class - * @param $actual - * @param $description - * @see \Codeception\Module\Asserts::assertInstanceOf() - */ - public function assertInstanceOf($class, $actual, $description = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertInstanceOf', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * @param $class - * @param $actual - * @param $description - * @see \Codeception\Module\Asserts::assertNotInstanceOf() - */ - public function assertNotInstanceOf($class, $actual, $description = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotInstanceOf', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * @param $type - * @param $actual - * @param $description - * @see \Codeception\Module\Asserts::assertInternalType() - */ - public function assertInternalType($type, $actual, $description = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertInternalType', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Fails the test with message. - * - * @param $message - * @see \Codeception\Module\Asserts::fail() - */ - public function fail($message) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('fail', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertStringContainsString() - */ - public function assertStringContainsString($needle, $haystack, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringContainsString', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertStringNotContainsString() - */ - public function assertStringNotContainsString($needle, $haystack, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringNotContainsString', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertStringContainsStringIgnoringCase() - */ - public function assertStringContainsStringIgnoringCase($needle, $haystack, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringContainsStringIgnoringCase', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertStringNotContainsStringIgnoringCase() - */ - public function assertStringNotContainsStringIgnoringCase($needle, $haystack, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringNotContainsStringIgnoringCase', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertIsArray() - */ - public function assertIsArray($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsArray', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertIsBool() - */ - public function assertIsBool($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsBool', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertIsFloat() - */ - public function assertIsFloat($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsFloat', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertIsInt() - */ - public function assertIsInt($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsInt', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertIsNumeric() - */ - public function assertIsNumeric($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsNumeric', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertIsObject() - */ - public function assertIsObject($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsObject', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertIsResource() - */ - public function assertIsResource($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsResource', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertIsString() - */ - public function assertIsString($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsString', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertIsScalar() - */ - public function assertIsScalar($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsScalar', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertIsCallable() - */ - public function assertIsCallable($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsCallable', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertIsNotArray() - */ - public function assertIsNotArray($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsNotArray', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertIsNotBool() - */ - public function assertIsNotBool($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsNotBool', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertIsNotFloat() - */ - public function assertIsNotFloat($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsNotFloat', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertIsNotInt() - */ - public function assertIsNotInt($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsNotInt', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertIsNotNumeric() - */ - public function assertIsNotNumeric($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsNotNumeric', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertIsNotObject() - */ - public function assertIsNotObject($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsNotObject', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertIsNotResource() - */ - public function assertIsNotResource($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsNotResource', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertIsNotString() - */ - public function assertIsNotString($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsNotString', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertIsNotScalar() - */ - public function assertIsNotScalar($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsNotScalar', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * - * @see \Codeception\Module\Asserts::assertIsNotCallable() - */ - public function assertIsNotCallable($actual, $message = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsNotCallable', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Make sure you are connected to the right database. - * - * ```php - * seeNumRecords(2, 'users'); //executed on default database - * $I->amConnectedToDatabase('db_books'); - * $I->seeNumRecords(30, 'books'); //executed on db_books database - * //All the next queries will be on db_books - * ``` - * @param $databaseKey - * @throws ModuleConfigException - * @see \Codeception\Module\Db::amConnectedToDatabase() - */ - public function amConnectedToDatabase($databaseKey) { - return $this->getScenario()->runStep(new \Codeception\Step\Condition('amConnectedToDatabase', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Can be used with a callback if you don't want to change the current database in your test. - * - * ```php - * seeNumRecords(2, 'users'); //executed on default database - * $I->performInDatabase('db_books', function($I) { - * $I->seeNumRecords(30, 'books'); //executed on db_books database - * }); - * $I->seeNumRecords(2, 'users'); //executed on default database - * ``` - * List of actions can be pragmatically built using `Codeception\Util\ActionSequence`: - * - * ```php - * performInDatabase('db_books', ActionSequence::build() - * ->seeNumRecords(30, 'books') - * ); - * ``` - * Alternatively an array can be used: - * - * ```php - * $I->performInDatabase('db_books', ['seeNumRecords' => [30, 'books']]); - * ``` - * - * Choose the syntax you like the most and use it, - * - * Actions executed from array or ActionSequence will print debug output for actions, and adds an action name to - * exception on failure. - * - * @param $databaseKey - * @param \Codeception\Util\ActionSequence|array|callable $actions - * @throws ModuleConfigException - * @see \Codeception\Module\Db::performInDatabase() - */ - public function performInDatabase($databaseKey, $actions) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('performInDatabase', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Inserts an SQL record into a database. This record will be erased after the test. - * - * ```php - * haveInDatabase('users', array('name' => 'miles', 'email' => 'miles@davis.com')); - * ?> - * ``` - * - * @param string $table - * @param array $data - * - * @return integer $id - * @see \Codeception\Module\Db::haveInDatabase() - */ - public function haveInDatabase($table, $data) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('haveInDatabase', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Asserts that a row with the given column values exists. - * Provide table name and column values. - * - * ```php - * seeInDatabase('users', ['name' => 'Davert', 'email' => 'davert@mail.com']); - * ``` - * Fails if no such user found. - * - * Comparison expressions can be used as well: - * - * ```php - * seeInDatabase('posts', ['num_comments >=' => '0']); - * $I->seeInDatabase('users', ['email like' => 'miles@davis.com']); - * ``` - * - * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. - * - * - * @param string $table - * @param array $criteria - * @see \Codeception\Module\Db::seeInDatabase() - */ - public function seeInDatabase($table, $criteria = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInDatabase', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Asserts that the given number of records were found in the database. - * - * ```php - * seeNumRecords(1, 'users', ['name' => 'davert']) - * ?> - * ``` - * - * @param int $expectedNumber Expected number - * @param string $table Table name - * @param array $criteria Search criteria [Optional] - * @see \Codeception\Module\Db::seeNumRecords() - */ - public function seeNumRecords($expectedNumber, $table, $criteria = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeNumRecords', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Effect is opposite to ->seeInDatabase - * - * Asserts that there is no record with the given column values in a database. - * Provide table name and column values. - * - * ``` php - * dontSeeInDatabase('users', ['name' => 'Davert', 'email' => 'davert@mail.com']); - * ``` - * Fails if such user was found. - * - * Comparison expressions can be used as well: - * - * ```php - * dontSeeInDatabase('posts', ['num_comments >=' => '0']); - * $I->dontSeeInDatabase('users', ['email like' => 'miles%']); - * ``` - * - * Supported operators: `<`, `>`, `>=`, `<=`, `!=`, `like`. - * - * @param string $table - * @param array $criteria - * @see \Codeception\Module\Db::dontSeeInDatabase() - */ - public function dontSeeInDatabase($table, $criteria = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('dontSeeInDatabase', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Fetches all values from the column in database. - * Provide table name, desired column and criteria. - * - * ``` php - * grabColumnFromDatabase('users', 'email', array('name' => 'RebOOter')); - * ``` - * - * @param string $table - * @param string $column - * @param array $criteria - * - * @return array - * @see \Codeception\Module\Db::grabColumnFromDatabase() - */ - public function grabColumnFromDatabase($table, $column, $criteria = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('grabColumnFromDatabase', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Fetches all values from the column in database. - * Provide table name, desired column and criteria. - * - * ``` php - * grabFromDatabase('users', 'email', array('name' => 'RebOOter')); - * ``` - * - * @param string $table - * @param string $column - * @param array $criteria - * - * @return mixed - * @see \Codeception\Module\Db::grabFromDatabase() - */ - public function grabFromDatabase($table, $column, $criteria = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('grabFromDatabase', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Returns the number of rows in a database - * - * @param string $table Table name - * @param array $criteria Search criteria [Optional] - * - * @return int - * @see \Codeception\Module\Db::grabNumRecords() - */ - public function grabNumRecords($table, $criteria = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('grabNumRecords', func_get_args())); - } - - - /** - * [!] Method is generated. Documentation taken from corresponding module. - * - * Update an SQL record into a database. - * - * ```php - * updateInDatabase('users', array('isAdmin' => true), array('email' => 'miles@davis.com')); - * ?> - * ``` - * - * @param string $table - * @param array $data - * @param array $criteria - * @see \Codeception\Module\Db::updateInDatabase() - */ - public function updateInDatabase($table, $data, $criteria = null) { - return $this->getScenario()->runStep(new \Codeception\Step\Action('updateInDatabase', func_get_args())); - } -} diff --git a/tests/unit.suite.yml b/tests/unit.suite.yml index 82106de486..1b1f1c57b5 100644 --- a/tests/unit.suite.yml +++ b/tests/unit.suite.yml @@ -3,5 +3,6 @@ # suite for unit (internal) tests. error_level: "E_ALL | E_STRICT" class_name: CodeGuy +bootstrap: _bootstrap.php modules: enabled: [CodeHelper, EmulateModuleHelper] diff --git a/tests/web.suite.yml b/tests/web.suite.yml index fc59dfb054..4e6659a15c 100644 --- a/tests/web.suite.yml +++ b/tests/web.suite.yml @@ -1,4 +1,5 @@ class_name: WebGuy +bootstrap: _bootstrap.php modules: enabled: [WebDriver, WebHelper] config: