From 7273c53d5346874509d1853a396c9fbc4b3897bb Mon Sep 17 00:00:00 2001 From: Ruud Boon Date: Mon, 6 Jan 2020 16:42:57 +0100 Subject: [PATCH 1/4] Added Phalcon for page --- _includes/phalcon_hero.html | 15 +++ for/phalcon.md | 228 ++++++++++++++++++++++++++++++++++ images/frameworks/phalcon.svg | 124 ++++++++++++++++++ 3 files changed, 367 insertions(+) create mode 100644 _includes/phalcon_hero.html create mode 100644 for/phalcon.md create mode 100644 images/frameworks/phalcon.svg diff --git a/_includes/phalcon_hero.html b/_includes/phalcon_hero.html new file mode 100644 index 000000000..9c3fa8fd5 --- /dev/null +++ b/_includes/phalcon_hero.html @@ -0,0 +1,15 @@ +
+
+
+
+
+

+
Codeception for
+ + Phalcon

+ +
+
+
+
+
diff --git a/for/phalcon.md b/for/phalcon.md new file mode 100644 index 000000000..fa65be26a --- /dev/null +++ b/for/phalcon.md @@ -0,0 +1,228 @@ +--- +layout: page +title: Codeception for Phalcon +hero: phalcon_hero.html +sidebar: | + + ## Features + + * Access Phalcon services through the dependency injection container: `$I->grabService(...)` + * Combine **all testing levels** (unit, functional, acceptance) + * + + ## Reference + + * [Phalcon 4 Module](/docs/modules/Phalcon4) + * [Demo Application](https://github.com/Codeception/phalcon-demo) + +--- + +## Install + +Install Codeception the Phalcon module and optional dependencies via Composer: + +```bash +composer require codeception/codeception codeception/module-phalcon4 codeception/module-phpbrowser codeception/module-asserts --dev +``` + +## Setup + +It is easy to setup tests by running bootstrap command: + +``` +vendor/bin/codecept bootstrap +``` + +This will create `tests` directory and configuration file `codeception.yml`. This also prepares 3 suites for testing: unit, functional and acceptance. + +### Unit Testing + +Codeception is powered by PHPUnit so unit and integration tests work in a similar manner. Add Phalcon to your unit test by adding the following to your `unit.suite.yml`: +```yaml +# Codeception Test Suite Configuration +# +# Suite for unit or integration tests. + +actor: UnitTester +modules: + enabled: + - Asserts + - \Helper\Unit + - Phalcon4: + bootstrap: public/index.php + cleanup: true + savepoints: true + step_decorators: ~ +``` + +To generate a plain PHPUnit test for class `Users`, run: + +``` +vendor/bin/codecept g:test unit Users +``` + +Actions of the Phalcon module will be accessible from `$this->tester` inside a test of `Codeception\Test\Unit`. + +
+ + Continue to Unit Testing Guide ». +
+ +## Functional Tests + +When it comes to test real features of web applications you can’t go with unit testing only. You want to test how application handles the requests, what responses it provides, what data is saved to database and so on. To test application in near user environment but without launching real webserver or a browser you can use functional tests. They are far more simpler than unit tests in a way they are written. They describe interaction scenario in a simple DSL so you don’t need to deal with application directly but describe actions from a user’s perspective. + +Enable Phalcon for your Functional tests first: + +```yaml +# Codeception Test Suite Configuration +# +# Suite for functional tests +# Emulate web requests and make application process them +# Include one of framework modules (PSymfony2, Yii2, Laravel5, Phalcon4) to use it +# Remove this suite if you don't use frameworks + +actor: FunctionalTester +modules: + enabled: + # add a framework module here + - \Helper\Functional + - Phalcon4: + bootstrap: public/index.php + cleanup: true + savepoints: true + step_decorators: ~ +``` + +Then use [Cest](https://codeception.com/docs/07-AdvancedUsage) or Cept to create a test. +``` +vendor/bin/codecept g:cest functional Login +``` +Then add your test case +```php +wantTo('login as regular user'); + + $I->amOnPage('/'); + $I->click('Log In/Sign Up'); + $I->seeInCurrentUrl('/session/index'); + + $I->see('Log In', "//*[@id='login-header']"); + $I->see("Don't have an account yet?", "//*[@id='signup-header']"); + + $I->fillField('email', 'demo@phalconphp.com'); + $I->fillField('password', 'phalcon'); + + $I->click('Login'); + $I->seeInCurrentUrl('/session/start'); + + $I->see('Welcome Phalcon Demo'); + $I->seeLink('Log Out'); + } +} +``` + +
+ + Continue to Functional Testing Guide » +
+ +### Acceptance Testing + +Sample configuration of `tests/acceptance.suite.yml`: + +```yaml +class_name: AcceptanceTester +modules: + enabled: + - WebDriver: + url: 'https://localhost/' # put your local url + browser: chrome + - \Helper\Acceptance +``` + +Browser can be specified as `chrome`, `firefox`, `phantomjs`, or others. + +To create a sample test called, run: + +``` +vendor/bin/codecept g:cest acceptance Login +``` + +This will create the file `tests/acceptance/LoginCest.php`. Each method of a class (except `_before` and `_after`) is a test. Tests use `$I` object (instance of `AcceptanceTester` class) to perform actions on a webpage. Methods of `AcceptanceTester` are proxified to corresponding modules, which in current case is `WebDriver`. + +
+ + Continue to Acceptance Testing Guide » +
+ +To run the tests you will need chrome browser, [selenium server running](http://codeception.com/docs/modules/WebDriver#Selenium). If this requirements met acceptance tests can be executed as + +``` +vendor/bin/codecept run acceptance +``` + +### BDD + +If you prefer to describe application with feature files, Codeception can turn them to acceptance tests. It is recommended to store feature files in `features` directory (like Behat does it) but symlinking it to `tests/acceptance/features` so they can be treated as tests too. + +``` +ln -s $PWD/features tests/acceptance +``` + +Codeception allows to combine tests written in different formats. If you are about to write a regression test it probably should not be described as a product's feature. That's why feature-files are a subset of all acceptance tests, and they are stored in subfolder of `tests/acceptance`. + +There are no standard Gherkin steps built in. By writing your feature files you can get code snippets which should be added to `AcceptanceTester` class. + +``` +vendor/bin/codecept gherkin:snippets +``` + +
+ + Continue to Behavior Driven Development Guide » +
+ +### API Tests + +API Tests are done at functional testing level but instead of testing HTML responses on user actions, they test requests and responses via protocols like REST or SOAP. To create api tests, you should create a suite for them: + +``` +vendor/bin/codecept g:suite api +``` + +You will need to enable `REST` and `Phalcon` module in `tests/api.suite.yml`: + +```yaml +class_name: ApiTester +modules: + enabled: + - Phalcon4: + bootstrap: public/index.php + cleanup: true + savepoints: true + - REST: + url: /v1 + depends: Phalcon4 + - \Helper\Api +``` + +Phalcon [module](/docs/modules/Phalcon4) actions like `amOnPage` or `see` should not be available for testing API. This is why Phalcon module is not enabled but declared with `depends` for REST module. But Phalcon module should be configured to load Kernel class from `app_path`. + + +
+ + Continue to REST API Testing Guide ». +
+ +[Edit this page on GitHub](https://github.com/Codeception/codeception.github.com/blob/master/for/phalcon.md) diff --git a/images/frameworks/phalcon.svg b/images/frameworks/phalcon.svg new file mode 100644 index 000000000..74b9be4e5 --- /dev/null +++ b/images/frameworks/phalcon.svg @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 8ae4fdd95305b0ab340ae651eb30dcffb2f6d69a Mon Sep 17 00:00:00 2001 From: Ruud Boon Date: Mon, 6 Jan 2020 16:43:34 +0100 Subject: [PATCH 2/4] Removed typo --- for/phalcon.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/for/phalcon.md b/for/phalcon.md index fa65be26a..25687d1f9 100644 --- a/for/phalcon.md +++ b/for/phalcon.md @@ -79,7 +79,7 @@ Enable Phalcon for your Functional tests first: # # Suite for functional tests # Emulate web requests and make application process them -# Include one of framework modules (PSymfony2, Yii2, Laravel5, Phalcon4) to use it +# Include one of framework modules (Symfony2, Yii2, Laravel5, Phalcon4) to use it # Remove this suite if you don't use frameworks actor: FunctionalTester From 5e0b559778b8a219b86ac040e6c30172d2c22745 Mon Sep 17 00:00:00 2001 From: Ruud Boon Date: Mon, 6 Jan 2020 16:44:47 +0100 Subject: [PATCH 3/4] Put focus on new Phalcon 4 Module --- docs/04-FunctionalTests.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/04-FunctionalTests.md b/docs/04-FunctionalTests.md index c26c49cab..48f15be28 100644 --- a/docs/04-FunctionalTests.md +++ b/docs/04-FunctionalTests.md @@ -146,10 +146,10 @@ modules: > See module reference to more configuration options -### Phalcon +### Phalcon 4 -The `Phalcon` module requires creating a bootstrap file which returns an instance of `\Phalcon\Mvc\Application`. -To start writing functional tests with Phalcon support you should enable the `Phalcon` module +The `Phalcon4` module requires creating a bootstrap file which returns an instance of `\Phalcon\Mvc\Application`. +To start writing functional tests with Phalcon support you should enable the `Phalcon4` module and provide the path to this bootstrap file: {% highlight yaml %} @@ -159,14 +159,14 @@ and provide the path to this bootstrap file: actor: FunctionalTester modules: enabled: - - Phalcon: + - Phalcon4: bootstrap: 'app/config/bootstrap.php' cleanup: true savepoints: true {% endhighlight %} -[See the full reference](http://codeception.com/docs/modules/Phalcon) +[See the full reference](http://codeception.com/docs/modules/Phalcon4) ## Writing Functional Tests @@ -279,4 +279,4 @@ If you are using a framework other than the ones listed here, create a module fo * **Next Chapter: [UnitTests >](/docs/05-UnitTests)** -* **Previous Chapter: [< AcceptanceTests](/docs/03-AcceptanceTests)** \ No newline at end of file +* **Previous Chapter: [< AcceptanceTests](/docs/03-AcceptanceTests)** From 8bea2f6c450cbb34347f49d7d0d6eaf203b91ebb Mon Sep 17 00:00:00 2001 From: Ruud Boon Date: Mon, 6 Jan 2020 17:49:30 +0100 Subject: [PATCH 4/4] Added Phalcon to menu --- _layouts/bootstrap.html | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/_layouts/bootstrap.html b/_layouts/bootstrap.html index 642bc2574..2f10254da 100644 --- a/_layouts/bootstrap.html +++ b/_layouts/bootstrap.html @@ -26,7 +26,7 @@ - + @@ -44,7 +44,7 @@ {% for post in site.posts limit:1 %} {{ post.title }} {% endfor %} - {% endif %} + {% endif %} @@ -68,22 +68,22 @@ CODECEPTION_ - + @@ -268,7 +268,7 @@

they support us_

- +